kbuild: remove head-y syntax
authorMasahiro Yamada <masahiroy@kernel.org>
Sat, 24 Sep 2022 18:19:15 +0000 (03:19 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Sun, 2 Oct 2022 09:06:03 +0000 (18:06 +0900)
Kbuild puts the objects listed in head-y at the head of vmlinux.
Conventionally, we do this for head*.S, which contains the kernel entry
point.

A counter approach is to control the section order by the linker script.
Actually, the code marked as __HEAD goes into the ".head.text" section,
which is placed before the normal ".text" section.

I do not know if both of them are needed. From the build system
perspective, head-y is not mandatory. If you can achieve the proper code
placement by the linker script only, it would be cleaner.

I collected the current head-y objects into head-object-list.txt. It is
a whitelist. My hope is it will be reduced in the long run.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Tested-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
24 files changed:
Documentation/kbuild/makefiles.rst
Makefile
arch/alpha/Makefile
arch/arc/Makefile
arch/arm/Makefile
arch/arm64/Makefile
arch/csky/Makefile
arch/hexagon/Makefile
arch/ia64/Makefile
arch/loongarch/Makefile
arch/m68k/Makefile
arch/microblaze/Makefile
arch/mips/Makefile
arch/nios2/Makefile
arch/openrisc/Makefile
arch/parisc/Makefile
arch/powerpc/Makefile
arch/riscv/Makefile
arch/s390/Makefile
arch/sh/Makefile
arch/sparc/Makefile
arch/x86/Makefile
arch/xtensa/Makefile
scripts/head-object-list.txt [new file with mode: 0644]

index 5a6a842..60134dd 100644 (file)
@@ -1070,8 +1070,7 @@ When kbuild executes, the following steps are followed (roughly):
    - The values of the above variables are expanded in arch/$(SRCARCH)/Makefile.
 5) All object files are then linked and the resulting file vmlinux is
    located at the root of the obj tree.
-   The very first objects linked are listed in head-y, assigned by
-   arch/$(SRCARCH)/Makefile.
+   The very first objects linked are listed in scripts/head-object-list.txt.
 6) Finally, the architecture-specific part does any required post processing
    and builds the final bootimage.
    - This includes building boot records
@@ -1219,6 +1218,9 @@ When kbuild executes, the following steps are followed (roughly):
        All object files for vmlinux. They are linked to vmlinux in the same
        order as listed in KBUILD_VMLINUX_OBJS.
 
+       The objects listed in scripts/head-object-list.txt are exceptions;
+       they are placed before the other objects.
+
     KBUILD_VMLINUX_LIBS
 
        All .a "lib" files for vmlinux. KBUILD_VMLINUX_OBJS and
@@ -1262,8 +1264,7 @@ When kbuild executes, the following steps are followed (roughly):
        machinery is all architecture-independent.
 
 
-       head-y, core-y, libs-y, drivers-y
-           $(head-y) lists objects to be linked first in vmlinux.
+       core-y, libs-y, drivers-y
 
            $(libs-y) lists directories where a lib.a archive can be located.
 
index 8da45f7..e4186c1 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1147,10 +1147,10 @@ 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)
+       $(AR) mPiT $$($(AR) t $@ | head -n1) $@ $$($(AR) t $@ | grep -F --file=$(srctree)/scripts/head-object-list.txt)
 
 targets += vmlinux.a
-vmlinux.a: $(KBUILD_VMLINUX_OBJS) autoksyms_recursive FORCE
+vmlinux.a: $(KBUILD_VMLINUX_OBJS) scripts/head-object-list.txt autoksyms_recursive FORCE
        $(call if_changed,ar_vmlinux.a)
 
 vmlinux.o: vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE
index 881cb91..4515802 100644 (file)
@@ -36,8 +36,6 @@ cflags-y                              += $(cpuflags-y)
 # BWX is most important, but we don't really want any emulation ever.
 KBUILD_CFLAGS += $(cflags-y) -Wa,-mev6
 
-head-y := arch/alpha/kernel/head.o
-
 libs-y                         += arch/alpha/lib/
 
 # export what is needed by arch/alpha/boot/Makefile
index efc54f3..329400a 100644 (file)
@@ -82,8 +82,6 @@ KBUILD_CFLAGS += $(cflags-y)
 KBUILD_AFLAGS  += $(KBUILD_CFLAGS)
 KBUILD_LDFLAGS += $(ldflags-y)
 
-head-y         := arch/arc/kernel/head.o
-
 # w/o this dtb won't embed into kernel binary
 core-y         += arch/arc/boot/dts/
 
index 56f655d..29d15c9 100644 (file)
@@ -134,9 +134,6 @@ KBUILD_AFLAGS       +=$(CFLAGS_ABI) $(AFLAGS_ISA) $(arch-y) $(tune-y) -include asm/uni
 
 CHECKFLAGS     += -D__arm__
 
-#Default value
-head-y         := arch/arm/kernel/head$(MMUEXT).o
-
 # Text offset. This list is sorted numerically by address in order to
 # provide a means to avoid/resolve conflicts in multi-arch kernels.
 # Note: the 32kB below this value is reserved for use by the kernel
index 6d9d4a5..6e03f15 100644 (file)
@@ -133,9 +133,6 @@ ifeq ($(CONFIG_DYNAMIC_FTRACE_WITH_REGS),y)
   CC_FLAGS_FTRACE := -fpatchable-function-entry=2
 endif
 
-# Default value
-head-y         := arch/arm64/kernel/head.o
-
 ifeq ($(CONFIG_KASAN_SW_TAGS), y)
 KASAN_SHADOW_SCALE_SHIFT := 4
 else ifeq ($(CONFIG_KASAN_GENERIC), y)
index 4e1d619..0e4237e 100644 (file)
@@ -59,8 +59,6 @@ LDFLAGS += -EL
 
 KBUILD_AFLAGS += $(KBUILD_CFLAGS)
 
-head-y := arch/csky/kernel/head.o
-
 core-y += arch/csky/$(CSKYABI)/
 
 libs-y += arch/csky/lib/ \
index 44312bc..92d0059 100644 (file)
@@ -32,5 +32,3 @@ KBUILD_LDFLAGS += $(ldflags-y)
 TIR_NAME := r19
 KBUILD_CFLAGS += -ffixed-$(TIR_NAME) -DTHREADINFO_REG=$(TIR_NAME) -D__linux__
 KBUILD_AFLAGS += -DTHREADINFO_REG=$(TIR_NAME)
-
-head-y := arch/hexagon/kernel/head.o
index e55c2f1..56c4bb2 100644 (file)
@@ -44,7 +44,6 @@ quiet_cmd_objcopy = OBJCOPY $@
 cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
 
 KBUILD_CFLAGS += $(cflags-y)
-head-y := arch/ia64/kernel/head.o
 
 libs-y                         += arch/ia64/lib/
 
index ec3de61..131fc21 100644 (file)
@@ -72,8 +72,6 @@ CHECKFLAGS += $(shell $(CC) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \
        sed -e "s/^\#define /-D'/" -e "s/ /'='/" -e "s/$$/'/" -e 's/\$$/&&/g')
 endif
 
-head-y := arch/loongarch/kernel/head.o
-
 libs-y += arch/loongarch/lib/
 
 ifeq ($(KBUILD_EXTMOD),)
index e358605..43e3904 100644 (file)
@@ -86,15 +86,6 @@ ifdef CONFIG_KGDB
 KBUILD_CFLAGS := $(subst -fomit-frame-pointer,,$(KBUILD_CFLAGS)) -g
 endif
 
-#
-# Select the assembler head startup code. Order is important. The default
-# head code is first, processor specific selections can override it after.
-#
-head-y                         := arch/m68k/kernel/head.o
-head-$(CONFIG_SUN3)            := arch/m68k/kernel/sun3-head.o
-head-$(CONFIG_M68000)          := arch/m68k/68000/head.o
-head-$(CONFIG_COLDFIRE)                := arch/m68k/coldfire/head.o
-
 libs-y                         += arch/m68k/lib/
 
 
index 1826d9c..3f8a86c 100644 (file)
@@ -48,7 +48,6 @@ CPUFLAGS-1 += $(call cc-option,-mcpu=v$(CPU_VER))
 # r31 holds current when in kernel mode
 KBUILD_CFLAGS += -ffixed-r31 $(CPUFLAGS-y) $(CPUFLAGS-1) $(CPUFLAGS-2)
 
-head-y := arch/microblaze/kernel/head.o
 libs-y += arch/microblaze/lib/
 
 boot := arch/microblaze/boot
index 4d2a3e7..b296e33 100644 (file)
@@ -324,8 +324,6 @@ endif
 
 OBJCOPYFLAGS           += --remove-section=.reginfo
 
-head-y := arch/mips/kernel/head.o
-
 libs-y                 += arch/mips/lib/
 libs-$(CONFIG_MIPS_FP_SUPPORT) += arch/mips/math-emu/
 
index 3f34e68..f1ff4ce 100644 (file)
@@ -37,7 +37,6 @@ KBUILD_CFLAGS += -DUTS_SYSNAME=\"$(UTS_SYSNAME)\"
 KBUILD_CFLAGS += -fno-builtin
 KBUILD_CFLAGS += -G 0
 
-head-y         := arch/nios2/kernel/head.o
 libs-y         += arch/nios2/lib/ $(LIBGCC)
 
 INSTALL_PATH ?= /tftpboot
index b446510..6824952 100644 (file)
@@ -55,8 +55,6 @@ ifeq ($(CONFIG_OPENRISC_HAVE_INST_SEXT),y)
        KBUILD_CFLAGS += $(call cc-option,-msext)
 endif
 
-head-y                 := arch/openrisc/kernel/head.o
-
 libs-y         += $(LIBGCC)
 
 PHONY += vmlinux.bin
index e38d993..a2d8600 100644 (file)
@@ -113,8 +113,6 @@ cflags-$(CONFIG_PA7100LC)   += -march=1.1 -mschedule=7100LC
 cflags-$(CONFIG_PA7300LC)      += -march=1.1 -mschedule=7300
 cflags-$(CONFIG_PA8X00)                += -march=2.0 -mschedule=8000
 
-head-y                 := arch/parisc/kernel/head.o 
-
 KBUILD_CFLAGS  += $(cflags-y)
 LIBGCC         := $(shell $(CC) -print-libgcc-file-name)
 export LIBGCC
index 02742fa..89c2782 100644 (file)
@@ -226,18 +226,6 @@ KBUILD_CFLAGS += $(cpu-as-y)
 KBUILD_AFLAGS += $(aflags-y)
 KBUILD_CFLAGS += $(cflags-y)
 
-head-$(CONFIG_PPC64)           := arch/powerpc/kernel/head_64.o
-head-$(CONFIG_PPC_BOOK3S_32)   := arch/powerpc/kernel/head_book3s_32.o
-head-$(CONFIG_PPC_8xx)         := arch/powerpc/kernel/head_8xx.o
-head-$(CONFIG_40x)             := arch/powerpc/kernel/head_40x.o
-head-$(CONFIG_44x)             := arch/powerpc/kernel/head_44x.o
-head-$(CONFIG_FSL_BOOKE)       := arch/powerpc/kernel/head_fsl_booke.o
-
-head-$(CONFIG_PPC64)           += arch/powerpc/kernel/entry_64.o
-head-$(CONFIG_PPC_FPU)         += arch/powerpc/kernel/fpu.o
-head-$(CONFIG_ALTIVEC)         += arch/powerpc/kernel/vector.o
-head-$(CONFIG_PPC_OF_BOOT_TRAMPOLINE)  += arch/powerpc/kernel/prom_init.o
-
 # Default to zImage, override when needed
 all: zImage
 
index 3fa8ef3..e013df8 100644 (file)
@@ -110,8 +110,6 @@ else
 KBUILD_IMAGE   := $(boot)/Image.gz
 endif
 
-head-y := arch/riscv/kernel/head.o
-
 libs-y += arch/riscv/lib/
 libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
 
index 4cb5d17..de6d8b2 100644 (file)
@@ -119,8 +119,6 @@ export KBUILD_CFLAGS_DECOMPRESSOR
 
 OBJCOPYFLAGS   := -O binary
 
-head-y         := arch/s390/kernel/head64.o
-
 libs-y         += arch/s390/lib/
 drivers-y      += drivers/s390/
 
index b39412b..5c87764 100644 (file)
@@ -114,8 +114,6 @@ endif
 
 export ld-bfd
 
-head-y := arch/sh/kernel/head_32.o
-
 # Mach groups
 machdir-$(CONFIG_SOLUTION_ENGINE)              += mach-se
 machdir-$(CONFIG_SH_HP6XX)                     += mach-hp6xx
index fe58a41..a4ea5b0 100644 (file)
@@ -56,8 +56,6 @@ endif
 
 endif
 
-head-y                 := arch/sparc/kernel/head_$(BITS).o
-
 libs-y                 += arch/sparc/prom/
 libs-y                 += arch/sparc/lib/
 
index bafbd90..9afd323 100644 (file)
@@ -234,11 +234,6 @@ archheaders:
 ###
 # Kernel objects
 
-head-y := arch/x86/kernel/head_$(BITS).o
-head-y += arch/x86/kernel/head$(BITS).o
-head-y += arch/x86/kernel/ebda.o
-head-y += arch/x86/kernel/platform-quirks.o
-
 libs-y  += arch/x86/lib/
 
 # drivers-y are linked after core-y
index 5097caa..bfd8e43 100644 (file)
@@ -55,8 +55,6 @@ KBUILD_CPPFLAGS += $(patsubst %,-I$(srctree)/%include,$(vardirs) $(plfdirs))
 
 KBUILD_DEFCONFIG := iss_defconfig
 
-head-y         := arch/xtensa/kernel/head.o
-
 libs-y         += arch/xtensa/lib/
 
 boot           := arch/xtensa/boot
diff --git a/scripts/head-object-list.txt b/scripts/head-object-list.txt
new file mode 100644 (file)
index 0000000..dd2ba2e
--- /dev/null
@@ -0,0 +1,53 @@
+# Head objects
+#
+# The objects listed here are placed at the head of vmlinux. A typical use-case
+# is an object that contains the entry point. This is kept for compatibility
+# with head-y, which Kbuild used to support.
+#
+# A counter approach is to control the section placement by the linker script.
+# The code marked as __HEAD goes into the ".head.text" section, which is placed
+# before the normal ".text" section.
+#
+# If you can achieve the correct code ordering by linker script, please delete
+# the entry from this file.
+#
+arch/alpha/kernel/head.o
+arch/arc/kernel/head.o
+arch/arm/kernel/head-nommu.o
+arch/arm/kernel/head.o
+arch/arm64/kernel/head.o
+arch/csky/kernel/head.o
+arch/hexagon/kernel/head.o
+arch/ia64/kernel/head.o
+arch/loongarch/kernel/head.o
+arch/m68k/68000/head.o
+arch/m68k/coldfire/head.o
+arch/m68k/kernel/head.o
+arch/m68k/kernel/sun3-head.o
+arch/microblaze/kernel/head.o
+arch/mips/kernel/head.o
+arch/nios2/kernel/head.o
+arch/openrisc/kernel/head.o
+arch/parisc/kernel/head.o
+arch/powerpc/kernel/head_40x.o
+arch/powerpc/kernel/head_44x.o
+arch/powerpc/kernel/head_64.o
+arch/powerpc/kernel/head_8xx.o
+arch/powerpc/kernel/head_book3s_32.o
+arch/powerpc/kernel/head_fsl_booke.o
+arch/powerpc/kernel/entry_64.o
+arch/powerpc/kernel/fpu.o
+arch/powerpc/kernel/vector.o
+arch/powerpc/kernel/prom_init.o
+arch/riscv/kernel/head.o
+arch/s390/kernel/head64.o
+arch/sh/kernel/head_32.o
+arch/sparc/kernel/head_32.o
+arch/sparc/kernel/head_64.o
+arch/x86/kernel/head_32.o
+arch/x86/kernel/head_64.o
+arch/x86/kernel/head32.o
+arch/x86/kernel/head64.o
+arch/x86/kernel/ebda.o
+arch/x86/kernel/platform-quirks.o
+arch/xtensa/kernel/head.o