kbuild: use obj-y instead extra-y for objects placed at the head
authorMasahiro Yamada <masahiroy@kernel.org>
Sat, 24 Sep 2022 18:19:14 +0000 (03:19 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Sun, 2 Oct 2022 09:04:05 +0000 (18:04 +0900)
The objects placed at the head of vmlinux need special treatments:

 - arch/$(SRCARCH)/Makefile adds them to head-y in order to place
   them before other archives in the linker command line.

 - arch/$(SRCARCH)/kernel/Makefile adds them to extra-y instead of
   obj-y to avoid them going into built-in.a.

This commit gets rid of the latter.

Create vmlinux.a to collect all the objects that are unconditionally
linked to vmlinux. The objects listed in head-y are moved to the head
of vmlinux.a by using 'ar m'.

With this, arch/$(SRCARCH)/kernel/Makefile can consistently use obj-y
for builtin objects.

There is no *.o that is directly linked to vmlinux. Drop unneeded code
in scripts/clang-tools/gen_compile_commands.py.

$(AR) mPi needs 'T' to workaround the llvm-ar bug. The fix was suggested
by Nathan Chancellor [1].

[1]: https://lore.kernel.org/llvm/YyjjT5gQ2hGMH0ni@dev-arch.thelio-3990X/

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Tested-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
29 files changed:
Documentation/kbuild/makefiles.rst
Makefile
arch/alpha/kernel/Makefile
arch/arc/kernel/Makefile
arch/arm/kernel/Makefile
arch/arm64/kernel/Makefile
arch/csky/kernel/Makefile
arch/hexagon/kernel/Makefile
arch/ia64/kernel/Makefile
arch/loongarch/kernel/Makefile
arch/m68k/68000/Makefile
arch/m68k/coldfire/Makefile
arch/m68k/kernel/Makefile
arch/microblaze/kernel/Makefile
arch/mips/kernel/Makefile
arch/nios2/kernel/Makefile
arch/openrisc/kernel/Makefile
arch/parisc/kernel/Makefile
arch/powerpc/kernel/Makefile
arch/riscv/kernel/Makefile
arch/s390/kernel/Makefile
arch/sh/kernel/Makefile
arch/sparc/kernel/Makefile
arch/x86/kernel/Makefile
arch/xtensa/kernel/Makefile
scripts/Makefile.modpost
scripts/Makefile.vmlinux_o
scripts/clang-tools/gen_compile_commands.py
scripts/link-vmlinux.sh

index ee7e3ea..5a6a842 100644 (file)
@@ -340,19 +340,7 @@ more details, with real examples.
 
        Examples are:
 
-       1) head objects
-
-           Some objects must be placed at the head of vmlinux. They are
-           directly linked to vmlinux without going through built-in.a
-           A typical use-case is an object that contains the entry point.
-
-           arch/$(SRCARCH)/Makefile should specify such objects as head-y.
-
-           Discussion:
-             Given that we can control the section order in the linker script,
-             why do we need head-y?
-
-       2) vmlinux linker script
+       1) vmlinux linker script
 
            The linker script for vmlinux is located at
            arch/$(SRCARCH)/kernel/vmlinux.lds
@@ -360,10 +348,6 @@ more details, with real examples.
        Example::
 
                # arch/x86/kernel/Makefile
-               extra-y := head_$(BITS).o
-               extra-y += head$(BITS).o
-               extra-y += ebda.o
-               extra-y += platform-quirks.o
                extra-y += vmlinux.lds
 
        $(extra-y) should only contain targets needed for vmlinux.
index 22a956b..8da45f7 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -645,6 +645,8 @@ else
 __all: modules
 endif
 
+targets :=
+
 # Decide whether to build built-in, modular, or both.
 # Normally, just do built-in.
 
@@ -1107,7 +1109,7 @@ export ARCH_LIB           := $(filter %/, $(libs-y))
 export ARCH_DRIVERS    := $(drivers-y) $(drivers-m)
 # Externally visible symbols (used by link-vmlinux.sh)
 
-KBUILD_VMLINUX_OBJS := $(head-y) ./built-in.a
+KBUILD_VMLINUX_OBJS := ./built-in.a
 ifdef CONFIG_MODULES
 KBUILD_VMLINUX_OBJS += $(patsubst %/, %/lib.a, $(filter %/, $(libs-y)))
 KBUILD_VMLINUX_LIBS := $(filter-out %/, $(libs-y))
@@ -1115,7 +1117,7 @@ else
 KBUILD_VMLINUX_LIBS := $(patsubst %/,%/lib.a, $(libs-y))
 endif
 
-export KBUILD_VMLINUX_OBJS KBUILD_VMLINUX_LIBS
+export KBUILD_VMLINUX_LIBS
 export KBUILD_LDS          := arch/$(SRCARCH)/kernel/vmlinux.lds
 
 # Recurse until adjust_autoksyms.sh is satisfied
@@ -1140,7 +1142,18 @@ quiet_cmd_autoksyms_h = GEN     $@
 $(autoksyms_h):
        $(call cmd,autoksyms_h)
 
-vmlinux.o: autoksyms_recursive $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS) FORCE
+# '$(AR) mPi' needs 'T' to workaround the bug of llvm-ar <= 14
+quiet_cmd_ar_vmlinux.a = AR      $@
+      cmd_ar_vmlinux.a = \
+       rm -f $@; \
+       $(AR) cDPrST $@ $(KBUILD_VMLINUX_OBJS); \
+       $(AR) mPiT $$($(AR) t $@ | head -n1) $@ $(head-y)
+
+targets += vmlinux.a
+vmlinux.a: $(KBUILD_VMLINUX_OBJS) autoksyms_recursive FORCE
+       $(call if_changed,ar_vmlinux.a)
+
+vmlinux.o: vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE
        $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vmlinux_o
 
 ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink)
@@ -1153,7 +1166,7 @@ cmd_link-vmlinux =                                                 \
 vmlinux: scripts/link-vmlinux.sh vmlinux.o $(KBUILD_LDS) modpost FORCE
        +$(call if_changed_dep,link-vmlinux)
 
-targets := vmlinux
+targets += vmlinux
 
 # The actual objects are generated when descending,
 # make sure no implicit rule kicks in
@@ -1878,7 +1891,7 @@ quiet_cmd_gen_compile_commands = GEN     $@
       cmd_gen_compile_commands = $(PYTHON3) $< -a $(AR) -o $@ $(filter-out $<, $(real-prereqs))
 
 $(extmod_prefix)compile_commands.json: scripts/clang-tools/gen_compile_commands.py \
-       $(if $(KBUILD_EXTMOD),,$(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS)) \
+       $(if $(KBUILD_EXTMOD),, vmlinux.a $(KBUILD_VMLINUX_LIBS)) \
        $(if $(CONFIG_MODULES), $(MODORDER)) FORCE
        $(call if_changed,gen_compile_commands)
 
index 5a74581..5a5b0a8 100644 (file)
@@ -3,11 +3,11 @@
 # Makefile for the linux kernel.
 #
 
-extra-y                := head.o vmlinux.lds
+extra-y                := vmlinux.lds
 asflags-y      := $(KBUILD_CFLAGS)
 ccflags-y      := -Wno-sign-compare
 
-obj-y    := entry.o traps.o process.o osf_sys.o irq.o \
+obj-y    := head.o entry.o traps.o process.o osf_sys.o irq.o \
            irq_alpha.o signal.o setup.o ptrace.o time.o \
            systbls.o err_common.o io.o bugs.o
 
index 8c4fc4b..0723d88 100644 (file)
@@ -3,7 +3,7 @@
 # Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
 #
 
-obj-y  := arcksyms.o setup.o irq.o reset.o ptrace.o process.o devtree.o
+obj-y  := head.o arcksyms.o setup.o irq.o reset.o ptrace.o process.o devtree.o
 obj-y  += signal.o traps.o sys.o troubleshoot.o stacktrace.o disasm.o
 obj-$(CONFIG_ISA_ARCOMPACT)            += entry-compact.o intc-compact.o
 obj-$(CONFIG_ISA_ARCV2)                        += entry-arcv2.o intc-arcv2.o
@@ -31,4 +31,4 @@ else
 obj-y += ctx_sw_asm.o
 endif
 
-extra-y := vmlinux.lds head.o
+extra-y := vmlinux.lds
index 5538667..8feaa32 100644 (file)
@@ -89,7 +89,7 @@ obj-$(CONFIG_VDSO)            += vdso.o
 obj-$(CONFIG_EFI)              += efi.o
 obj-$(CONFIG_PARAVIRT) += paravirt.o
 
-head-y                 := head$(MMUEXT).o
+obj-y                  += head$(MMUEXT).o
 obj-$(CONFIG_DEBUG_LL) += debug.o
 obj-$(CONFIG_EARLY_PRINTK)     += early_printk.o
 obj-$(CONFIG_ARM_PATCH_PHYS_VIRT)      += phys2virt.o
@@ -109,4 +109,4 @@ obj-$(CONFIG_HAVE_ARM_SMCCC)        += smccc-call.o
 
 obj-$(CONFIG_GENERIC_CPU_VULNERABILITIES) += spectre.o
 
-extra-y := $(head-y) vmlinux.lds
+extra-y := vmlinux.lds
index 1add7b0..b619ff2 100644 (file)
@@ -85,8 +85,8 @@ $(obj)/vdso-wrap.o: $(obj)/vdso/vdso.so
 $(obj)/vdso32-wrap.o: $(obj)/vdso32/vdso.so
 
 obj-y                                  += probes/
-head-y                                 := head.o
-extra-y                                        += $(head-y) vmlinux.lds
+obj-y                                  += head.o
+extra-y                                        += vmlinux.lds
 
 ifeq ($(CONFIG_DEBUG_EFI),y)
 AFLAGS_head.o += -DVMLINUX_PATH="\"$(realpath $(objtree)/vmlinux)\""
index 6f14c92..8a86831 100644 (file)
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
-extra-y := head.o vmlinux.lds
+extra-y := vmlinux.lds
 
-obj-y += entry.o atomic.o signal.o traps.o irq.o time.o vdso.o vdso/
+obj-y += head.o entry.o atomic.o signal.o traps.o irq.o time.o vdso.o vdso/
 obj-y += power.o syscall.o syscall_table.o setup.o io.o
 obj-y += process.o cpu-probe.o ptrace.o stacktrace.o
 obj-y += probes/
index fae3dce..e73cb32 100644 (file)
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
-extra-y := head.o vmlinux.lds
+extra-y := vmlinux.lds
 
+obj-y += head.o
 obj-$(CONFIG_SMP) += smp.o
 
 obj-y += setup.o irq_cpu.o traps.o syscalltab.o signal.o time.o
index 08d4a2b..4a1fcb1 100644 (file)
@@ -7,9 +7,9 @@ ifdef CONFIG_DYNAMIC_FTRACE
 CFLAGS_REMOVE_ftrace.o = -pg
 endif
 
-extra-y        := head.o vmlinux.lds
+extra-y        := vmlinux.lds
 
-obj-y := entry.o efi.o efi_stub.o gate-data.o fsys.o irq.o irq_ia64.o  \
+obj-y := head.o entry.o efi.o efi_stub.o gate-data.o fsys.o irq.o irq_ia64.o   \
         irq_lsapic.o ivt.o pal.o patch.o process.o ptrace.o sal.o              \
         salinfo.o setup.o signal.o sys_ia64.o time.o traps.o unaligned.o \
         unwind.o mca.o mca_asm.o topology.o dma-mapping.o iosapic.o acpi.o \
index e5be170..6c33b5c 100644 (file)
@@ -3,9 +3,9 @@
 # Makefile for the Linux/LoongArch kernel.
 #
 
-extra-y                := head.o vmlinux.lds
+extra-y                := vmlinux.lds
 
-obj-y          += cpu-probe.o cacheinfo.o env.o setup.o entry.o genex.o \
+obj-y          += head.o cpu-probe.o cacheinfo.o env.o setup.o entry.o genex.o \
                   traps.o irq.o idle.o process.o dma.o mem.o io.o reset.o switch.o \
                   elf.o syscall.o signal.o time.o topology.o inst.o ptrace.o vdso.o
 
index 674541f..279560a 100644 (file)
@@ -17,4 +17,4 @@ obj-$(CONFIG_DRAGEN2) += dragen2.o
 obj-$(CONFIG_UCSIMM)   += ucsimm.o
 obj-$(CONFIG_UCDIMM)   += ucsimm.o
 
-extra-y                := head.o
+obj-y                  += head.o
index 9419a6c..c56bc0d 100644 (file)
@@ -45,4 +45,4 @@ obj-$(CONFIG_STMARK2) += stmark2.o
 obj-$(CONFIG_PCI)      += pci.o
 
 obj-y                  += gpio.o
-extra-y := head.o
+obj-y                  += head.o
index c0833da..af01544 100644 (file)
@@ -3,19 +3,20 @@
 # Makefile for the linux kernel.
 #
 
-extra-$(CONFIG_AMIGA)  := head.o
-extra-$(CONFIG_ATARI)  := head.o
-extra-$(CONFIG_MAC)    := head.o
-extra-$(CONFIG_APOLLO) := head.o
-extra-$(CONFIG_VME)    := head.o
-extra-$(CONFIG_HP300)  := head.o
-extra-$(CONFIG_Q40)    := head.o
-extra-$(CONFIG_SUN3X)  := head.o
-extra-$(CONFIG_VIRT)   := head.o
-extra-$(CONFIG_SUN3)   := sun3-head.o
 extra-y                        += vmlinux.lds
 
-obj-y  := entry.o irq.o module.o process.o ptrace.o
+obj-$(CONFIG_AMIGA)    := head.o
+obj-$(CONFIG_ATARI)    := head.o
+obj-$(CONFIG_MAC)      := head.o
+obj-$(CONFIG_APOLLO)   := head.o
+obj-$(CONFIG_VME)      := head.o
+obj-$(CONFIG_HP300)    := head.o
+obj-$(CONFIG_Q40)      := head.o
+obj-$(CONFIG_SUN3X)    := head.o
+obj-$(CONFIG_VIRT)     := head.o
+obj-$(CONFIG_SUN3)     := sun3-head.o
+
+obj-y  += entry.o irq.o module.o process.o ptrace.o
 obj-y  += setup.o signal.o sys_m68k.o syscalltable.o time.o traps.o
 
 obj-$(CONFIG_MMU_MOTOROLA) += ints.o vectors.o
index 15a20eb..4393bee 100644 (file)
@@ -12,9 +12,9 @@ CFLAGS_REMOVE_ftrace.o = -pg
 CFLAGS_REMOVE_process.o = -pg
 endif
 
-extra-y := head.o vmlinux.lds
+extra-y := vmlinux.lds
 
-obj-y += dma.o exceptions.o \
+obj-y += head.o dma.o exceptions.o \
        hw_exception_handler.o irq.o \
        process.o prom.o ptrace.o \
        reset.o setup.o signal.o sys_microblaze.o timer.o traps.o unwind.o
index 7c96282..5d1adda 100644 (file)
@@ -3,9 +3,9 @@
 # Makefile for the Linux/MIPS kernel.
 #
 
-extra-y                := head.o vmlinux.lds
+extra-y                := vmlinux.lds
 
-obj-y          += branch.o cmpxchg.o elf.o entry.o genex.o idle.o irq.o \
+obj-y          += head.o branch.o cmpxchg.o elf.o entry.o genex.o idle.o irq.o \
                   process.o prom.o ptrace.o reset.o setup.o signal.o \
                   syscall.o time.o topology.o traps.o unaligned.o watch.o \
                   vdso.o cacheinfo.o
index 0b645e1..78a9131 100644 (file)
@@ -3,9 +3,9 @@
 # Makefile for the nios2 linux kernel.
 #
 
-extra-y        += head.o
 extra-y        += vmlinux.lds
 
+obj-y  += head.o
 obj-y  += cpuinfo.o
 obj-y  += entry.o
 obj-y  += insnemu.o
index 2d172e7..7912916 100644 (file)
@@ -3,9 +3,9 @@
 # Makefile for the linux kernel.
 #
 
-extra-y        := head.o vmlinux.lds
+extra-y        := vmlinux.lds
 
-obj-y  := setup.o or32_ksyms.o process.o dma.o \
+obj-y  := head.o setup.o or32_ksyms.o process.o dma.o \
           traps.o time.o irq.o entry.o ptrace.o signal.o \
           sys_call_table.o unwinder.o
 
index d0bfac8..3d138c9 100644 (file)
@@ -3,9 +3,9 @@
 # Makefile for arch/parisc/kernel
 #
 
-extra-y                        := head.o vmlinux.lds
+extra-y                := vmlinux.lds
 
-obj-y          := cache.o pacache.o setup.o pdt.o traps.o time.o irq.o \
+obj-y          := head.o cache.o pacache.o setup.o pdt.o traps.o time.o irq.o \
                   pa7300lc.o syscall.o entry.o sys_parisc.o firmware.o \
                   ptrace.o hardware.o inventory.o drivers.o alternative.o \
                   signal.o hpmc.o real2.o parisc_ksyms.o unaligned.o \
index 06d2d1f..ad3decb 100644 (file)
@@ -118,12 +118,12 @@ obj-$(CONFIG_PPC_FSL_BOOK3E)      += cpu_setup_fsl_booke.o
 obj-$(CONFIG_PPC_DOORBELL)     += dbell.o
 obj-$(CONFIG_JUMP_LABEL)       += jump_label.o
 
-extra-$(CONFIG_PPC64)          := head_64.o
-extra-$(CONFIG_PPC_BOOK3S_32)  := head_book3s_32.o
-extra-$(CONFIG_40x)            := head_40x.o
-extra-$(CONFIG_44x)            := head_44x.o
-extra-$(CONFIG_FSL_BOOKE)      := head_fsl_booke.o
-extra-$(CONFIG_PPC_8xx)                := head_8xx.o
+obj-$(CONFIG_PPC64)            += head_64.o
+obj-$(CONFIG_PPC_BOOK3S_32)    += head_book3s_32.o
+obj-$(CONFIG_40x)              += head_40x.o
+obj-$(CONFIG_44x)              += head_44x.o
+obj-$(CONFIG_FSL_BOOKE)                += head_fsl_booke.o
+obj-$(CONFIG_PPC_8xx)          += head_8xx.o
 extra-y                                += vmlinux.lds
 
 obj-$(CONFIG_RELOCATABLE)      += reloc_$(BITS).o
@@ -198,10 +198,10 @@ KCOV_INSTRUMENT_paca.o := n
 CFLAGS_setup_64.o              += -fno-stack-protector
 CFLAGS_paca.o                  += -fno-stack-protector
 
-extra-$(CONFIG_PPC_FPU)                += fpu.o
-extra-$(CONFIG_ALTIVEC)                += vector.o
-extra-$(CONFIG_PPC64)          += entry_64.o
-extra-$(CONFIG_PPC_OF_BOOT_TRAMPOLINE) += prom_init.o
+obj-$(CONFIG_PPC_FPU)          += fpu.o
+obj-$(CONFIG_ALTIVEC)          += vector.o
+obj-$(CONFIG_PPC64)            += entry_64.o
+obj-$(CONFIG_PPC_OF_BOOT_TRAMPOLINE)   += prom_init.o
 
 extra-$(CONFIG_PPC_OF_BOOT_TRAMPOLINE) += prom_init_check
 
index 33bb60a..db6e4b1 100644 (file)
@@ -28,9 +28,9 @@ KASAN_SANITIZE_cpufeature.o := n
 endif
 endif
 
-extra-y += head.o
 extra-y += vmlinux.lds
 
+obj-y  += head.o
 obj-y  += soc.o
 obj-$(CONFIG_RISCV_ALTERNATIVE) += alternative.o
 obj-y  += cpu.o
index 3cbfa9f..7ce0081 100644 (file)
@@ -33,7 +33,7 @@ CFLAGS_stacktrace.o   += -fno-optimize-sibling-calls
 CFLAGS_dumpstack.o     += -fno-optimize-sibling-calls
 CFLAGS_unwind_bc.o     += -fno-optimize-sibling-calls
 
-obj-y  := traps.o time.o process.o earlypgm.o early.o setup.o idle.o vtime.o
+obj-y  := head64.o traps.o time.o process.o earlypgm.o early.o setup.o idle.o vtime.o
 obj-y  += processor.o syscall.o ptrace.o signal.o cpcmd.o ebcdic.o nmi.o
 obj-y  += debug.o irq.o ipl.o dis.o diag.o vdso.o cpufeature.o
 obj-y  += sysinfo.o lgr.o os_info.o machine_kexec.o
@@ -42,7 +42,7 @@ obj-y += entry.o reipl.o relocate_kernel.o kdebugfs.o alternative.o
 obj-y  += nospec-branch.o ipl_vmparm.o machine_kexec_reloc.o unwind_bc.o
 obj-y  += smp.o text_amode31.o stacktrace.o
 
-extra-y                                += head64.o vmlinux.lds
+extra-y                                += vmlinux.lds
 
 obj-$(CONFIG_SYSFS)            += nospec-sysfs.o
 CFLAGS_REMOVE_nospec-branch.o  += $(CC_FLAGS_EXPOLINE)
index aa0fbc9..69cd9ac 100644 (file)
@@ -3,7 +3,7 @@
 # Makefile for the Linux/SuperH kernel.
 #
 
-extra-y        := head_32.o vmlinux.lds
+extra-y        := vmlinux.lds
 
 ifdef CONFIG_FUNCTION_TRACER
 # Do not profile debug and lowlevel utilities
@@ -12,7 +12,7 @@ endif
 
 CFLAGS_REMOVE_return_address.o = -pg
 
-obj-y  := debugtraps.o dumpstack.o             \
+obj-y  := head_32.o debugtraps.o dumpstack.o                           \
           idle.o io.o irq.o irq_32.o kdebugfs.o                        \
           machvec.o nmi_debug.o process.o                              \
           process_32.o ptrace.o ptrace_32.o                            \
index d3a0e07..b328e4a 100644 (file)
@@ -7,8 +7,6 @@
 asflags-y := -ansi
 ccflags-y := -Werror
 
-extra-y     := head_$(BITS).o
-
 # Undefine sparc when processing vmlinux.lds - it is used
 # And teach CPP we are doing $(BITS) builds (for this case)
 CPPFLAGS_vmlinux.lds := -Usparc -m$(BITS)
@@ -22,6 +20,7 @@ CFLAGS_REMOVE_perf_event.o := -pg
 CFLAGS_REMOVE_pcr.o := -pg
 endif
 
+obj-y                   := head_$(BITS).o
 obj-$(CONFIG_SPARC64)   += urtt_fill.o
 obj-$(CONFIG_SPARC32)   += entry.o wof.o wuf.o
 obj-$(CONFIG_SPARC32)   += etrap_32.o
index a20a5eb..956e50c 100644 (file)
@@ -3,10 +3,6 @@
 # Makefile for the linux kernel.
 #
 
-extra-y        := head_$(BITS).o
-extra-y        += head$(BITS).o
-extra-y        += ebda.o
-extra-y        += platform-quirks.o
 extra-y        += vmlinux.lds
 
 CPPFLAGS_vmlinux.lds += -U$(UTS_MACHINE)
@@ -42,7 +38,11 @@ KCOV_INSTRUMENT              := n
 
 CFLAGS_irq.o := -I $(srctree)/$(src)/../include/asm/trace
 
-obj-y                  := process_$(BITS).o signal.o
+obj-y                  += head_$(BITS).o
+obj-y                  += head$(BITS).o
+obj-y                  += ebda.o
+obj-y                  += platform-quirks.o
+obj-y                  += process_$(BITS).o signal.o
 obj-$(CONFIG_COMPAT)   += signal_compat.o
 obj-y                  += traps.o idt.o irq.o irq_$(BITS).o dumpstack_$(BITS).o
 obj-y                  += time.o ioport.o dumpstack.o nmi.o
index 897c1c7..f28b8e3 100644 (file)
@@ -3,9 +3,9 @@
 # Makefile for the Linux/Xtensa kernel.
 #
 
-extra-y := head.o vmlinux.lds
+extra-y := vmlinux.lds
 
-obj-y := align.o coprocessor.o entry.o irq.o platform.o process.o \
+obj-y := head.o align.o coprocessor.o entry.o irq.o platform.o process.o \
         ptrace.o setup.o signal.o stacktrace.o syscall.o time.o traps.o \
         vectors.o
 
index 40a3e9b..7740ce3 100644 (file)
@@ -70,13 +70,12 @@ quiet_cmd_vmlinux_objs = GEN     $@
        for f in $(real-prereqs); do    \
                case $${f} in           \
                *libgcc.a) ;;           \
-               *.a) $(AR) t $${f} ;;   \
-               *) echo $${f} ;;        \
+               *) $(AR) t $${f} ;;     \
                esac                    \
        done > $@
 
 targets += .vmlinux.objs
-.vmlinux.objs: $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS) FORCE
+.vmlinux.objs: vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE
        $(call if_changed,vmlinux_objs)
 
 vmlinux.o-if-present := $(wildcard vmlinux.o)
index 7d531b8..68c2287 100644 (file)
@@ -18,7 +18,7 @@ quiet_cmd_gen_initcalls_lds = GEN     $@
        $(PERL) $(real-prereqs) > $@
 
 .tmp_initcalls.lds: $(srctree)/scripts/generate_initcall_order.pl \
-               $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS) FORCE
+               vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE
        $(call if_changed,gen_initcalls_lds)
 
 targets := .tmp_initcalls.lds
@@ -48,7 +48,7 @@ quiet_cmd_ld_vmlinux.o = LD      $@
       cmd_ld_vmlinux.o = \
        $(LD) ${KBUILD_LDFLAGS} -r -o $@ \
        $(addprefix -T , $(initcalls-lds)) \
-       --whole-archive $(KBUILD_VMLINUX_OBJS) --no-whole-archive \
+       --whole-archive vmlinux.a --no-whole-archive \
        --start-group $(KBUILD_VMLINUX_LIBS) --end-group \
        $(cmd_objtool)
 
@@ -57,7 +57,7 @@ define rule_ld_vmlinux.o
        $(call cmd,gen_objtooldep)
 endef
 
-vmlinux.o: $(initcalls-lds) $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS) FORCE
+vmlinux.o: $(initcalls-lds) vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE
        $(call if_changed_rule,ld_vmlinux.o)
 
 targets += vmlinux.o
index 47da25b..d800b2c 100755 (executable)
@@ -109,20 +109,6 @@ def to_cmdfile(path):
     return os.path.join(dir, '.' + base + '.cmd')
 
 
-def cmdfiles_for_o(obj):
-    """Generate the iterator of .cmd files associated with the object
-
-    Yield the .cmd file used to build the given object
-
-    Args:
-        obj: The object path
-
-    Yields:
-        The path to .cmd file
-    """
-    yield to_cmdfile(obj)
-
-
 def cmdfiles_for_a(archive, ar):
     """Generate the iterator of .cmd files associated with the archive.
 
@@ -211,13 +197,10 @@ def main():
     for path in paths:
         # If 'path' is a directory, handle all .cmd files under it.
         # Otherwise, handle .cmd files associated with the file.
-        # Most of built-in objects are linked via archives (built-in.a or lib.a)
-        # but some objects are linked to vmlinux directly.
+        # built-in objects are linked via vmlinux.a
         # Modules are listed in modules.order.
         if os.path.isdir(path):
             cmdfiles = cmdfiles_in_dir(path)
-        elif path.endswith('.o'):
-            cmdfiles = cmdfiles_for_o(path)
         elif path.endswith('.a'):
             cmdfiles = cmdfiles_for_a(path, ar)
         elif path.endswith('modules.order'):
index 6a197d8..23ac13f 100755 (executable)
@@ -3,17 +3,15 @@
 #
 # link vmlinux
 #
-# vmlinux is linked from the objects selected by $(KBUILD_VMLINUX_OBJS) and
-# $(KBUILD_VMLINUX_LIBS). Most are built-in.a files from top-level directories
-# in the kernel tree, others are specified in arch/$(ARCH)/Makefile.
+# vmlinux is linked from the objects in vmlinux.a and $(KBUILD_VMLINUX_LIBS).
+# vmlinux.a contains objects that are linked unconditionally.
 # $(KBUILD_VMLINUX_LIBS) are archives which are linked conditionally
 # (not within --whole-archive), and do not require symbol indexes added.
 #
 # vmlinux
 #   ^
 #   |
-#   +--< $(KBUILD_VMLINUX_OBJS)
-#   |    +--< init/built-in.a drivers/built-in.a mm/built-in.a + more
+#   +--< vmlinux.a
 #   |
 #   +--< $(KBUILD_VMLINUX_LIBS)
 #   |    +--< lib/lib.a + more
@@ -67,7 +65,7 @@ vmlinux_link()
                objs=vmlinux.o
                libs=
        else
-               objs="${KBUILD_VMLINUX_OBJS}"
+               objs=vmlinux.a
                libs="${KBUILD_VMLINUX_LIBS}"
        fi