Commit 32164845 authored by Masahiro Yamada's avatar Masahiro Yamada
Browse files

kbuild: use obj-y instead extra-y for objects placed at the head

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: default avatarMasahiro Yamada <masahiroy@kernel.org>
Tested-by: default avatarNick Desaulniers <ndesaulniers@google.com>
Reviewed-by: default avatarNicolas Schier <nicolas@fjasle.eu>
parent 4b098659
Loading
Loading
Loading
Loading
+1 −17
Original line number Diff line number Diff line
@@ -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.
+18 −5
Original line number Diff line number Diff line
@@ -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)

+2 −2
Original line number Diff line number Diff line
@@ -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

+2 −2
Original line number Diff line number Diff line
@@ -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
+2 −2
Original line number Diff line number Diff line
@@ -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
Loading