]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blobdiff - scripts/link-vmlinux.sh
UBUNTU: Ubuntu-raspi2-4.10.0-1011.14
[mirror_ubuntu-zesty-kernel.git] / scripts / link-vmlinux.sh
index 4f727eb5ec43f294e0a508244bab4249c9001575..c80291319cb2e20e15df93b685b8065ffdd9742e 100755 (executable)
@@ -37,12 +37,40 @@ info()
        fi
 }
 
+# Thin archive build here makes a final archive with
+# symbol table and indexes from vmlinux objects, which can be
+# used as input to linker.
+#
+# Traditional incremental style of link does not require this step
+#
+# built-in.o output file
+#
+archive_builtin()
+{
+       if [ -n "${CONFIG_THIN_ARCHIVES}" ]; then
+               info AR built-in.o
+               rm -f built-in.o;
+               ${AR} rcsT${KBUILD_ARFLAGS} built-in.o                  \
+                                       ${KBUILD_VMLINUX_INIT}          \
+                                       ${KBUILD_VMLINUX_MAIN}
+       fi
+}
+
 # Link of vmlinux.o used for section mismatch analysis
 # ${1} output file
 modpost_link()
 {
-       ${LD} ${LDFLAGS} -r -o ${1} ${KBUILD_VMLINUX_INIT}                   \
-               --start-group ${KBUILD_VMLINUX_MAIN} --end-group
+       local objects
+
+       if [ -n "${CONFIG_THIN_ARCHIVES}" ]; then
+               objects="--whole-archive built-in.o"
+       else
+               objects="${KBUILD_VMLINUX_INIT}                         \
+                       --start-group                                   \
+                       ${KBUILD_VMLINUX_MAIN}                          \
+                       --end-group"
+       fi
+       ${LD} ${LDFLAGS} -r -o ${1} ${objects}
 }
 
 # Link of vmlinux
@@ -51,18 +79,36 @@ modpost_link()
 vmlinux_link()
 {
        local lds="${objtree}/${KBUILD_LDS}"
+       local objects
 
        if [ "${SRCARCH}" != "um" ]; then
-               ${LD} ${LDFLAGS} ${LDFLAGS_vmlinux} -o ${2}                  \
-                       -T ${lds} ${KBUILD_VMLINUX_INIT}                     \
-                       --start-group ${KBUILD_VMLINUX_MAIN} --end-group ${1}
+               if [ -n "${CONFIG_THIN_ARCHIVES}" ]; then
+                       objects="--whole-archive built-in.o ${1}"
+               else
+                       objects="${KBUILD_VMLINUX_INIT}                 \
+                               --start-group                           \
+                               ${KBUILD_VMLINUX_MAIN}                  \
+                               --end-group                             \
+                               ${1}"
+               fi
+
+               ${LD} ${LDFLAGS} ${LDFLAGS_vmlinux} -o ${2}             \
+                       -T ${lds} ${objects}
        else
-               ${CC} ${CFLAGS_vmlinux} -o ${2}                              \
-                       -Wl,-T,${lds} ${KBUILD_VMLINUX_INIT}                 \
-                       -Wl,--start-group                                    \
-                                ${KBUILD_VMLINUX_MAIN}                      \
-                       -Wl,--end-group                                      \
-                       -lutil -lrt -lpthread ${1}
+               if [ -n "${CONFIG_THIN_ARCHIVES}" ]; then
+                       objects="-Wl,--whole-archive built-in.o ${1}"
+               else
+                       objects="${KBUILD_VMLINUX_INIT}                 \
+                               -Wl,--start-group                       \
+                               ${KBUILD_VMLINUX_MAIN}                  \
+                               -Wl,--end-group                         \
+                               ${1}"
+               fi
+
+               ${CC} ${CFLAGS_vmlinux} -o ${2}                         \
+                       -Wl,-T,${lds}                                   \
+                       ${objects}                                      \
+                       -lutil -lrt -lpthread
                rm -f linux
        fi
 }
@@ -119,6 +165,7 @@ cleanup()
        rm -f .tmp_kallsyms*
        rm -f .tmp_version
        rm -f .tmp_vmlinux*
+       rm -f built-in.o
        rm -f System.map
        rm -f vmlinux
        rm -f vmlinux.o
@@ -162,13 +209,6 @@ case "${KCONFIG_CONFIG}" in
        . "./${KCONFIG_CONFIG}"
 esac
 
-#link vmlinux.o
-info LD vmlinux.o
-modpost_link vmlinux.o
-
-# modpost vmlinux.o to check for section mismatches
-${MAKE} -f "${srctree}/scripts/Makefile.modpost" vmlinux.o
-
 # Update version
 info GEN .version
 if [ ! -r .version ]; then
@@ -182,6 +222,15 @@ fi;
 # final build of init/
 ${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}"
 
+archive_builtin
+
+#link vmlinux.o
+info LD vmlinux.o
+modpost_link vmlinux.o
+
+# modpost vmlinux.o to check for section mismatches
+${MAKE} -f "${srctree}/scripts/Makefile.modpost" vmlinux.o
+
 kallsymso=""
 kallsyms_vmlinux=""
 if [ -n "${CONFIG_KALLSYMS}" ]; then
@@ -197,10 +246,14 @@ if [ -n "${CONFIG_KALLSYMS}" ]; then
        #     the right size, but due to the added section, some
        #     addresses have shifted.
        #     From here, we generate a correct .tmp_kallsyms2.o
-       # 2a) We may use an extra pass as this has been necessary to
-       #     woraround some alignment related bugs.
-       #     KALLSYMS_EXTRA_PASS=1 is used to trigger this.
-       # 3)  The correct ${kallsymso} is linked into the final vmlinux.
+       # 3)  That link may have expanded the kernel image enough that
+       #     more linker branch stubs / trampolines had to be added, which
+       #     introduces new names, which further expands kallsyms. Do another
+       #     pass if that is the case. In theory it's possible this results
+       #     in even more stubs, but unlikely.
+       #     KALLSYMS_EXTRA_PASS=1 may also used to debug or work around
+       #     other bugs.
+       # 4)  The correct ${kallsymso} is linked into the final vmlinux.
        #
        # a)  Verify that the System.map from vmlinux matches the map from
        #     ${kallsymso}.
@@ -216,8 +269,11 @@ if [ -n "${CONFIG_KALLSYMS}" ]; then
        vmlinux_link .tmp_kallsyms1.o .tmp_vmlinux2
        kallsyms .tmp_vmlinux2 .tmp_kallsyms2.o
 
-       # step 2a
-       if [ -n "${KALLSYMS_EXTRA_PASS}" ]; then
+       # step 3
+       size1=$(stat -c "%s" .tmp_kallsyms1.o)
+       size2=$(stat -c "%s" .tmp_kallsyms2.o)
+
+       if [ $size1 -ne $size2 ] || [ -n "${KALLSYMS_EXTRA_PASS}" ]; then
                kallsymso=.tmp_kallsyms3.o
                kallsyms_vmlinux=.tmp_vmlinux3