]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - scripts/link-vmlinux.sh
kbuild: handle libs-y archives separately from built-in.o archives
[karo-tx-linux.git] / scripts / link-vmlinux.sh
index c80291319cb2e20e15df93b685b8065ffdd9742e..e7b7eee31538e69963874ae3e326a254dac54622 100755 (executable)
@@ -3,9 +3,12 @@
 # link vmlinux
 #
 # vmlinux is linked from the objects selected by $(KBUILD_VMLINUX_INIT) and
-# $(KBUILD_VMLINUX_MAIN). Most are built-in.o files from top-level directories
-# in the kernel tree, others are specified in arch/$(ARCH)/Makefile.
-# Ordering when linking is important, and $(KBUILD_VMLINUX_INIT) must be first.
+# $(KBUILD_VMLINUX_MAIN) and $(KBUILD_VMLINUX_LIBS). Most are built-in.o files
+# from top-level directories in the kernel tree, others are specified in
+# arch/$(ARCH)/Makefile. Ordering when linking is important, and
+# $(KBUILD_VMLINUX_INIT) must be first. $(KBUILD_VMLINUX_LIBS) are archives
+# which are linked conditionally (not within --whole-archive), and do not
+# require symbol indexes added.
 #
 # vmlinux
 #   ^
@@ -16,6 +19,9 @@
 #   +--< $(KBUILD_VMLINUX_MAIN)
 #   |    +--< drivers/built-in.o mm/built-in.o + more
 #   |
+#   +--< $(KBUILD_VMLINUX_LIBS)
+#   |    +--< lib/lib.a + more
+#   |
 #   +-< ${kallsymso} (see description in KALLSYMS section)
 #
 # vmlinux version (uname -v) cannot be updated during normal
@@ -37,9 +43,10 @@ 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.
+# Thin archive build here makes a final archive with symbol table and indexes
+# from vmlinux objects INIT and MAIN, which can be used as input to linker.
+# KBUILD_VMLINUX_LIBS archives should already have symbol table and indexes
+# added.
 #
 # Traditional incremental style of link does not require this step
 #
@@ -50,7 +57,7 @@ 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                  \
+               ${AR} rcsTP${KBUILD_ARFLAGS} built-in.o                 \
                                        ${KBUILD_VMLINUX_INIT}          \
                                        ${KBUILD_VMLINUX_MAIN}
        fi
@@ -63,11 +70,17 @@ modpost_link()
        local objects
 
        if [ -n "${CONFIG_THIN_ARCHIVES}" ]; then
-               objects="--whole-archive built-in.o"
+               objects="--whole-archive                                \
+                       built-in.o                                      \
+                       --no-whole-archive                              \
+                       --start-group                                   \
+                       ${KBUILD_VMLINUX_LIBS}                          \
+                       --end-group"
        else
                objects="${KBUILD_VMLINUX_INIT}                         \
                        --start-group                                   \
                        ${KBUILD_VMLINUX_MAIN}                          \
+                       ${KBUILD_VMLINUX_LIBS}                          \
                        --end-group"
        fi
        ${LD} ${LDFLAGS} -r -o ${1} ${objects}
@@ -83,11 +96,18 @@ vmlinux_link()
 
        if [ "${SRCARCH}" != "um" ]; then
                if [ -n "${CONFIG_THIN_ARCHIVES}" ]; then
-                       objects="--whole-archive built-in.o ${1}"
+                       objects="--whole-archive                        \
+                               built-in.o                              \
+                               --no-whole-archive                      \
+                               --start-group                           \
+                               ${KBUILD_VMLINUX_LIBS}                  \
+                               --end-group                             \
+                               ${1}"
                else
                        objects="${KBUILD_VMLINUX_INIT}                 \
                                --start-group                           \
                                ${KBUILD_VMLINUX_MAIN}                  \
+                               ${KBUILD_VMLINUX_LIBS}                  \
                                --end-group                             \
                                ${1}"
                fi
@@ -96,11 +116,18 @@ vmlinux_link()
                        -T ${lds} ${objects}
        else
                if [ -n "${CONFIG_THIN_ARCHIVES}" ]; then
-                       objects="-Wl,--whole-archive built-in.o ${1}"
+                       objects="-Wl,--whole-archive                    \
+                               built-in.o                              \
+                               -Wl,--no-whole-archive                  \
+                               -Wl,--start-group                       \
+                               ${KBUILD_VMLINUX_LIBS}                  \
+                               -Wl,--end-group                         \
+                               ${1}"
                else
                        objects="${KBUILD_VMLINUX_INIT}                 \
                                -Wl,--start-group                       \
                                ${KBUILD_VMLINUX_MAIN}                  \
+                               ${KBUILD_VMLINUX_LIBS}                  \
                                -Wl,--end-group                         \
                                ${1}"
                fi