Makefile (420b6d00ca94ce5b6578b1bc12e767ac7a0251ac) Makefile (26a92425f9a301fdeb5482e7891915ce43cc0556)
1# SPDX-License-Identifier: GPL-2.0
2#
3# The stub may be linked into the kernel proper or into a separate boot binary,
4# but in either case, it executes before the kernel does (with MMU disabled) so
5# things like ftrace and stack-protector are likely to cause trouble if left
6# enabled, even if doing so doesn't break the build.
7#
8cflags-$(CONFIG_X86_32) := -march=i386

--- 47 unchanged lines hidden (view full) ---

56
57lib-$(CONFIG_ARM) += arm32-stub.o
58lib-$(CONFIG_ARM64) += arm64-stub.o
59lib-$(CONFIG_X86) += x86-stub.o
60CFLAGS_arm32-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET)
61CFLAGS_arm64-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET)
62
63#
1# SPDX-License-Identifier: GPL-2.0
2#
3# The stub may be linked into the kernel proper or into a separate boot binary,
4# but in either case, it executes before the kernel does (with MMU disabled) so
5# things like ftrace and stack-protector are likely to cause trouble if left
6# enabled, even if doing so doesn't break the build.
7#
8cflags-$(CONFIG_X86_32) := -march=i386

--- 47 unchanged lines hidden (view full) ---

56
57lib-$(CONFIG_ARM) += arm32-stub.o
58lib-$(CONFIG_ARM64) += arm64-stub.o
59lib-$(CONFIG_X86) += x86-stub.o
60CFLAGS_arm32-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET)
61CFLAGS_arm64-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET)
62
63#
64# For x86, bootloaders like systemd-boot or grub-efi do not zero-initialize the
65# .bss section, so the .bss section of the EFI stub needs to be included in the
66# .data section of the compressed kernel to ensure initialization. Rename the
67# .bss section here so it's easy to pick out in the linker script.
68#
69STUBCOPY_FLAGS-$(CONFIG_X86) += --rename-section .bss=.bss.efistub,load,alloc
70STUBCOPY_RELOC-$(CONFIG_X86_32) := R_386_32
71STUBCOPY_RELOC-$(CONFIG_X86_64) := R_X86_64_64
72
73#
74# ARM discards the .data section because it disallows r/w data in the
75# decompressor. So move our .data to .data.efistub and .bss to .bss.efistub,
76# which are preserved explicitly by the decompressor linker script.
77#
78STUBCOPY_FLAGS-$(CONFIG_ARM) += --rename-section .data=.data.efistub \
79 --rename-section .bss=.bss.efistub,load,alloc
80STUBCOPY_RELOC-$(CONFIG_ARM) := R_ARM_ABS
81
82#
64# arm64 puts the stub in the kernel proper, which will unnecessarily retain all
65# code indefinitely unless it is annotated as __init/__initdata/__initconst etc.
66# So let's apply the __init annotations at the section level, by prefixing
67# the section names directly. This will ensure that even all the inline string
68# literals are covered.
69# The fact that the stub and the kernel proper are essentially the same binary
70# also means that we need to be extra careful to make sure that the stub does
71# not rely on any absolute symbol references, considering that the virtual
72# kernel mapping that the linker uses is not active yet when the stub is
73# executing. So build all C dependencies of the EFI stub into libstub, and do
74# a verification pass to see if any absolute relocations exist in any of the
75# object files.
76#
83# arm64 puts the stub in the kernel proper, which will unnecessarily retain all
84# code indefinitely unless it is annotated as __init/__initdata/__initconst etc.
85# So let's apply the __init annotations at the section level, by prefixing
86# the section names directly. This will ensure that even all the inline string
87# literals are covered.
88# The fact that the stub and the kernel proper are essentially the same binary
89# also means that we need to be extra careful to make sure that the stub does
90# not rely on any absolute symbol references, considering that the virtual
91# kernel mapping that the linker uses is not active yet when the stub is
92# executing. So build all C dependencies of the EFI stub into libstub, and do
93# a verification pass to see if any absolute relocations exist in any of the
94# object files.
95#
77extra-$(CONFIG_EFI_GENERIC_STUB) := $(lib-y)
78lib-$(CONFIG_EFI_GENERIC_STUB) := $(patsubst %.o,%.stub.o,$(lib-y))
96extra-y := $(lib-y)
97lib-y := $(patsubst %.o,%.stub.o,$(lib-y))
79
80STUBCOPY_FLAGS-$(CONFIG_ARM64) += --prefix-alloc-sections=.init \
81 --prefix-symbols=__efistub_
82STUBCOPY_RELOC-$(CONFIG_ARM64) := R_AARCH64_ABS
83
84$(obj)/%.stub.o: $(obj)/%.o FORCE
85 $(call if_changed,stubcopy)
86

--- 6 unchanged lines hidden (view full) ---

93quiet_cmd_stubcopy = STUBCPY $@
94 cmd_stubcopy = \
95 $(STRIP) --strip-debug -o $@ $<; \
96 if $(OBJDUMP) -r $@ | grep $(STUBCOPY_RELOC-y); then \
97 echo "$@: absolute symbol references not allowed in the EFI stub" >&2; \
98 /bin/false; \
99 fi; \
100 $(OBJCOPY) $(STUBCOPY_FLAGS-y) $< $@
98
99STUBCOPY_FLAGS-$(CONFIG_ARM64) += --prefix-alloc-sections=.init \
100 --prefix-symbols=__efistub_
101STUBCOPY_RELOC-$(CONFIG_ARM64) := R_AARCH64_ABS
102
103$(obj)/%.stub.o: $(obj)/%.o FORCE
104 $(call if_changed,stubcopy)
105

--- 6 unchanged lines hidden (view full) ---

112quiet_cmd_stubcopy = STUBCPY $@
113 cmd_stubcopy = \
114 $(STRIP) --strip-debug -o $@ $<; \
115 if $(OBJDUMP) -r $@ | grep $(STUBCOPY_RELOC-y); then \
116 echo "$@: absolute symbol references not allowed in the EFI stub" >&2; \
117 /bin/false; \
118 fi; \
119 $(OBJCOPY) $(STUBCOPY_FLAGS-y) $< $@
101
102#
103# ARM discards the .data section because it disallows r/w data in the
104# decompressor. So move our .data to .data.efistub and .bss to .bss.efistub,
105# which are preserved explicitly by the decompressor linker script.
106#
107STUBCOPY_FLAGS-$(CONFIG_ARM) += --rename-section .data=.data.efistub \
108 --rename-section .bss=.bss.efistub,load,alloc
109STUBCOPY_RELOC-$(CONFIG_ARM) := R_ARM_ABS