x86: Build the core kernel using PIC codegen
Subsystems (8)
cover x86: Build the core kernel using PIC codegen
From: Ard Biesheuvel <[email protected]>
Originally, only arch/x86/kernel/head64.c had some code that required special care because it executes very early from the 1:1 mapping of the kernel rather than the ordinary kernel virtual mapping.
This is no longer the case, and there is a lot of SEV related code that is reachable from the primary startup path, with no guarantees that the toolchain will produce code that runs correctly. This is especially problematic when it comes to things like string literals, which are emitted by the compiler as data objects, and subsequently referenced via an absolute address that is not mapped yet this early in the boot [0].
Kevin has been looking into failures resulting from the fact that Clang behaves slightly differently from GCC in this regard, by selectively applying PIC codegen to the objects in question. However, while this fixes the observed issues, it does not offer any guarantees, given that the set of reachable code from startup_64() does not appear to be bounded when running on SEV hardware.
Instead of applying this change piecemeal to objects that happen to have caused issues in the past, this series convert the core kernel to PIC codegen entirely.
Note that this does not entirely solve the problem of the unbounded set of reachable code from the early SEV entrypoint: there might be code that attempts to access global objects via their kernel virtual address (which is not mapped yet). But at least all implicit accesses will be made via the same translation that the code is running from.
This does result in a slight increase in code size (see below) but it also reduces the size of the KASLR relocation table (applied by the decompressor) by roughly half.
Before
$ size -x vmlinux text data bss dec hex filename 0x1b78ec1 0xdde145 0x381000 47022086 2cd8006 vmlinux
After
$ size -x vmlinux text data bss dec hex filename 0x1b8371b 0xde0d1d 0x370000 47006776 2cd4438 vmlinux
[0] arch/x86/mm/mem_encrypt_identity.c has some nice examples of this, where RIP-relative references are emitted using inline asm.
[1] https://lkml.kernel.org/r/20240111223650.3502633-1-kevinloughlin%40google.com
Ard Biesheuvel (5):
kallsyms: Avoid weak references for kallsyms symbols
vmlinux: Avoid weak reference to notes section
btf: Avoid weak external references
x86/head64: Replace pointer fixups with PIE codegen
x86: Build the core kernel with position independent codegen
arch/x86/Makefile | 18 ++- arch/x86/boot/compressed/Makefile | 2 +- arch/x86/entry/vdso/Makefile | 2 +- arch/x86/include/asm/init.h | 2 - arch/x86/include/asm/setup.h | 2 +- arch/x86/kernel/head64.c | 117 +++++++------------- arch/x86/realmode/rm/Makefile | 1 + include/asm-generic/vmlinux.lds.h | 23 ++++ kernel/bpf/btf.c | 4 +- kernel/kallsyms.c | 6 - kernel/kallsyms_internal.h | 30 ++--- kernel/ksysfs.c | 4 +- lib/buildid.c | 4 +- 13 files changed, 104 insertions(+), 111 deletions(-)
Signature · 1 line
2.43.0.429.g432eaa2c6b-goog
RFC PATCH 1/5 kallsyms: Avoid weak references for kallsyms symbols
From: Ard Biesheuvel <[email protected]>
kallsyms is a directory of all the symbols in the vmlinux binary, and so creating it is somewhat of a chicken-and-egg problem, as its non-zero size affects the layout of the binary, and therefore the values of the symbols.
For this reason, the kernel is linked more than once, and the first pass does not include any kallsyms data at all. For the linker to accept this, the symbol declarations describing the kallsyms metadata are emitted as having weak linkage, so they can remain unsatisfied. During the subsequent passes, the weak references are satisfied by the kallsyms metadata that was constructed based on information gathered from the preceding passes.
Weak references lead to somewhat worse codegen, because taking their address may need to produce NULL (if the reference was unsatisfied), and this is not usually supported by RIP or PC relative symbol references.
Given that these references are ultimately always satisfied in the final link, let's drop the weak annotation, and instead, provide fallback definitions in the linker script that are only emitted if an unsatisfied reference exists.
While at it, drop the FRV specific annotation that these symbols reside in .rodata - FRV is long gone.
--- include/asm-generic/vmlinux.lds.h | 19 +++++++++++++ kernel/kallsyms.c | 6 ---- kernel/kallsyms_internal.h | 30 ++++++++------------ 3 files changed, 31 insertions(+), 24 deletions(-)
include/asm-generic/vmlinux.lds.h +19 -0
@@ -448,11 +448,30 @@#endif #endif +/* +* Some symbol definitions will not exist yet during the first pass of the +* link, but are guaranteed to exist in the final link. Provide preliminary +* definitions that will be superseded in the final link to avoid having to +* rely on weak external linkage, which requires a GOT when used in position +* independent code. +*/ +#define PRELIMINARY_SYMBOL_DEFINITIONS \ + PROVIDE(kallsyms_addresses = .); \ + PROVIDE(kallsyms_offsets = .); \ + PROVIDE(kallsyms_names = .); \ + PROVIDE(kallsyms_num_syms = .); \ + PROVIDE(kallsyms_relative_base = .); \ + PROVIDE(kallsyms_token_table = .); \ + PROVIDE(kallsyms_token_index = .); \ + PROVIDE(kallsyms_markers = .); \ + PROVIDE(kallsyms_seqs_of_names = .); +/* * Read only Data */ #define RO_DATA (align) \ . = ALIGN((align)); \ + PRELIMINARY_SYMBOL_DEFINITIONS \ .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \ __start_rodata = .; \ *(.rodata) *(.rodata.*) \
kernel/kallsyms.c +0 -6
@@ -325,12 +325,6 @@ static unsigned long get_symbol_pos(unsigned long addr,unsigned long symbol_start =0 , symbol_end =0 ;unsigned long i, low, high, mid; -/* This kernel should never had been booted. */ -if (!IS_ENABLED (CONFIG_KALLSYMS_BASE_RELATIVE )) -BUG_ON (!kallsyms_addresses); -else -BUG_ON (!kallsyms_offsets); -/* Do a binary search on the sorted kallsyms_addresses array. */ low =0 ; high = kallsyms_num_syms;
kernel/kallsyms_internal.h +12 -18
@@ -5,27 +5,21 @@#include <linux/types.h> /* -* These will be re-linked against their real values -* during the second link stage. +* These will be re-linked against their real values during the second link +* stage. Preliminary values must be provided in the linker script using the +* PROVIDE() directive so that the first link stage can complete successfully. */ -extern const unsigned long kallsyms_addresses[]__weak ; -extern const int kallsyms_offsets[]__weak ; -extern const u8 kallsyms_names[]__weak ; +extern const unsigned long kallsyms_addresses[]; +extern const int kallsyms_offsets[]; +extern const u8 kallsyms_names[]; -/* -* Tell the compiler that the count isn't in the small data section if the arch -* has one (eg: FRV). -*/ -extern const unsigned int kallsyms_num_syms -__section(".rodata") __attribute__((weak)); - -extern const unsigned long kallsyms_relative_base -__section(".rodata") __attribute__((weak)); +extern const unsigned int kallsyms_num_syms; +extern const unsigned long kallsyms_relative_base; -extern const char kallsyms_token_table[]__weak ; -extern const u16 kallsyms_token_index[]__weak ; +extern const char kallsyms_token_table[]; +extern const u16 kallsyms_token_index[]; -extern const unsigned int kallsyms_markers[]__weak ; -extern const u8 kallsyms_seqs_of_names[]__weak ; +extern const unsigned int kallsyms_markers[]; +extern const u8 kallsyms_seqs_of_names[];#endif // LINUX_KALLSYMS_INTERNAL_H_
Signature · 1 line
2.43.0.429.g432eaa2c6b-goog
RFC PATCH 2/5 vmlinux: Avoid weak reference to notes section
In reply to Ard BiesheuvelFrom: Ard Biesheuvel <[email protected]>
Weak references are references that are permitted to remain unsatisfied in the final link. This means they cannot be implemented using place relative relocations, resulting in GOT entries when using position independent code generation.
The notes section should always exist, so the weak annotations can be omitted.
--- kernel/ksysfs.c | 4 ++-- lib/buildid.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
kernel/ksysfs.c +2 -2
@@ -226,8 +226,8 @@ KERNEL_ATTR_RW(rcu_normal);/* * Make /sys/kernel/notes give the raw contents of our kernel .notes section. */ -extern const void __start_notes__weak ; -extern const void __stop_notes__weak ; +extern const void __start_notes; +extern const void __stop_notes;#define notes_size (&__stop_notes - &__start_notes) static ssize_t notes_read(struct file *filp, struct kobject *kobj,
lib/buildid.c +2 -2
@@ -182,8 +182,8 @@ unsigned char vmlinux_build_id[BUILD_ID_SIZE_MAX] __ro_after_init;*/ void __init init_vmlinux_build_id (void ) { -extern const void __start_notes__weak ; -extern const void __stop_notes__weak ; +extern const void __start_notes; +extern const void __stop_notes;unsigned int size = &__stop_notes - &__start_notes;build_id_parse_buf (&__start_notes, vmlinux_build_id, size);
Signature · 1 line
2.43.0.429.g432eaa2c6b-goog
RFC PATCH 3/5 btf: Avoid weak external references
In reply to Ard BiesheuvelFrom: Ard Biesheuvel <[email protected]>
If the BTF code is enabled in the build configuration, the start/stop BTF markers are guaranteed to exist in the final link but not during the first linker pass.
Avoid GOT based relocations to these markers in the final executable by providing preliminary definitions that will be used by the first linker pass, and superseded by the actual definitions in the subsequent ones.
--- include/asm-generic/vmlinux.lds.h | 2 ++ kernel/bpf/btf.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-)
include/asm-generic/vmlinux.lds.h +2 -0
@@ -456,6 +456,8 @@* independent code. */ #define PRELIMINARY_SYMBOL_DEFINITIONS \ + PROVIDE(__start_BTF = .); \ + PROVIDE(__stop_BTF = .); \ PROVIDE(kallsyms_addresses = .); \ PROVIDE(kallsyms_offsets = .); \ PROVIDE(kallsyms_names = .); \
kernel/bpf/btf.c +2 -2
@@ -5581,8 +5581,8 @@ static struct btf *btf_parse(const union bpf_attr *attr, bpfptr_t uattr, u32 uatreturn ERR_PTR (err); } -extern char __weak __start_BTF[]; -extern char __weak __stop_BTF[]; +extern char __start_BTF[]; +extern char __stop_BTF[];extern struct btf *btf_vmlinux;#define BPF_MAP_TYPE (_id, _ops)
Signature · 1 line
2.43.0.429.g432eaa2c6b-goog
RFC PATCH 4/5 x86/head64: Replace pointer fixups with PIE codegen
In reply to Ard BiesheuvelFrom: Ard Biesheuvel <[email protected]>
Some of the C code in head64.c may be called from a different virtual address than it was linked at. Currently, we deal with this by using ordinary, position dependent codegen, and fixing up all symbol references on the fly. This is fragile and tricky to maintain. It is also unnecessary: we can use position independent codegen (with hidden visibility) to ensure that all compiler generated symbol references are RIP-relative, removing the need for fixups entirely.
It does mean we need explicit references to kernel virtual addresses to be generated by hand, so generate those using a movabs instruction in inline asm in the handful places where we actually need this.
While at it, move these routines to .inittext where they belong.
--- arch/x86/Makefile | 11 ++ arch/x86/boot/compressed/Makefile | 2 +- arch/x86/include/asm/init.h | 2 - arch/x86/include/asm/setup.h | 2 +- arch/x86/kernel/Makefile | 4 + arch/x86/kernel/head64.c | 117 +++++++------------- 6 files changed, 60 insertions(+), 78 deletions(-)
arch/x86/Makefile +11 -0
@@ -168,6 +168,17 @@ else KBUILD_CFLAGS += -mcmodel=kernel KBUILD_RUSTFLAGS += -Cno-redzone=y KBUILD_RUSTFLAGS += -Ccode-model=kernel + + PIE_CFLAGS := -fpie -mcmodel=small \ + -include $(srctree)/include/linux/hidden.h + + ifeq ($(CONFIG_STACKPROTECTOR),y) + ifeq ($(CONFIG_SMP),y) + PIE_CFLAGS += -mstack-protector-guard-reg=gs + endif + endif + + export PIE_CFLAGS endif #
arch/x86/boot/compressed/Makefile +1 -1
@@ -84,7 +84,7 @@ LDFLAGS_vmlinux += -T hostprogs := mkpiggy HOST_EXTRACFLAGS += -I$(srctree)/tools/include -sed-voffset := -e 's/^\([0-9a-fA-F]*\) [ABCDGRSTVW] \(_text\|__bss_start\|_end\)$$/\#define VO_\2 _AC(0x\1,UL)/p' +sed-voffset := -e 's/^\([0-9a-fA-F]*\) [ABbCDGRSTtVW] \(_text\|__bss_start\|_end\)$$/\#define VO_\2 _AC(0x\1,UL)/p' quiet_cmd_voffset = VOFFSET $@ cmd_voffset = $(NM) $< | sed -n $(sed-voffset) > $@
arch/x86/include/asm/init.h +0 -2
@@ -2,8 +2,6 @@ #ifndef _ASM_X86_INIT_H #define _ASM_X86_INIT_H -#define __head __section(".head.text") - struct x86_mapping_info { void *(*alloc_pgt_page)(void *); /* allocate buf for page table */ void *context; /* context for alloc_pgt_page */
arch/x86/include/asm/setup.h +1 -1
@@ -48,7 +48,7 @@ extern unsigned long saved_video_mode;extern void reserve_standard_io_resources (void );extern void i386_reserve_resources (void );extern unsigned long __startup_64 (unsigned long physaddr,struct boot_params *bp); -extern void startup_64_setup_env (unsigned long physbase); +extern void startup_64_setup_env (void );extern void early_setup_idt (void );extern void __init do_early_exception (struct pt_regs *regs,int trapnr);
arch/x86/kernel/Makefile +4 -0
@@ -21,6 +21,10 @@ CFLAGS_REMOVE_sev.o = -pg CFLAGS_REMOVE_rethook.o = -pg endif +# head64.c contains C code that may execute from a different virtual address +# than it was linked at, so we always build it using PIE codegen +CFLAGS_head64.o += $(PIE_CFLAGS) + KASAN_SANITIZE_head$(BITS).o := n KASAN_SANITIZE_dumpstack.o := n KASAN_SANITIZE_dumpstack_$(BITS).o := n
arch/x86/kernel/head64.c +43 -74
236 lines not on this page · raw message
Signature · 1 line
2.43.0.429.g432eaa2c6b-goog
Re: [RFC PATCH 4/5] x86/head64: Replace pointer fixups with PIE codegen
Quoted 33 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
Some of the C code in
head64.cmay be called from a different virtual address than it was linked at. Currently, we deal with this by using ordinary, position dependent codegen, and fixing up all symbol references on the fly. This is fragile and tricky to maintain. It is also unnecessary: we can use position independent codegen (with hidden visibility) to ensure that all compiler generated symbol references are RIP-relative, removing the need for fixups entirely.It does mean we need explicit references to kernel virtual addresses to be generated by hand, so generate those using a movabs instruction in inline asm in the handful places where we actually need this.
While at it, move these routines to .inittext where they belong.
Signed-off-by Ard Biesheuvel <[email protected]>--- arch/x86/Makefile | 11 ++ arch/x86/boot/compressed/Makefile | 2 +- arch/x86/include/asm/init.h | 2 - arch/x86/include/asm/setup.h | 2 +- arch/x86/kernel/Makefile | 4 + arch/x86/kernel/head64.c | 117 +++++++------------- 6 files changed, 60 insertions(+), 78 deletions(-)arch/x86/Makefile +0
-0@@ -168,6 +168,17 @@ else KBUILD_CFLAGS += -mcmodel=kernel
arch/x86/Makefile else · line 178
Quoted 10 lines
arch/x86/Makefile +8
-0KBUILD_RUSTFLAGS += -Cno-redzone=y KBUILD_RUSTFLAGS += -Ccode-model=kernel + + PIE_CFLAGS := -fpie -mcmodel=small \ + -include $(srctree)/include/linux/hidden.h + + ifeq ($(CONFIG_STACKPROTECTOR),y) + ifeq ($(CONFIG_SMP),y) + PIE_CFLAGS += -mstack-protector-guard-reg=gs + endif
This compiler flag requires GCC 8.1 or later. When I posted a patch series[1] to convert the stack protector to a normal percpu variable instead of the fixed offset, there was pushback over requiring GCC 8.1 to keep stack protector support. I added code to objtool to convert code from older compilers, but there hasn't been any feedback since. Similar conversion code would be needed in objtool for this unless the decision is made to require GCC 8.1 for stack protector support going forward.
Brian Gerst
Re: [RFC PATCH 4/5] x86/head64: Replace pointer fixups with PIE codegen
Quoted 54 lines · Brian Gerst
Quoted 33 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
Some of the C code in
head64.cmay be called from a different virtual address than it was linked at. Currently, we deal with this by using ordinary, position dependent codegen, and fixing up all symbol references on the fly. This is fragile and tricky to maintain. It is also unnecessary: we can use position independent codegen (with hidden visibility) to ensure that all compiler generated symbol references are RIP-relative, removing the need for fixups entirely.It does mean we need explicit references to kernel virtual addresses to be generated by hand, so generate those using a movabs instruction in inline asm in the handful places where we actually need this.
While at it, move these routines to .inittext where they belong.
Signed-off-by Ard Biesheuvel <[email protected]>--- arch/x86/Makefile | 11 ++ arch/x86/boot/compressed/Makefile | 2 +- arch/x86/include/asm/init.h | 2 - arch/x86/include/asm/setup.h | 2 +- arch/x86/kernel/Makefile | 4 + arch/x86/kernel/head64.c | 117 +++++++------------- 6 files changed, 60 insertions(+), 78 deletions(-)arch/x86/Makefile +0
-0@@ -168,6 +168,17 @@ else KBUILD_CFLAGS += -mcmodel=kernelarch/x86/Makefile else · line 178
Quoted 10 lines
arch/x86/Makefile +8
-0KBUILD_RUSTFLAGS += -Cno-redzone=y KBUILD_RUSTFLAGS += -Ccode-model=kernel + + PIE_CFLAGS := -fpie -mcmodel=small \ + -include $(srctree)/include/linux/hidden.h + + ifeq ($(CONFIG_STACKPROTECTOR),y) + ifeq ($(CONFIG_SMP),y) + PIE_CFLAGS += -mstack-protector-guard-reg=gs + endifThis compiler flag requires GCC 8.1 or later. When I posted a patch series[1] to convert the stack protector to a normal percpu variable instead of the fixed offset, there was pushback over requiring GCC 8.1 to keep stack protector support. I added code to objtool to convert code from older compilers, but there hasn't been any feedback since. Similar conversion code would be needed in objtool for this unless the decision is made to require GCC 8.1 for stack protector support going forward.
Quoted 3 lines
Brian Gerst
I was going to comment on this as well, as that flag was only supported in clang 12.0.0 and newer. It should not be too big of a deal for us though, as I was already planning on bumping the minimum supported version of clang for building the kernel to 13.0.1 (but there may be breakage reports if this series lands before that):
https://lore.kernel.org/[email protected]/
Cheers,
Nathan
Re: [RFC PATCH 4/5] x86/head64: Replace pointer fixups with PIE codegen
Quoted 58 lines · Nathan Chancellor
Quoted 56 lines · Brian Gerst
Quoted 33 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
Some of the C code in
head64.cmay be called from a different virtual address than it was linked at. Currently, we deal with this by using ordinary, position dependent codegen, and fixing up all symbol references on the fly. This is fragile and tricky to maintain. It is also unnecessary: we can use position independent codegen (with hidden visibility) to ensure that all compiler generated symbol references are RIP-relative, removing the need for fixups entirely.It does mean we need explicit references to kernel virtual addresses to be generated by hand, so generate those using a movabs instruction in inline asm in the handful places where we actually need this.
While at it, move these routines to .inittext where they belong.
Signed-off-by Ard Biesheuvel <[email protected]>--- arch/x86/Makefile | 11 ++ arch/x86/boot/compressed/Makefile | 2 +- arch/x86/include/asm/init.h | 2 - arch/x86/include/asm/setup.h | 2 +- arch/x86/kernel/Makefile | 4 + arch/x86/kernel/head64.c | 117 +++++++------------- 6 files changed, 60 insertions(+), 78 deletions(-)arch/x86/Makefile +0
-0@@ -168,6 +168,17 @@ else KBUILD_CFLAGS += -mcmodel=kernelarch/x86/Makefile else · line 178
Quoted 10 lines
arch/x86/Makefile +8
-0KBUILD_RUSTFLAGS += -Cno-redzone=y KBUILD_RUSTFLAGS += -Ccode-model=kernel + + PIE_CFLAGS := -fpie -mcmodel=small \ + -include $(srctree)/include/linux/hidden.h + + ifeq ($(CONFIG_STACKPROTECTOR),y) + ifeq ($(CONFIG_SMP),y) + PIE_CFLAGS += -mstack-protector-guard-reg=gs + endifThis compiler flag requires GCC 8.1 or later. When I posted a patch series[1] to convert the stack protector to a normal percpu variable instead of the fixed offset, there was pushback over requiring GCC 8.1 to keep stack protector support. I added code to objtool to convert code from older compilers, but there hasn't been any feedback since. Similar conversion code would be needed in objtool for this unless the decision is made to require GCC 8.1 for stack protector support going forward.
Brian Gerst
Quoted 8 lines
Quoted 1 line
I was going to comment on this as well, as that flag was only supported in clang 12.0.0 and newer. It should not be too big of a deal for us though, as I was already planning on bumping the minimum supported version of clang for building the kernel to 13.0.1 (but there may be breakage reports if this series lands before that):
Thanks for pointing this out.
Given that building the entire kernel with fPIC is neither necessary nor sufficient, I am going to abandon this approach.
If we apply fPIC to only a handful of compilation units containing code that runs from the 1:1 mapping, it is not unreasonable to simply disable the stack protector altogether for those pieces too. This works around the older GCC issue.
RFC PATCH 5/5 x86: Build the core kernel with position independent codegen
In reply to Ard BiesheuvelFrom: Ard Biesheuvel <[email protected]>
Pass the -fpie flag to the compiler when building objects that are intended for the core kernel. This ensures that all implicit symbol references are emitted using RIP-relative relocations, allowing the code to be executed correctly even if it runs from a different virtual address than the address it was linked/loaded/relocated to run at.
This is necessary to ensure that all C code that gets pulled in by the early startup code runs correctly without the need for unpalatable hacks in the code to force RIP-relative references.
--- arch/x86/Makefile | 7 +++++-- arch/x86/entry/vdso/Makefile | 2 +- arch/x86/kernel/Makefile | 4 ---- arch/x86/realmode/rm/Makefile | 1 + include/asm-generic/vmlinux.lds.h | 2 ++ 5 files changed, 9 insertions(+), 7 deletions(-)
arch/x86/Makefile +5 -2
@@ -165,11 +165,13 @@ else KBUILD_RUSTFLAGS += $(rustflags-y) KBUILD_CFLAGS += -mno-red-zone - KBUILD_CFLAGS += -mcmodel=kernel + KBUILD_CFLAGS_MODULE += -mcmodel=kernel KBUILD_RUSTFLAGS += -Cno-redzone=y - KBUILD_RUSTFLAGS += -Ccode-model=kernel + KBUILD_RUSTFLAGS_KERNEL += -Ccode-model=small + KBUILD_RUSTFLAGS_MODULE += -Ccode-model=kernel PIE_CFLAGS := -fpie -mcmodel=small \ + $(call cc-option,-Wa$(comma)-mrelax-relocations=no) \ -include $(srctree)/include/linux/hidden.h ifeq ($(CONFIG_STACKPROTECTOR),y)
@@ -178,6 +180,7 @@ else endif endif + KBUILD_CFLAGS_KERNEL += $(PIE_CFLAGS) export PIE_CFLAGS endif
arch/x86/entry/vdso/Makefile +1 -1
@@ -149,7 +149,7 @@ $(obj)/vdso32.so.dbg: KBUILD_AFLAGS = $(KBUILD_AFLAGS_32) $(obj)/vdso32.so.dbg: asflags-$(CONFIG_X86_64) += -m32 KBUILD_CFLAGS_32 := $(filter-out -m64,$(KBUILD_CFLAGS)) -KBUILD_CFLAGS_32 := $(filter-out -mcmodel=kernel,$(KBUILD_CFLAGS_32)) +KBUILD_CFLAGS_32 := $(filter-out -mcmodel=small,$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out -mfentry,$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out $(RANDSTRUCT_CFLAGS),$(KBUILD_CFLAGS_32))
arch/x86/kernel/Makefile +0 -4
@@ -21,10 +21,6 @@ CFLAGS_REMOVE_sev.o = -pg CFLAGS_REMOVE_rethook.o = -pg endif -# head64.c contains C code that may execute from a different virtual address -# than it was linked at, so we always build it using PIE codegen -CFLAGS_head64.o += $(PIE_CFLAGS) - KASAN_SANITIZE_head$(BITS).o := n KASAN_SANITIZE_dumpstack.o := n KASAN_SANITIZE_dumpstack_$(BITS).o := n
arch/x86/realmode/rm/Makefile +1 -0
@@ -76,5 +76,6 @@ KBUILD_CFLAGS := $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \ -I$(srctree)/arch/x86/boot KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ KBUILD_CFLAGS += -fno-asynchronous-unwind-tables +KBUILD_CFLAGS_KERNEL := $(filter-out $(PIE_CFLAGS),$(KBUILD_CFLAGS_KERNEL)) GCOV_PROFILE := n UBSAN_SANITIZE := n
include/asm-generic/vmlinux.lds.h +2 -0
@@ -355,6 +355,7 @@ *(.data..decrypted) \ *(.ref.data) \ *(.data..shared_aligned) /* percpu related */ \ + *(.data.rel .data.rel.*) \ MEM_KEEP(init.data*) \ *(.data.unlikely) \ __start_once = .; \
@@ -477,6 +478,7 @@ .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \ __start_rodata = .; \ *(.rodata) *(.rodata.*) \ + *(.data.rel.ro*) \ SCHED_DATA \RO_AFTER_INIT_DATA /* Read only after init */ \ . = ALIGN(8); \
Signature · 1 line
2.43.0.429.g432eaa2c6b-goog