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.o 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.o mm/built-in.o + 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.o output file
57 if [ -n "${CONFIG_THIN_ARCHIVES}" ]; then
60 ${AR} rcsTP
${KBUILD_ARFLAGS} built-in.o \
61 ${KBUILD_VMLINUX_INIT} \
62 ${KBUILD_VMLINUX_MAIN}
66 # Link of vmlinux.o used for section mismatch analysis
72 if [ -n "${CONFIG_THIN_ARCHIVES}" ]; then
73 objects
="--whole-archive \
77 ${KBUILD_VMLINUX_LIBS} \
80 objects
="${KBUILD_VMLINUX_INIT} \
82 ${KBUILD_VMLINUX_MAIN} \
83 ${KBUILD_VMLINUX_LIBS} \
86 ${LD} ${LDFLAGS} -r -o ${1} ${objects}
90 # ${1} - optional extra .o files
94 local lds
="${objtree}/${KBUILD_LDS}"
97 if [ "${SRCARCH}" != "um" ]; then
98 if [ -n "${CONFIG_THIN_ARCHIVES}" ]; then
99 objects
="--whole-archive \
103 ${KBUILD_VMLINUX_LIBS} \
107 objects
="${KBUILD_VMLINUX_INIT} \
109 ${KBUILD_VMLINUX_MAIN} \
110 ${KBUILD_VMLINUX_LIBS} \
115 ${LD} ${LDFLAGS} ${LDFLAGS_vmlinux} -o ${2} \
118 if [ -n "${CONFIG_THIN_ARCHIVES}" ]; then
119 objects
="-Wl,--whole-archive \
121 -Wl,--no-whole-archive \
123 ${KBUILD_VMLINUX_LIBS} \
127 objects
="${KBUILD_VMLINUX_INIT} \
129 ${KBUILD_VMLINUX_MAIN} \
130 ${KBUILD_VMLINUX_LIBS} \
135 ${CC} ${CFLAGS_vmlinux} -o ${2} \
138 -lutil -lrt -lpthread
144 # Create ${2} .o file with all symbols from the ${1} object file
150 if [ -n "${CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX}" ]; then
151 kallsymopt
="${kallsymopt} --symbol-prefix=_"
154 if [ -n "${CONFIG_KALLSYMS_ALL}" ]; then
155 kallsymopt
="${kallsymopt} --all-symbols"
158 if [ -n "${CONFIG_KALLSYMS_ABSOLUTE_PERCPU}" ]; then
159 kallsymopt
="${kallsymopt} --absolute-percpu"
162 if [ -n "${CONFIG_KALLSYMS_BASE_RELATIVE}" ]; then
163 kallsymopt
="${kallsymopt} --base-relative"
166 local aflags
="${KBUILD_AFLAGS} ${KBUILD_AFLAGS_KERNEL} \
167 ${NOSTDINC_FLAGS} ${LINUXINCLUDE} ${KBUILD_CPPFLAGS}"
169 local afile
="`basename ${2} .o`.S"
171 ${NM} -n ${1} | scripts/kallsyms ${kallsymopt} > ${afile}
172 ${CC} ${aflags} -c -o ${2} ${afile}
175 # Create map file with all symbols from ${1}
176 # See mksymap for additional details
179 ${CONFIG_SHELL} "${srctree}/scripts/mksysmap" ${1} ${2}
184 ${objtree}/scripts
/sortextable
${1}
187 # Delete output files in case of error
191 rm -f .tmp_System.map
203 if [ $?
-ne 0 ]; then
213 trap on_signals HUP INT QUIT TERM
217 # Use "make V=1" to debug this script
218 case "${KBUILD_VERBOSE}" in
224 if [ "$1" = "clean" ]; then
229 # We need access to CONFIG_ symbols
230 case "${KCONFIG_CONFIG}" in
232 .
"${KCONFIG_CONFIG}"
235 # Force using a file from the current directory
236 .
"./${KCONFIG_CONFIG}"
241 if [ ! -r .version
]; then
245 mv .version .old_version
;
246 expr 0$
(cat .old_version
) + 1 >.version
;
249 # final build of init/
250 ${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}"
256 modpost_link vmlinux.o
258 # modpost vmlinux.o to check for section mismatches
259 ${MAKE} -f "${srctree}/scripts
/Makefile.modpost
" vmlinux.o
263 if [ -n "${CONFIG_KALLSYMS}" ]; then
266 # Generate section listing all symbols and add it into vmlinux
267 # It's a three step process:
268 # 1) Link .tmp_vmlinux1 so it has all symbols and sections,
269 # but __kallsyms is empty.
270 # Running kallsyms on that gives us .tmp_kallsyms1.o with
272 # 2) Link .tmp_vmlinux2 so it now has a __kallsyms section of
273 # the right size, but due to the added section, some
274 # addresses have shifted.
275 # From here, we generate a correct .tmp_kallsyms2.o
276 # 3) That link may have expanded the kernel image enough that
277 # more linker branch stubs / trampolines had to be added, which
278 # introduces new names, which further expands kallsyms. Do another
279 # pass if that is the case. In theory it's possible this results
280 # in even more stubs, but unlikely.
281 # KALLSYMS_EXTRA_PASS=1 may also used to debug or work around
283 # 4) The correct ${kallsymso} is linked into the final vmlinux.
285 # a) Verify that the System.map from vmlinux matches the map from
288 kallsymso=.tmp_kallsyms2.o
289 kallsyms_vmlinux=.tmp_vmlinux2
292 vmlinux_link "" .tmp_vmlinux1
293 kallsyms .tmp_vmlinux1 .tmp_kallsyms1.o
296 vmlinux_link .tmp_kallsyms1.o .tmp_vmlinux2
297 kallsyms .tmp_vmlinux2 .tmp_kallsyms2.o
300 size1=$(stat -c "%s
" .tmp_kallsyms1.o)
301 size2=$(stat -c "%s
" .tmp_kallsyms2.o)
303 if [ $size1 -ne $size2 ] || [ -n "${KALLSYMS_EXTRA_PASS}" ]; then
304 kallsymso=.tmp_kallsyms3.o
305 kallsyms_vmlinux=.tmp_vmlinux3
307 vmlinux_link .tmp_kallsyms2.o .tmp_vmlinux3
309 kallsyms .tmp_vmlinux3 .tmp_kallsyms3.o
314 vmlinux_link "${kallsymso}" vmlinux
316 if [ -n "${CONFIG_BUILDTIME_EXTABLE_SORT}" ]; then
321 info SYSMAP System.map
322 mksysmap vmlinux System.map
324 # step a (see comment above)
325 if [ -n "${CONFIG_KALLSYMS}" ]; then
326 mksysmap ${kallsyms_vmlinux} .tmp_System.map
328 if ! cmp -s System.map .tmp_System.map; then
329 echo >&2 Inconsistent kallsyms data
330 echo >&2 Try "make KALLSYMS_EXTRA_PASS
=1" as a workaround
335 # We made a new kernel - delete old version file