Skip to content

Commit ce697cc

Browse files
committed
kbuild: remove head-y syntax
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 <[email protected]> Tested-by: Nick Desaulniers <[email protected]> Reviewed-by: Nicolas Schier <[email protected]>
1 parent 3216484 commit ce697cc

File tree

24 files changed

+60
-67
lines changed

24 files changed

+60
-67
lines changed

Documentation/kbuild/makefiles.rst

+5-4
Original file line numberDiff line numberDiff line change
@@ -1070,8 +1070,7 @@ When kbuild executes, the following steps are followed (roughly):
10701070
- The values of the above variables are expanded in arch/$(SRCARCH)/Makefile.
10711071
5) All object files are then linked and the resulting file vmlinux is
10721072
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.
10751074
6) Finally, the architecture-specific part does any required post processing
10761075
and builds the final bootimage.
10771076
- This includes building boot records
@@ -1219,6 +1218,9 @@ When kbuild executes, the following steps are followed (roughly):
12191218
All object files for vmlinux. They are linked to vmlinux in the same
12201219
order as listed in KBUILD_VMLINUX_OBJS.
12211220

1221+
The objects listed in scripts/head-object-list.txt are exceptions;
1222+
they are placed before the other objects.
1223+
12221224
KBUILD_VMLINUX_LIBS
12231225

12241226
All .a "lib" files for vmlinux. KBUILD_VMLINUX_OBJS and
@@ -1262,8 +1264,7 @@ When kbuild executes, the following steps are followed (roughly):
12621264
machinery is all architecture-independent.
12631265

12641266

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
12671268

12681269
$(libs-y) lists directories where a lib.a archive can be located.
12691270

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1147,10 +1147,10 @@ quiet_cmd_ar_vmlinux.a = AR $@
11471147
cmd_ar_vmlinux.a = \
11481148
rm -f $@; \
11491149
$(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)
11511151

11521152
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
11541154
$(call if_changed,ar_vmlinux.a)
11551155

11561156
vmlinux.o: vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE

arch/alpha/Makefile

-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ cflags-y += $(cpuflags-y)
3636
# BWX is most important, but we don't really want any emulation ever.
3737
KBUILD_CFLAGS += $(cflags-y) -Wa,-mev6
3838

39-
head-y := arch/alpha/kernel/head.o
40-
4139
libs-y += arch/alpha/lib/
4240

4341
# export what is needed by arch/alpha/boot/Makefile

arch/arc/Makefile

-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ KBUILD_CFLAGS += $(cflags-y)
8282
KBUILD_AFLAGS += $(KBUILD_CFLAGS)
8383
KBUILD_LDFLAGS += $(ldflags-y)
8484

85-
head-y := arch/arc/kernel/head.o
86-
8785
# w/o this dtb won't embed into kernel binary
8886
core-y += arch/arc/boot/dts/
8987

arch/arm/Makefile

-3
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,6 @@ KBUILD_AFLAGS +=$(CFLAGS_ABI) $(AFLAGS_ISA) $(arch-y) $(tune-y) -include asm/uni
134134

135135
CHECKFLAGS += -D__arm__
136136

137-
#Default value
138-
head-y := arch/arm/kernel/head$(MMUEXT).o
139-
140137
# Text offset. This list is sorted numerically by address in order to
141138
# provide a means to avoid/resolve conflicts in multi-arch kernels.
142139
# Note: the 32kB below this value is reserved for use by the kernel

arch/arm64/Makefile

-3
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,6 @@ ifeq ($(CONFIG_DYNAMIC_FTRACE_WITH_REGS),y)
133133
CC_FLAGS_FTRACE := -fpatchable-function-entry=2
134134
endif
135135

136-
# Default value
137-
head-y := arch/arm64/kernel/head.o
138-
139136
ifeq ($(CONFIG_KASAN_SW_TAGS), y)
140137
KASAN_SHADOW_SCALE_SHIFT := 4
141138
else ifeq ($(CONFIG_KASAN_GENERIC), y)

arch/csky/Makefile

-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ LDFLAGS += -EL
5959

6060
KBUILD_AFLAGS += $(KBUILD_CFLAGS)
6161

62-
head-y := arch/csky/kernel/head.o
63-
6462
core-y += arch/csky/$(CSKYABI)/
6563

6664
libs-y += arch/csky/lib/ \

arch/hexagon/Makefile

-2
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,3 @@ KBUILD_LDFLAGS += $(ldflags-y)
3232
TIR_NAME := r19
3333
KBUILD_CFLAGS += -ffixed-$(TIR_NAME) -DTHREADINFO_REG=$(TIR_NAME) -D__linux__
3434
KBUILD_AFLAGS += -DTHREADINFO_REG=$(TIR_NAME)
35-
36-
head-y := arch/hexagon/kernel/head.o

arch/ia64/Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ quiet_cmd_objcopy = OBJCOPY $@
4444
cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
4545

4646
KBUILD_CFLAGS += $(cflags-y)
47-
head-y := arch/ia64/kernel/head.o
4847

4948
libs-y += arch/ia64/lib/
5049

arch/loongarch/Makefile

-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ CHECKFLAGS += $(shell $(CC) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \
7272
sed -e "s/^\#define /-D'/" -e "s/ /'='/" -e "s/$$/'/" -e 's/\$$/&&/g')
7373
endif
7474

75-
head-y := arch/loongarch/kernel/head.o
76-
7775
libs-y += arch/loongarch/lib/
7876

7977
ifeq ($(KBUILD_EXTMOD),)

arch/m68k/Makefile

-9
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,6 @@ ifdef CONFIG_KGDB
8686
KBUILD_CFLAGS := $(subst -fomit-frame-pointer,,$(KBUILD_CFLAGS)) -g
8787
endif
8888

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-
9889
libs-y += arch/m68k/lib/
9990

10091

arch/microblaze/Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ CPUFLAGS-1 += $(call cc-option,-mcpu=v$(CPU_VER))
4848
# r31 holds current when in kernel mode
4949
KBUILD_CFLAGS += -ffixed-r31 $(CPUFLAGS-y) $(CPUFLAGS-1) $(CPUFLAGS-2)
5050

51-
head-y := arch/microblaze/kernel/head.o
5251
libs-y += arch/microblaze/lib/
5352

5453
boot := arch/microblaze/boot

arch/mips/Makefile

-2
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,6 @@ endif
324324

325325
OBJCOPYFLAGS += --remove-section=.reginfo
326326

327-
head-y := arch/mips/kernel/head.o
328-
329327
libs-y += arch/mips/lib/
330328
libs-$(CONFIG_MIPS_FP_SUPPORT) += arch/mips/math-emu/
331329

arch/nios2/Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ KBUILD_CFLAGS += -DUTS_SYSNAME=\"$(UTS_SYSNAME)\"
3737
KBUILD_CFLAGS += -fno-builtin
3838
KBUILD_CFLAGS += -G 0
3939

40-
head-y := arch/nios2/kernel/head.o
4140
libs-y += arch/nios2/lib/ $(LIBGCC)
4241

4342
INSTALL_PATH ?= /tftpboot

arch/openrisc/Makefile

-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ ifeq ($(CONFIG_OPENRISC_HAVE_INST_SEXT),y)
5555
KBUILD_CFLAGS += $(call cc-option,-msext)
5656
endif
5757

58-
head-y := arch/openrisc/kernel/head.o
59-
6058
libs-y += $(LIBGCC)
6159

6260
PHONY += vmlinux.bin

arch/parisc/Makefile

-2
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ cflags-$(CONFIG_PA7100LC) += -march=1.1 -mschedule=7100LC
113113
cflags-$(CONFIG_PA7300LC) += -march=1.1 -mschedule=7300
114114
cflags-$(CONFIG_PA8X00) += -march=2.0 -mschedule=8000
115115

116-
head-y := arch/parisc/kernel/head.o
117-
118116
KBUILD_CFLAGS += $(cflags-y)
119117
LIBGCC := $(shell $(CC) -print-libgcc-file-name)
120118
export LIBGCC

arch/powerpc/Makefile

-12
Original file line numberDiff line numberDiff line change
@@ -226,18 +226,6 @@ KBUILD_CFLAGS += $(cpu-as-y)
226226
KBUILD_AFLAGS += $(aflags-y)
227227
KBUILD_CFLAGS += $(cflags-y)
228228

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-
241229
# Default to zImage, override when needed
242230
all: zImage
243231

arch/riscv/Makefile

-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ else
110110
KBUILD_IMAGE := $(boot)/Image.gz
111111
endif
112112

113-
head-y := arch/riscv/kernel/head.o
114-
115113
libs-y += arch/riscv/lib/
116114
libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
117115

arch/s390/Makefile

-2
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ export KBUILD_CFLAGS_DECOMPRESSOR
119119

120120
OBJCOPYFLAGS := -O binary
121121

122-
head-y := arch/s390/kernel/head64.o
123-
124122
libs-y += arch/s390/lib/
125123
drivers-y += drivers/s390/
126124

arch/sh/Makefile

-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ endif
114114

115115
export ld-bfd
116116

117-
head-y := arch/sh/kernel/head_32.o
118-
119117
# Mach groups
120118
machdir-$(CONFIG_SOLUTION_ENGINE) += mach-se
121119
machdir-$(CONFIG_SH_HP6XX) += mach-hp6xx

arch/sparc/Makefile

-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ endif
5656

5757
endif
5858

59-
head-y := arch/sparc/kernel/head_$(BITS).o
60-
6159
libs-y += arch/sparc/prom/
6260
libs-y += arch/sparc/lib/
6361

arch/x86/Makefile

-5
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,6 @@ archheaders:
234234
###
235235
# Kernel objects
236236

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-
242237
libs-y += arch/x86/lib/
243238

244239
# drivers-y are linked after core-y

arch/xtensa/Makefile

-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ KBUILD_CPPFLAGS += $(patsubst %,-I$(srctree)/%include,$(vardirs) $(plfdirs))
5555

5656
KBUILD_DEFCONFIG := iss_defconfig
5757

58-
head-y := arch/xtensa/kernel/head.o
59-
6058
libs-y += arch/xtensa/lib/
6159

6260
boot := arch/xtensa/boot

scripts/head-object-list.txt

+53
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)