5 # vmlinux is linked from the objects selected by $(KBUILD_VMLINUX_INIT) and
6 # $(KBUILD_VMLINUX_MAIN) and $(KBUILD_VMLINUX_LIBS). Most are built-in.a files
7 # from top-level directories in the kernel tree, others are specified in
8 # arch/$(ARCH)/Makefile. Ordering when linking is important, and
9 # $(KBUILD_VMLINUX_INIT) must be first. $(KBUILD_VMLINUX_LIBS) are archives
10 # which are linked conditionally (not within --whole-archive), and do not
11 # require symbol indexes added.
16 # +-< $(KBUILD_VMLINUX_INIT)
17 # | +--< init/version.o + more
19 # +--< $(KBUILD_VMLINUX_MAIN)
20 # | +--< drivers/built-in.a mm/built-in.a + more
22 # +--< $(KBUILD_VMLINUX_LIBS)
23 # | +--< lib/lib.a + more
25 # +-< ${kallsymso} (see description in KALLSYMS section)
27 # vmlinux version (uname -v) cannot be updated during normal
28 # descending-into-subdirs phase since we do not yet know if we need to
30 # Therefore this step is delayed until just before final link of vmlinux.
32 # System.map is generated to document addresses of all kernel symbols
37 # Nice output in kbuild format
38 # Will be supressed by "make -s"
41 if [ "${quiet}" != "silent_" ]; then
42 printf " %-7s %s\n" ${1} ${2}
46 # Thin archive build here makes a final archive with symbol table and indexes
47 # from vmlinux objects INIT and MAIN, which can be used as input to linker.
48 # KBUILD_VMLINUX_LIBS archives should already have symbol table and indexes
51 # Traditional incremental style of link does not require this step
53 # built-in.a output file
59 ${AR} rcsTP${KBUILD_ARFLAGS} built-in.a \
60 ${KBUILD_VMLINUX_INIT} \
61 ${KBUILD_VMLINUX_MAIN}
63 # rebuild with llvm-ar to update the symbol table
64 if [ -n "${CONFIG_LTO_CLANG}" ]; then
65 mv -f built-in.a built-in.a.tmp
66 ${LLVM_AR} rcsT${KBUILD_ARFLAGS} built-in.a $(${AR} t built-in.a.tmp)
71 # If CONFIG_LTO_CLANG is selected, collect generated symbol versions into
75 if [ -z "${CONFIG_LTO_CLANG}" ]; then
79 if [ -z "${CONFIG_MODVERSIONS}" ]; then
83 rm -f .tmp_symversions
85 for a in built-in.a ${KBUILD_VMLINUX_LIBS}; do
86 for o in $(${AR} t $a); do
87 if [ -f ${o}.symversions ]; then
88 cat ${o}.symversions >> .tmp_symversions
93 echo "-T .tmp_symversions"
96 # Link of vmlinux.o used for section mismatch analysis
102 objects="--whole-archive \
106 ${KBUILD_VMLINUX_LIBS} \
109 if [ -n "${CONFIG_LTO_CLANG}" ]; then
110 # This might take a while, so indicate that we're doing
115 ${LD} ${LDFLAGS} -r -o ${1} $(modversions) ${objects}
118 # If CONFIG_LTO_CLANG is selected, we postpone running recordmcount until
119 # we have compiled LLVM IR to an object file.
122 if [ -z "${CONFIG_LTO_CLANG}" ]; then
126 if [ -n "${CONFIG_FTRACE_MCOUNT_RECORD}" ]; then
127 scripts/recordmcount ${RECORDMCOUNT_FLAGS} $*
132 # ${1} - optional extra .o files
136 local lds="${objtree}/${KBUILD_LDS}"
139 if [ "${SRCARCH}" != "um" ]; then
140 if [ -z "${CONFIG_LTO_CLANG}" ]; then
141 objects="--whole-archive \
145 ${KBUILD_VMLINUX_LIBS} \
149 objects="--start-group \
155 ${LD} ${LDFLAGS} ${LDFLAGS_vmlinux} -o ${2} \
158 objects="-Wl,--whole-archive \
160 -Wl,--no-whole-archive \
162 ${KBUILD_VMLINUX_LIBS} \
166 ${CC} ${CFLAGS_vmlinux} -o ${2} \
169 -lutil -lrt -lpthread
174 # Create ${2} .o file with all symbols from the ${1} object file
180 if [ -n "${CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX}" ]; then
181 kallsymopt="${kallsymopt} --symbol-prefix=_"
184 if [ -n "${CONFIG_KALLSYMS_ALL}" ]; then
185 kallsymopt="${kallsymopt} --all-symbols"
188 if [ -n "${CONFIG_ARM}" ] && [ -z "${CONFIG_XIP_KERNEL}" ] && [ -n "${CONFIG_PAGE_OFFSET}" ]; then
189 kallsymopt="${kallsymopt} --page-offset=$CONFIG_PAGE_OFFSET"
192 if [ -n "${CONFIG_X86_64}" ]; then
193 kallsymopt="${kallsymopt} --absolute-percpu"
196 local aflags="${KBUILD_AFLAGS} ${KBUILD_AFLAGS_KERNEL} \
197 ${NOSTDINC_FLAGS} ${LINUXINCLUDE} ${KBUILD_CPPFLAGS}"
200 scripts/kallsyms ${kallsymopt} | \
201 ${CC} ${aflags} -c -o ${2} -x assembler-with-cpp -
204 # Create map file with all symbols from ${1}
205 # See mksymap for additional details
208 ${CONFIG_SHELL} "${srctree}/scripts/mksysmap" ${1} ${2}
213 ${objtree}/scripts/sortextable ${1}
216 # Delete output files in case of error
220 rm -f .tmp_System.map
222 rm -f .tmp_symversions
233 if [ $? -ne 0 ]; then
243 trap on_signals HUP INT QUIT TERM
247 # Use "make V=1" to debug this script
248 case "${KBUILD_VERBOSE}" in
254 if [ "$1" = "clean" ]; then
259 # We need access to CONFIG_ symbols
260 case "${KCONFIG_CONFIG}" in
262 . "${KCONFIG_CONFIG}"
265 # Force using a file from the current directory
266 . "./${KCONFIG_CONFIG}"
271 if [ ! -r .version ]; then
275 mv .version .old_version;
276 expr 0$(cat .old_version) + 1 >.version;
279 # final build of init/
280 ${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
285 modpost_link vmlinux.o
287 # modpost vmlinux.o to check for section mismatches
288 ${MAKE} -f "${srctree}/scripts/Makefile.modpost" vmlinux.o
290 if [ -n "${CONFIG_LTO_CLANG}" ]; then
291 # Call recordmcount if needed
292 recordmcount vmlinux.o
297 if [ -n "${CONFIG_KALLSYMS}" ]; then
300 # Generate section listing all symbols and add it into vmlinux
301 # It's a three step process:
302 # 1) Link .tmp_vmlinux1 so it has all symbols and sections,
303 # but __kallsyms is empty.
304 # Running kallsyms on that gives us .tmp_kallsyms1.o with
306 # 2) Link .tmp_vmlinux2 so it now has a __kallsyms section of
307 # the right size, but due to the added section, some
308 # addresses have shifted.
309 # From here, we generate a correct .tmp_kallsyms2.o
310 # 2a) We may use an extra pass as this has been necessary to
311 # woraround some alignment related bugs.
312 # KALLSYMS_EXTRA_PASS=1 is used to trigger this.
313 # 3) The correct ${kallsymso} is linked into the final vmlinux.
315 # a) Verify that the System.map from vmlinux matches the map from
318 kallsymso=.tmp_kallsyms2.o
319 kallsyms_vmlinux=.tmp_vmlinux2
322 vmlinux_link "" .tmp_vmlinux1
323 kallsyms .tmp_vmlinux1 .tmp_kallsyms1.o
326 vmlinux_link .tmp_kallsyms1.o .tmp_vmlinux2
327 kallsyms .tmp_vmlinux2 .tmp_kallsyms2.o
330 if [ -n "${KALLSYMS_EXTRA_PASS}" ]; then
331 kallsymso=.tmp_kallsyms3.o
332 kallsyms_vmlinux=.tmp_vmlinux3
334 vmlinux_link .tmp_kallsyms2.o .tmp_vmlinux3
336 kallsyms .tmp_vmlinux3 .tmp_kallsyms3.o
341 vmlinux_link "${kallsymso}" vmlinux
343 if [ -n "${CONFIG_BUILDTIME_EXTABLE_SORT}" ]; then
348 info SYSMAP System.map
349 mksysmap vmlinux System.map
351 # step a (see comment above)
352 if [ -n "${CONFIG_KALLSYMS}" ]; then
353 mksysmap ${kallsyms_vmlinux} .tmp_System.map
355 if ! cmp -s System.map .tmp_System.map; then
356 echo >&2 Inconsistent kallsyms data
357 echo >&2 Try "make KALLSYMS_EXTRA_PASS=1" as a workaround
362 # We made a new kernel - delete old version file