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.
Unified · Split
| @@ -1070,8 +1070,7 @@ When kbuild executes, the following steps are followed (roughly): · 1069 unmodified lines | ||
| 1070 | 1070 | - The values of the above variables are expanded in arch/$(SRCARCH)/Makefile. |
| 1071 | 1071 | 5) All object files are then linked and the resulting file vmlinux is |
| 1072 | 1072 | located at the root of the obj tree. |
| 1073 | − The very first objects linked are listed in head-y, assigned by | |
| 1074 | − arch/$(SRCARCH)/Makefile. | |
| 1073 | + The very first objects linked are listed in scripts/head-object-list.txt. | |
| 1075 | 1074 | 6) Finally, the architecture-specific part does any required post processing |
| 1076 | 1075 | and builds the final bootimage. |
| 1077 | 1076 | - This includes building boot records |
| @@ -1219,6 +1218,9 @@ When kbuild executes, the following steps are followed (roughly): · 141 unmodified lines | ||
| 1219 | 1218 | All object files for vmlinux. They are linked to vmlinux in the same |
| 1220 | 1219 | order as listed in KBUILD_VMLINUX_OBJS. |
| 1221 | 1220 | |
| 1221 | + The objects listed in scripts/head-object-list.txt are exceptions; | |
| 1222 | + they are placed before the other objects. | |
| 1223 | + | |
| 1222 | 1224 | KBUILD_VMLINUX_LIBS |
| 1223 | 1225 | |
| 1224 | 1226 | All .a "lib" files for vmlinux. KBUILD_VMLINUX_OBJS and |
| @@ -1262,8 +1264,7 @@ When kbuild executes, the following steps are followed (roughly): · 37 unmodified lines | ||
| 1262 | 1264 | machinery is all architecture-independent. |
| 1263 | 1265 | |
| 1264 | 1266 | |
| 1265 | − head-y, core-y, libs-y, drivers-y | |
| 1266 | − $(head-y) lists objects to be linked first in vmlinux. | |
| 1267 | + core-y, libs-y, drivers-y | |
| 1267 | 1268 | |
| 1268 | 1269 | $(libs-y) lists directories where a lib.a archive can be located. |
| 1269 | 1270 | |
| @@ -1147,10 +1147,10 @@ quiet_cmd_ar_vmlinux.a = AR $@ · 1146 unmodified lines | ||
| 1147 | 1147 | cmd_ar_vmlinux.a = \ |
| 1148 | 1148 | rm -f $@; \ |
| 1149 | 1149 | $(AR) cDPrST $@ $(KBUILD_VMLINUX_OBJS); \ |
| 1150 | − $(AR) mPiT $$($(AR) t $@ | head -n1) $@ $(head-y) | |
| 1150 | + $(AR) mPiT $$($(AR) t $@ | head -n1) $@ $$($(AR) t $@ | grep -F --file=$(srctree)/scripts/head-object-list.txt) | |
| 1151 | 1151 | |
| 1152 | 1152 | targets += vmlinux.a |
| 1153 | −vmlinux.a: $(KBUILD_VMLINUX_OBJS) autoksyms_recursive FORCE | |
| 1153 | +vmlinux.a: $(KBUILD_VMLINUX_OBJS) scripts/head-object-list.txt autoksyms_recursive FORCE | |
| 1154 | 1154 | $(call if_changed,ar_vmlinux.a) |
| 1155 | 1155 | |
| 1156 | 1156 | vmlinux.o: vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE |
| @@ -36,8 +36,6 @@ cflags-y += $(cpuflags-y) · 35 unmodified lines | ||
| 36 | 36 | # BWX is most important, but we don't really want any emulation ever. |
| 37 | 37 | KBUILD_CFLAGS += $(cflags-y) -Wa,-mev6 |
| 38 | 38 | |
| 39 | −head-y := arch/alpha/kernel/head.o | |
| 40 | − | |
| 41 | 39 | libs-y += arch/alpha/lib/ |
| 42 | 40 | |
| 43 | 41 | # export what is needed by arch/alpha/boot/Makefile |
| @@ -82,8 +82,6 @@ KBUILD_CFLAGS += $(cflags-y) · 81 unmodified lines | ||
| 82 | 82 | KBUILD_AFLAGS += $(KBUILD_CFLAGS) |
| 83 | 83 | KBUILD_LDFLAGS += $(ldflags-y) |
| 84 | 84 | |
| 85 | −head-y := arch/arc/kernel/head.o | |
| 86 | − | |
| 87 | 85 | # w/o this dtb won't embed into kernel binary |
| 88 | 86 | core-y += arch/arc/boot/dts/ |
| 89 | 87 | |
| @@ -134,9 +134,6 @@ KBUILD_AFLAGS +=$(CFLAGS_ABI) $(AFLAGS_ISA) $(arch-y) $(tune-y) -include asm/uni · 133 unmodified lines | ||
| 134 | 134 | |
| 135 | 135 | CHECKFLAGS += -D__arm__ |
| 136 | 136 | |
| 137 | −#Default value | |
| 138 | −head-y := arch/arm/kernel/head$(MMUEXT).o | |
| 139 | − | |
| 140 | 137 | # Text offset. This list is sorted numerically by address in order to |
| 141 | 138 | # provide a means to avoid/resolve conflicts in multi-arch kernels. |
| 142 | 139 | # Note: the 32kB below this value is reserved for use by the kernel |
| @@ -133,9 +133,6 @@ ifeq ($(CONFIG_DYNAMIC_FTRACE_WITH_REGS),y) · 132 unmodified lines | ||
| 133 | 133 | CC_FLAGS_FTRACE := -fpatchable-function-entry=2 |
| 134 | 134 | endif |
| 135 | 135 | |
| 136 | −# Default value | |
| 137 | −head-y := arch/arm64/kernel/head.o | |
| 138 | − | |
| 139 | 136 | ifeq ($(CONFIG_KASAN_SW_TAGS), y) |
| 140 | 137 | KASAN_SHADOW_SCALE_SHIFT := 4 |
| 141 | 138 | else ifeq ($(CONFIG_KASAN_GENERIC), y) |
| @@ -59,8 +59,6 @@ LDFLAGS += -EL · 58 unmodified lines | ||
| 59 | 59 | |
| 60 | 60 | KBUILD_AFLAGS += $(KBUILD_CFLAGS) |
| 61 | 61 | |
| 62 | −head-y := arch/csky/kernel/head.o | |
| 63 | − | |
| 64 | 62 | core-y += arch/csky/$(CSKYABI)/ |
| 65 | 63 | |
| 66 | 64 | libs-y += arch/csky/lib/ \ |
| @@ -32,5 +32,3 @@ KBUILD_LDFLAGS += $(ldflags-y) · 31 unmodified lines | ||
| 32 | 32 | TIR_NAME := r19 |
| 33 | 33 | KBUILD_CFLAGS += -ffixed-$(TIR_NAME) -DTHREADINFO_REG=$(TIR_NAME) -D__linux__ |
| 34 | 34 | KBUILD_AFLAGS += -DTHREADINFO_REG=$(TIR_NAME) |
| 35 | − | |
| 36 | −head-y := arch/hexagon/kernel/head.o | |
| @@ -44,7 +44,6 @@ quiet_cmd_objcopy = OBJCOPY $@ · 43 unmodified lines | ||
| 44 | 44 | cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@ |
| 45 | 45 | |
| 46 | 46 | KBUILD_CFLAGS += $(cflags-y) |
| 47 | −head-y := arch/ia64/kernel/head.o | |
| 48 | 47 | |
| 49 | 48 | libs-y += arch/ia64/lib/ |
| 50 | 49 | |
| @@ -72,8 +72,6 @@ CHECKFLAGS += $(shell $(CC) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \ · 71 unmodified lines | ||
| 72 | 72 | sed -e "s/^\#define /-D'/" -e "s/ /'='/" -e "s/$$/'/" -e 's/\$$/&&/g') |
| 73 | 73 | endif |
| 74 | 74 | |
| 75 | −head-y := arch/loongarch/kernel/head.o | |
| 76 | − | |
| 77 | 75 | libs-y += arch/loongarch/lib/ |
| 78 | 76 | |
| 79 | 77 | ifeq ($(KBUILD_EXTMOD),) |
| @@ -86,15 +86,6 @@ ifdef CONFIG_KGDB · 85 unmodified lines | ||
| 86 | 86 | KBUILD_CFLAGS := $(subst -fomit-frame-pointer,,$(KBUILD_CFLAGS)) -g |
| 87 | 87 | endif |
| 88 | 88 | |
| 89 | −# | |
| 90 | −# Select the assembler head startup code. Order is important. The default | |
| 91 | −# head code is first, processor specific selections can override it after. | |
| 92 | −# | |
| 93 | −head-y := arch/m68k/kernel/head.o | |
| 94 | −head-$(CONFIG_SUN3) := arch/m68k/kernel/sun3-head.o | |
| 95 | −head-$(CONFIG_M68000) := arch/m68k/68000/head.o | |
| 96 | −head-$(CONFIG_COLDFIRE) := arch/m68k/coldfire/head.o | |
| 97 | − | |
| 98 | 89 | libs-y += arch/m68k/lib/ |
| 99 | 90 | |
| 100 | 91 | |
| @@ -48,7 +48,6 @@ CPUFLAGS-1 += $(call cc-option,-mcpu=v$(CPU_VER)) · 47 unmodified lines | ||
| 48 | 48 | # r31 holds current when in kernel mode |
| 49 | 49 | KBUILD_CFLAGS += -ffixed-r31 $(CPUFLAGS-y) $(CPUFLAGS-1) $(CPUFLAGS-2) |
| 50 | 50 | |
| 51 | −head-y := arch/microblaze/kernel/head.o | |
| 52 | 51 | libs-y += arch/microblaze/lib/ |
| 53 | 52 | |
| 54 | 53 | boot := arch/microblaze/boot |
| @@ -324,8 +324,6 @@ endif · 323 unmodified lines | ||
| 324 | 324 | |
| 325 | 325 | OBJCOPYFLAGS += --remove-section=.reginfo |
| 326 | 326 | |
| 327 | −head-y := arch/mips/kernel/head.o | |
| 328 | − | |
| 329 | 327 | libs-y += arch/mips/lib/ |
| 330 | 328 | libs-$(CONFIG_MIPS_FP_SUPPORT) += arch/mips/math-emu/ |
| 331 | 329 | |
| @@ -37,7 +37,6 @@ KBUILD_CFLAGS += -DUTS_SYSNAME=\"$(UTS_SYSNAME)\" · 36 unmodified lines | ||
| 37 | 37 | KBUILD_CFLAGS += -fno-builtin |
| 38 | 38 | KBUILD_CFLAGS += -G 0 |
| 39 | 39 | |
| 40 | −head-y := arch/nios2/kernel/head.o | |
| 41 | 40 | libs-y += arch/nios2/lib/ $(LIBGCC) |
| 42 | 41 | |
| 43 | 42 | INSTALL_PATH ?= /tftpboot |
| @@ -55,8 +55,6 @@ ifeq ($(CONFIG_OPENRISC_HAVE_INST_SEXT),y) · 54 unmodified lines | ||
| 55 | 55 | KBUILD_CFLAGS += $(call cc-option,-msext) |
| 56 | 56 | endif |
| 57 | 57 | |
| 58 | −head-y := arch/openrisc/kernel/head.o | |
| 59 | − | |
| 60 | 58 | libs-y += $(LIBGCC) |
| 61 | 59 | |
| 62 | 60 | PHONY += vmlinux.bin |
| @@ -113,8 +113,6 @@ cflags-$(CONFIG_PA7100LC) += -march=1.1 -mschedule=7100LC · 112 unmodified lines | ||
| 113 | 113 | cflags-$(CONFIG_PA7300LC) += -march=1.1 -mschedule=7300 |
| 114 | 114 | cflags-$(CONFIG_PA8X00) += -march=2.0 -mschedule=8000 |
| 115 | 115 | |
| 116 | −head-y := arch/parisc/kernel/head.o | |
| 117 | − | |
| 118 | 116 | KBUILD_CFLAGS += $(cflags-y) |
| 119 | 117 | LIBGCC := $(shell $(CC) -print-libgcc-file-name) |
| 120 | 118 | export LIBGCC |
| @@ -226,18 +226,6 @@ KBUILD_CFLAGS += $(cpu-as-y) · 225 unmodified lines | ||
| 226 | 226 | KBUILD_AFLAGS += $(aflags-y) |
| 227 | 227 | KBUILD_CFLAGS += $(cflags-y) |
| 228 | 228 | |
| 229 | −head-$(CONFIG_PPC64) := arch/powerpc/kernel/head_64.o | |
| 230 | −head-$(CONFIG_PPC_BOOK3S_32) := arch/powerpc/kernel/head_book3s_32.o | |
| 231 | −head-$(CONFIG_PPC_8xx) := arch/powerpc/kernel/head_8xx.o | |
| 232 | −head-$(CONFIG_40x) := arch/powerpc/kernel/head_40x.o | |
| 233 | −head-$(CONFIG_44x) := arch/powerpc/kernel/head_44x.o | |
| 234 | −head-$(CONFIG_FSL_BOOKE) := arch/powerpc/kernel/head_fsl_booke.o | |
| 235 | − | |
| 236 | −head-$(CONFIG_PPC64) += arch/powerpc/kernel/entry_64.o | |
| 237 | −head-$(CONFIG_PPC_FPU) += arch/powerpc/kernel/fpu.o | |
| 238 | −head-$(CONFIG_ALTIVEC) += arch/powerpc/kernel/vector.o | |
| 239 | −head-$(CONFIG_PPC_OF_BOOT_TRAMPOLINE) += arch/powerpc/kernel/prom_init.o | |
| 240 | − | |
| 241 | 229 | # Default to zImage, override when needed |
| 242 | 230 | all: zImage |
| 243 | 231 | |
| @@ -110,8 +110,6 @@ else · 109 unmodified lines | ||
| 110 | 110 | KBUILD_IMAGE := $(boot)/Image.gz |
| 111 | 111 | endif |
| 112 | 112 | |
| 113 | −head-y := arch/riscv/kernel/head.o | |
| 114 | − | |
| 115 | 113 | libs-y += arch/riscv/lib/ |
| 116 | 114 | libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a |
| 117 | 115 | |
| @@ -119,8 +119,6 @@ export KBUILD_CFLAGS_DECOMPRESSOR · 118 unmodified lines | ||
| 119 | 119 | |
| 120 | 120 | OBJCOPYFLAGS := -O binary |
| 121 | 121 | |
| 122 | −head-y := arch/s390/kernel/head64.o | |
| 123 | − | |
| 124 | 122 | libs-y += arch/s390/lib/ |
| 125 | 123 | drivers-y += drivers/s390/ |
| 126 | 124 | |
| @@ -114,8 +114,6 @@ endif · 113 unmodified lines | ||
| 114 | 114 | |
| 115 | 115 | export ld-bfd |
| 116 | 116 | |
| 117 | −head-y := arch/sh/kernel/head_32.o | |
| 118 | − | |
| 119 | 117 | # Mach groups |
| 120 | 118 | machdir-$(CONFIG_SOLUTION_ENGINE) += mach-se |
| 121 | 119 | machdir-$(CONFIG_SH_HP6XX) += mach-hp6xx |
| @@ -56,8 +56,6 @@ endif · 55 unmodified lines | ||
| 56 | 56 | |
| 57 | 57 | endif |
| 58 | 58 | |
| 59 | −head-y := arch/sparc/kernel/head_$(BITS).o | |
| 60 | − | |
| 61 | 59 | libs-y += arch/sparc/prom/ |
| 62 | 60 | libs-y += arch/sparc/lib/ |
| 63 | 61 | |
| @@ -234,11 +234,6 @@ archheaders: · 233 unmodified lines | ||
| 234 | 234 | ### |
| 235 | 235 | # Kernel objects |
| 236 | 236 | |
| 237 | −head-y := arch/x86/kernel/head_$(BITS).o | |
| 238 | −head-y += arch/x86/kernel/head$(BITS).o | |
| 239 | −head-y += arch/x86/kernel/ebda.o | |
| 240 | −head-y += arch/x86/kernel/platform-quirks.o | |
| 241 | − | |
| 242 | 237 | libs-y += arch/x86/lib/ |
| 243 | 238 | |
| 244 | 239 | # drivers-y are linked after core-y |
| @@ -55,8 +55,6 @@ KBUILD_CPPFLAGS += $(patsubst %,-I$(srctree)/%include,$(vardirs) $(plfdirs)) · 54 unmodified lines | ||
| 55 | 55 | |
| 56 | 56 | KBUILD_DEFCONFIG := iss_defconfig |
| 57 | 57 | |
| 58 | −head-y := arch/xtensa/kernel/head.o | |
| 59 | − | |
| 60 | 58 | libs-y += arch/xtensa/lib/ |
| 61 | 59 | |
| 62 | 60 | boot := arch/xtensa/boot |
| @@ -0,0 +1,53 @@ | ||
| 1 | +# Head objects | |
| 2 | +# | |
| 3 | +# The objects listed here are placed at the head of vmlinux. A typical use-case | |
| 4 | +# is an object that contains the entry point. This is kept for compatibility | |
| 5 | +# with head-y, which Kbuild used to support. | |
| 6 | +# | |
| 7 | +# A counter approach is to control the section placement by the linker script. | |
| 8 | +# The code marked as __HEAD goes into the ".head.text" section, which is placed | |
| 9 | +# before the normal ".text" section. | |
| 10 | +# | |
| 11 | +# If you can achieve the correct code ordering by linker script, please delete | |
| 12 | +# the entry from this file. | |
| 13 | +# | |
| 14 | +arch/alpha/kernel/head.o | |
| 15 | +arch/arc/kernel/head.o | |
| 16 | +arch/arm/kernel/head-nommu.o | |
| 17 | +arch/arm/kernel/head.o | |
| 18 | +arch/arm64/kernel/head.o | |
| 19 | +arch/csky/kernel/head.o | |
| 20 | +arch/hexagon/kernel/head.o | |
| 21 | +arch/ia64/kernel/head.o | |
| 22 | +arch/loongarch/kernel/head.o | |
| 23 | +arch/m68k/68000/head.o | |
| 24 | +arch/m68k/coldfire/head.o | |
| 25 | +arch/m68k/kernel/head.o | |
| 26 | +arch/m68k/kernel/sun3-head.o | |
| 27 | +arch/microblaze/kernel/head.o | |
| 28 | +arch/mips/kernel/head.o | |
| 29 | +arch/nios2/kernel/head.o | |
| 30 | +arch/openrisc/kernel/head.o | |
| 31 | +arch/parisc/kernel/head.o | |
| 32 | +arch/powerpc/kernel/head_40x.o | |
| 33 | +arch/powerpc/kernel/head_44x.o | |
| 34 | +arch/powerpc/kernel/head_64.o | |
| 35 | +arch/powerpc/kernel/head_8xx.o | |
| 36 | +arch/powerpc/kernel/head_book3s_32.o | |
| 37 | +arch/powerpc/kernel/head_fsl_booke.o | |
| 38 | +arch/powerpc/kernel/entry_64.o | |
| 39 | +arch/powerpc/kernel/fpu.o | |
| 40 | +arch/powerpc/kernel/vector.o | |
| 41 | +arch/powerpc/kernel/prom_init.o | |
| 42 | +arch/riscv/kernel/head.o | |
| 43 | +arch/s390/kernel/head64.o | |
| 44 | +arch/sh/kernel/head_32.o | |
| 45 | +arch/sparc/kernel/head_32.o | |
| 46 | +arch/sparc/kernel/head_64.o | |
| 47 | +arch/x86/kernel/head_32.o | |
| 48 | +arch/x86/kernel/head_64.o | |
| 49 | +arch/x86/kernel/head32.o | |
| 50 | +arch/x86/kernel/head64.o | |
| 51 | +arch/x86/kernel/ebda.o | |
| 52 | +arch/x86/kernel/platform-quirks.o | |
| 53 | +arch/xtensa/kernel/head.o | |