s390: compile relocatable kernel with/without fPIE
cover s390: compile relocatable kernel with/without fPIE
Hi All,
This is a rebased version of Josh's patch series with a few fixups.
https://git.kernel.org/pub/scm/linux/kernel/git/jpoimboe/linux.git/log/?h=s390
This introduces the capability to compile the s390 relocatable kernel with and without the -fPIE option.
When utilizing the kpatch functionality, it is advisable to compile the kernel without the -fPIE option. This is particularly important if the kernel is built with the -ffunction-sections and -fdata-sections flags. The linker imposes a restriction on the number of sections (limited to 64k), necessitating the omission of -fPIE.
[1] https://gcc.gnu.org/pipermail/gcc-patches/2023-June/622872.html
[2] https://gcc.gnu.org/pipermail/gcc-patches/2023-August/625986.html
Gcc recently implemented an optimization [1] for loading symbols without explicit alignment, aligning with the IBM Z ELF ABI. This ABI mandates symbols to reside on a 2-byte boundary, enabling the use of the larl instruction. However, kernel linker scripts may still generate unaligned symbols. To address this, a new -munaligned-symbols option has been introduced [2] in recent gcc versions. This option has to be used with future gcc versions.
Older Clang lacks support for handling unaligned symbols generated by kernel linker scripts when the kernel is built without -fPIE. However, future versions of Clang will include support for the -munaligned-symbols option. When the support is unavailable, compile the kernel with -fPIE to maintain the existing behavior.
Patch 1 filters out -munaligned-symbol flag for vdso code. This is beneficial when compiling kernel with -fno-PIE and -munaligned-symbols combination.
Patch 2 introduces the 'relocs' tool, which reads the vmlinux file and generates a vmlinux.relocs_64 section, containing offsets for all R_390_64 relocations.
Patch 3 enables the compilation of a relocatable kernel with or without the -fPIE option. It allows for building the relocatable kernel without -fPIE. However, if compiler cannot handle unaligned symbols, the kernel is built with -fPIE.
Patch 4 handles orphan .rela sections when kernel is built with -fno-PIE.
kpatch tools changes:
* -mno-pic-data-is-text-relative prevents relative addressing between code and data. This is needed to avoid relocation error when klp text and data are too far apart. kpatch already includes this flag. However, with these changes, ARCH_KFLAGS+="-fPIC" should be added to s390 kpatch tools, As -mno-pic-data-is-text-relative can be used only with -fPIC. The corresponding pull request will be sent to kpatch tools.
Thank you,
Sumanth
Josh Poimboeuf (2):
s390: Add relocs tool
s390: Compile relocatable kernel without -fPIE
Sumanth Korikkar (2):
s390/vdso64: filter out munaligned-symbols flag for vdso s390/kernel: vmlinux.lds.S: handle orphan .rela sections
arch/s390/Kconfig | 15 +- arch/s390/Makefile | 8 +- arch/s390/boot/.gitignore | 1 + arch/s390/boot/Makefile | 14 +- arch/s390/boot/boot.h | 6 + arch/s390/boot/startup.c | 80 +++++- arch/s390/boot/vmlinux.lds.S | 18 ++ arch/s390/include/asm/physmem_info.h | 1 + arch/s390/kernel/vdso64/Makefile | 1 + arch/s390/kernel/vmlinux.lds.S | 15 ++ arch/s390/tools/.gitignore | 1 + arch/s390/tools/Makefile | 5 + arch/s390/tools/relocs.c | 390 +++++++++++++++++++++++++++ 13 files changed, 542 insertions(+), 13 deletions(-) create mode 100644 arch/s390/tools/relocs.c
Signature · 1 line
2.40.1
PATCH 1/4 s390/vdso64: filter out munaligned-symbols flag for vdso
Gcc recently implemented an optimization [1] for loading symbols without explicit alignment, aligning with the IBM Z ELF ABI. This ABI mandates symbols to reside on a 2-byte boundary, enabling the use of the larl instruction. However, kernel linker scripts may still generate unaligned symbols. To address this, a new -munaligned-symbols option has been introduced [2] in recent gcc versions.
[1] https://gcc.gnu.org/pipermail/gcc-patches/2023-June/622872.html
[2] https://gcc.gnu.org/pipermail/gcc-patches/2023-August/625986.html
However, when -munaligned-symbols is used in vdso code, it leads to the following compilation error:.data.rel.ro.local' referenced in section .text' of arch/s390/kernel/vdso64/vdso64_generic.o: defined in discarded section `.data.rel.ro.local' of arch/s390/kernel/vdso64/vdso64_generic.o
vdso linker script discards .data section to make it lightweight. However, -munaligned-symbols in vdso object files references literal pool and accesses _vdso_data. Hence, compile vdso code without -munaligned-symbols. This means in the future, vdso code should deal with alignment of newly introduced unaligned linker symbols.
--- arch/s390/kernel/vdso64/Makefile | 1 + 1 file changed, 1 insertion(+)
arch/s390/kernel/vdso64/Makefile +1 -0
@@ -25,6 +25,7 @@ KBUILD_AFLAGS_64 += -m64 KBUILD_CFLAGS_64 := $(filter-out -m64,$(KBUILD_CFLAGS)) KBUILD_CFLAGS_64 := $(filter-out -mno-pic-data-is-text-relative,$(KBUILD_CFLAGS_64)) +KBUILD_CFLAGS_64 := $(filter-out -munaligned-symbols,$(KBUILD_CFLAGS_64)) KBUILD_CFLAGS_64 += -m64 -fPIC -fno-common -fno-builtin ldflags-y := -shared -soname=linux-vdso64.so.1 \ --hash-style=both --build-id=sha1 -T
Signature · 1 line
2.40.1
Re: [PATCH 1/4] s390/vdso64: filter out munaligned-symbols flag for vdso
Quoted 22 lines · Sumanth Korikkar
Gcc recently implemented an optimization [1] for loading symbols without explicit alignment, aligning with the IBM Z ELF ABI. This ABI mandates symbols to reside on a 2-byte boundary, enabling the use of the larl instruction. However, kernel linker scripts may still generate unaligned symbols. To address this, a new -munaligned-symbols option has been introduced [2] in recent gcc versions.
[1] https://gcc.gnu.org/pipermail/gcc-patches/2023-June/622872.html
[2] https://gcc.gnu.org/pipermail/gcc-patches/2023-August/625986.htmlHowever, when -munaligned-symbols is used in vdso code, it leads to the following compilation error:
.data.rel.ro.local' referenced in section.text' ofarch/s390/kernel/vdso64/vdso64_generic.o: defined in discarded section `.data.rel.ro.local' ofarch/s390/kernel/vdso64/vdso64_generic.ovdso linker script discards .data section to make it lightweight. However, -munaligned-symbols in vdso object files references literal pool and accesses
_vdso_data. Hence, compile vdso code without -munaligned-symbols. This means in the future, vdso code should deal with alignment of newly introduced unaligned linker symbols.
Quoted 4 lines
Signed-off-by Sumanth Korikkar <[email protected]>--- arch/s390/kernel/vdso64/Makefile | 1 + 1 file changed, 1 insertion(+)
PATCH 2/4 s390: Add relocs tool
In reply to Sumanth KorikkarFrom: Josh Poimboeuf <[email protected]>
This 'relocs' tool is copied from the x86 version, ported for s390, and greatly simplified to remove unnecessary features.
It reads vmlinux and outputs assembly to create a .vmlinux.relocs_64 section which contains the offsets of all R_390_64 relocations which apply to allocatable sections.
--- arch/s390/tools/.gitignore | 1 + arch/s390/tools/Makefile | 5 + arch/s390/tools/relocs.c | 390 +++++++++++++++++++++++++++++++++++++ 3 files changed, 396 insertions(+) create mode 100644 arch/s390/tools/relocs.c
arch/s390/tools/.gitignore +1 -0
@@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only gen_facilities gen_opcode_table +relocs
arch/s390/tools/Makefile +5 -0
@@ -25,3 +25,8 @@ $(kapi)/facility-defs.h: $(obj)/gen_facilities FORCE $(kapi)/dis-defs.h: $(obj)/gen_opcode_table FORCE $(call filechk,dis-defs.h) + +hostprogs += relocs +PHONY += relocs +relocs: $(obj)/relocs + @:
arch/s390/tools/relocs.c new file +390 -0
390 lines not on this page · raw message
Signature · 1 line
2.40.1
Re: [PATCH 2/4] s390: Add relocs tool
Quoted 9 lines · Sumanth Korikkar
From: Josh Poimboeuf <[email protected]>
This 'relocs' tool is copied from the x86 version, ported for s390, and greatly simplified to remove unnecessary features.
It reads vmlinux and outputs assembly to create a .vmlinux.relocs_64 section which contains the offsets of all
R_390_64relocations which apply to allocatable sections.
Quoted 7 lines
Signed-off-by Josh Poimboeuf <[email protected]>--- arch/s390/tools/.gitignore | 1 + arch/s390/tools/Makefile | 5 + arch/s390/tools/relocs.c | 390 +++++++++++++++++++++++++++++++++++++ 3 files changed, 396 insertions(+) create mode 100644 arch/s390/tools/relocs.c
PATCH 3/4 s390: Compile relocatable kernel without -fPIE
In reply to Sumanth KorikkarFrom: Josh Poimboeuf <[email protected]>
On s390, currently kernel uses the '-fPIE' compiler flag for compiling vmlinux. This has a few problems:
- It uses dynamic symbols (.dynsym), for which the linker refuses to allow more than 64k sections. This can break features which use '-ffunction-sections' and '-fdata-sections', including kpatch-build
[1] and Function Granular KASLR.
- It unnecessarily uses GOT relocations, adding an extra layer of indirection for many memory accesses.
Instead of using '-fPIE', resolve all the relocations at link time and then manually adjust any absolute relocations (R_390_64) during boot.
This is done by first telling the linker to preserve all relocations during the vmlinux link. (Note this is harmless: they are later stripped in the vmlinux.bin link.)
Then use the 'relocs' tool to find all absolute relocations (R_390_64) which apply to allocatable sections. The offsets of those relocations are saved in a special section which is then used to adjust the relocations during boot.
(Note: For some reason, Clang occasionally creates a GOT reference, even without '-fPIE'. So Clang-compiled kernels have a GOT, which needs to be adjusted.)
On my mostly-defconfig kernel, this reduces kernel text size by ~1.3%.
[1] https://github.com/dynup/kpatch/issues/1284
[2] https://gcc.gnu.org/pipermail/gcc-patches/2023-June/622872.html
[3] https://gcc.gnu.org/pipermail/gcc-patches/2023-August/625986.html
Compiler consideration:
Gcc recently implemented an optimization [2] for loading symbols without explicit alignment, aligning with the IBM Z ELF ABI. This ABI mandates symbols to reside on a 2-byte boundary, enabling the use of the larl instruction. However, kernel linker scripts may still generate unaligned symbols. To address this, a new -munaligned-symbols option has been introduced [3] in recent gcc versions. This option has to be used with future gcc versions.
Older Clang lacks support for handling unaligned symbols generated by kernel linker scripts when the kernel is built without -fPIE. However, future versions of Clang will include support for the -munaligned-symbols option. When the support is unavailable, compile the kernel with -fPIE to maintain the existing behavior.
In addition to it:
move vmlinux.relocs to safe relocation
When the kernel is built with CONFIG_KERNEL_UNCOMPRESSED, the entire uncompressed vmlinux.bin is positioned in the bzImage decompressor image at the default kernel LMA of 0x100000, enabling it to be executed in-place. However, the size of .vmlinux.relocs could be large enough to cause an overlap with the uncompressed kernel at the address 0x100000. To address this issue, .vmlinux.relocs is positioned after the .rodata.compressed in the bzImage. Nevertheless, in this configuration, vmlinux.relocs will overlap with the .bss section of vmlinux.bin. To overcome that, move vmlinux.relocs to a safe location before clearing .bss and handling relocs.
[Rebased Josh Poimboeuf patches and move vmlinux.relocs
to safe location: Sumanth Korikkar <[email protected]>]
--- arch/s390/Kconfig | 15 ++++-- arch/s390/Makefile | 8 ++- arch/s390/boot/.gitignore | 1 + arch/s390/boot/Makefile | 14 ++++- arch/s390/boot/boot.h | 6 +++ arch/s390/boot/startup.c | 80 +++++++++++++++++++++++++--- arch/s390/boot/vmlinux.lds.S | 18 +++++++ arch/s390/include/asm/physmem_info.h | 1 + arch/s390/kernel/vmlinux.lds.S | 9 ++++ 9 files changed, 139 insertions(+), 13 deletions(-)
arch/s390/Kconfig +12 -3
@@ -583,14 +583,23 @@ config RELOCATABLE help This builds a kernel image that retains relocation information so it can be loaded at an arbitrary address. - The kernel is linked as a position-independent executable (PIE) - and contains dynamic relocations which are processed early in the - bootup process. The relocations make the kernel image about 15% larger (compressed 10%), but are discarded at runtime. Note: this option exists only for documentation purposes, please do not remove it. +config PIE_BUILD + def_bool CC_IS_CLANG && !$(cc-option,-munaligned-symbols) + help + If the compiler is unable to generate code that can manage unaligned + symbols, the kernel is linked as a position-independent executable + (PIE) and includes dynamic relocations that are processed early + during bootup. + + For kpatch functionality, it is recommended to build the kernel + without the PIE_BUILD option. PIE_BUILD is only enabled when the + compiler lacks proper support for handling unaligned symbols. + config RANDOMIZE_BASE bool "Randomize the address of the kernel image (KASLR)" default y
arch/s390/Makefile +7 -1
@@ -14,8 +14,14 @@ KBUILD_AFLAGS_MODULE += -fPIC KBUILD_CFLAGS_MODULE += -fPIC KBUILD_AFLAGS += -m64 KBUILD_CFLAGS += -m64 +ifdef CONFIG_PIE_BUILD KBUILD_CFLAGS += -fPIE LDFLAGS_vmlinux := -pie -z notext +else +KBUILD_CFLAGS += $(call cc-option,-munaligned-symbols,) +LDFLAGS_vmlinux := --emit-relocs --discard-none +extra_tools := relocs +endif aflags_dwarf := -Wa,-gdwarf-2 KBUILD_AFLAGS_DECOMPRESSOR := $(CLANG_FLAGS) -m64 -D__ASSEMBLY__ ifndef CONFIG_AS_IS_LLVM
@@ -143,7 +149,7 @@ archheaders: archprepare: $(Q)$(MAKE) $(build)=$(syscalls) kapi - $(Q)$(MAKE) $(build)=$(tools) kapi + $(Q)$(MAKE) $(build)=$(tools) kapi $(extra_tools) ifeq ($(KBUILD_EXTMOD),) # We need to generate vdso-offsets.h before compiling certain files in kernel/. # In order to do that, we should use the archprepare target, but we can't since
arch/s390/boot/.gitignore +1 -0
@@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only image bzImage +relocs.S section_cmp.* vmlinux vmlinux.lds
arch/s390/boot/Makefile +13 -1
@@ -37,7 +37,8 @@ CFLAGS_sclp_early_core.o += -I$(srctree)/drivers/s390/char obj-y := head.o als.o startup.o physmem_info.o ipl_parm.o ipl_report.o vmem.o obj-y += string.o ebcdic.o sclp_early_core.o mem.o ipl_vmparm.o cmdline.o -obj-y += version.o pgm_check_info.o ctype.o ipl_data.o machine_kexec_reloc.o +obj-y += version.o pgm_check_info.o ctype.o ipl_data.o +obj-y += $(if $(CONFIG_PIE_BUILD),machine_kexec_reloc.o,relocs.o) obj-$(findstring y, $(CONFIG_PROTECTED_VIRTUALIZATION_GUEST) $(CONFIG_PGSTE)) += uv.o obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o obj-y += $(if $(CONFIG_KERNEL_UNCOMPRESSED),,decompressor.o) info.o
@@ -48,6 +49,9 @@ targets := bzImage section_cmp.boot.data section_cmp.boot.preserved.data $(obj-y targets += vmlinux.lds vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 targets += vmlinux.bin.xz vmlinux.bin.lzma vmlinux.bin.lzo vmlinux.bin.lz4 targets += vmlinux.bin.zst info.bin syms.bin vmlinux.syms $(obj-all) +ifndef CONFIG_PIE_BUILD +targets += relocs.S +endif OBJECTS := $(addprefix $(obj)/,$(obj-y)) OBJECTS_ALL := $(addprefix $(obj)/,$(obj-all))
@@ -106,6 +110,14 @@ OBJCOPYFLAGS_vmlinux.bin := -O binary --remove-section=.comment --remove-section $(obj)/vmlinux.bin: vmlinux FORCE $(call if_changed,objcopy) +ifndef CONFIG_PIE_BUILD +CMD_RELOCS=arch/s390/tools/relocs +quiet_cmd_relocs = RELOCS $@ + cmd_relocs = $(CMD_RELOCS) $< > $@ +$(obj)/relocs.S: vmlinux FORCE + $(call if_changed,relocs) +endif + suffix-$(CONFIG_KERNEL_GZIP) := .gz suffix-$(CONFIG_KERNEL_BZIP2) := .bz2 suffix-$(CONFIG_KERNEL_LZ4) := .lz4
arch/s390/boot/boot.h +6 -0
@@ -25,9 +25,14 @@ struct vmlinux_info {unsigned long bootdata_size;unsigned long bootdata_preserved_off;unsigned long bootdata_preserved_size; +#ifdef CONFIG_PIE_BUILD unsigned long dynsym_start;unsigned long rela_dyn_start;unsigned long rela_dyn_end; +#else +unsigned long got_off; +unsigned long got_size; +#endif unsigned long amode31_size;unsigned long init_mm_off;unsigned long swapper_pg_dir_off;
@@ -83,6 +88,7 @@ extern unsigned long vmalloc_size;extern int vmalloc_size_set;extern char __boot_data_start[], __boot_data_end[];extern char __boot_data_preserved_start[], __boot_data_preserved_end[]; +extern int __vmlinux_relocs_64_start[], __vmlinux_relocs_64_end[];extern char _decompressor_syms_start[], _decompressor_syms_end[];extern char _stack_start[], _stack_end[];extern char _end[], _decompressor_end[];
arch/s390/boot/startup.c +72 -8
130 lines not on this page · raw message
arch/s390/boot/vmlinux.lds.S +18 -0
@@ -110,6 +110,24 @@ SECTIONS _compressed_end = .; } +#ifndef CONFIG_PIE_BUILD + /* + * When the kernel is built with CONFIG_KERNEL_UNCOMPRESSED, the entire + * uncompressed vmlinux.bin is positioned in the bzImage decompressor + * image at the default kernel LMA of 0x100000, enabling it to be + * executed in-place. However, the size of .vmlinux.relocs could be + * large enough to cause an overlap with the uncompressed kernel at the + * address 0x100000. To address this issue, .vmlinux.relocs is + * positioned after the .rodata.compressed. + */ + . = ALIGN(4); + .vmlinux.relocs : { + __vmlinux_relocs_64_start = .; + *(.vmlinux.relocs_64) + __vmlinux_relocs_64_end = .; + } +#endif + #define SB_TRAILER_SIZE 32 /* Trailer needed for Secure Boot */ . += SB_TRAILER_SIZE; /* make sure .sb.trailer does not overwrite the previous section */
arch/s390/include/asm/physmem_info.h +1 -0
@@ -22,6 +22,7 @@ enum reserved_range_type {RR_DECOMPRESSOR ,RR_INITRD ,RR_VMLINUX , +RR_RELOC ,RR_AMODE31 ,RR_IPLREPORT , RR_CERT_COMP_LIST,
arch/s390/kernel/vmlinux.lds.S +9 -0
@@ -63,7 +63,9 @@ SECTIONS *(.data.rel.ro .data.rel.ro.*) } .got : { + __got_start = .; *(.got) + __got_end = .; } . = ALIGN(PAGE_SIZE);
@@ -190,6 +192,7 @@ SECTIONS PERCPU_SECTION(0x100) +#ifdef CONFIG_PIE_BUILD .dynsym ALIGN(8) : { __dynsym_start = .; *(.dynsym)
@@ -206,6 +209,7 @@ SECTIONS .dynstr ALIGN(8) : { *(.dynstr) } +#endif .hash ALIGN(8) : { *(.hash) }
@@ -235,9 +239,14 @@ SECTIONS QUAD(__boot_data_preserved_start) /* bootdata_preserved_off */ QUAD(__boot_data_preserved_end - __boot_data_preserved_start) /* bootdata_preserved_size */ +#ifdef CONFIG_PIE_BUILD QUAD(__dynsym_start) /* dynsym_start */ QUAD(__rela_dyn_start) /* rela_dyn_start */ QUAD(__rela_dyn_end) /* rela_dyn_end */ +#else + QUAD(__got_start) /* got_off */ + QUAD(__got_end - __got_start) /* got_size */ +#endif QUAD(_eamode31 - _samode31) /* amode31_size */ QUAD(init_mm) QUAD(swapper_pg_dir)
Signature · 1 line
2.40.1
Re: [PATCH 3/4] s390: Compile relocatable kernel without -fPIE
Quoted 69 lines · Sumanth Korikkar
From: Josh Poimboeuf <[email protected]>
On s390, currently kernel uses the '-fPIE' compiler flag for compiling vmlinux. This has a few problems:
- It uses dynamic symbols (.dynsym), for which the linker refuses to allow more than 64k sections. This can break features which use '-ffunction-sections' and '-fdata-sections', including kpatch-build
[1] and Function Granular KASLR.- It unnecessarily uses GOT relocations, adding an extra layer of indirection for many memory accesses.
Instead of using '-fPIE', resolve all the relocations at link time and then manually adjust any absolute relocations (
R_390_64) during boot.This is done by first telling the linker to preserve all relocations during the vmlinux link. (Note this is harmless: they are later stripped in the vmlinux.bin link.)
Then use the 'relocs' tool to find all absolute relocations (
R_390_64) which apply to allocatable sections. The offsets of those relocations are saved in a special section which is then used to adjust the relocations during boot.(Note: For some reason, Clang occasionally creates a GOT reference, even without '-fPIE'. So Clang-compiled kernels have a GOT, which needs to be adjusted.)
On my mostly-defconfig kernel, this reduces kernel text size by ~1.3%.
[1] https://github.com/dynup/kpatch/issues/1284
[2] https://gcc.gnu.org/pipermail/gcc-patches/2023-June/622872.html
[3] https://gcc.gnu.org/pipermail/gcc-patches/2023-August/625986.htmlCompiler consideration:
Gcc recently implemented an optimization [2] for loading symbols without explicit alignment, aligning with the IBM Z ELF ABI. This ABI mandates symbols to reside on a 2-byte boundary, enabling the use of the larl instruction. However, kernel linker scripts may still generate unaligned symbols. To address this, a new -munaligned-symbols option has been introduced [3] in recent gcc versions. This option has to be used with future gcc versions.
Older Clang lacks support for handling unaligned symbols generated by kernel linker scripts when the kernel is built without -fPIE. However, future versions of Clang will include support for the -munaligned-symbols option. When the support is unavailable, compile the kernel with -fPIE to maintain the existing behavior.
In addition to it:
move vmlinux.relocs to safe relocationWhen the kernel is built with
CONFIG_KERNEL_UNCOMPRESSED, the entire uncompressed vmlinux.bin is positioned in the bzImage decompressor image at the default kernel LMA of0x100000, enabling it to be executed in-place. However, the size of .vmlinux.relocs could be large enough to cause an overlap with the uncompressed kernel at the address0x100000. To address this issue, .vmlinux.relocs is positioned after the .rodata.compressed in the bzImage. Nevertheless, in this configuration, vmlinux.relocs will overlap with the .bss section of vmlinux.bin. To overcome that, move vmlinux.relocs to a safe location before clearing .bss and handling relocs.[Rebased Josh Poimboeuf patches and move vmlinux.relocs
to safe location: Sumanth Korikkar <[email protected]>]Tested-by Sumanth Korikkar <[email protected]>Signed-off-by Josh Poimboeuf <[email protected]>
Quoted 11 lines
--- arch/s390/Kconfig | 15 ++++-- arch/s390/Makefile | 8 ++- arch/s390/boot/.gitignore | 1 + arch/s390/boot/Makefile | 14 ++++- arch/s390/boot/boot.h | 6 +++ arch/s390/boot/startup.c | 80 +++++++++++++++++++++++++--- arch/s390/boot/vmlinux.lds.S | 18 +++++++ arch/s390/include/asm/physmem_info.h | 1 + arch/s390/kernel/vmlinux.lds.S | 9 ++++ 9 files changed, 139 insertions(+), 13 deletions(-)
PATCH 4/4 s390/kernel: vmlinux.lds.S: handle orphan .rela sections
In reply to Sumanth KorikkarWhen kernel is built with CONFIG_LD_ORPHAN_WARN and -fno-PIE, there are several warnings:
ld: warning: orphan section .rela.iplt' from arch/s390/kernel/head64.o' being placed in section `.rela.dyn'
ld: warning: orphan section .rela.head.text' from arch/s390/kernel/head64.o' being placed in section `.rela.dyn'
ld: warning: orphan section .rela.init.text' from arch/s390/kernel/head64.o' being placed in section `.rela.dyn'
ld: warning: orphan section .rela.rodata.cst8' from arch/s390/kernel/head64.o' being placed in section `.rela.dyn'
Orphan sections are sections that exist in an object file but don't have a corresponding output section in the final executable. ld raises a warning when it identifies such sections.
Eliminate the warning by placing all .rela orphan sections in .rela.dyn and raise an error when size of .rela.dyn is greater than zero. i.e. Dont just neglect orphan sections.
This is similar to adjustment performed in x86, where kernel is built with -fno-PIE.
commit 5354e84598f2 ("x86/build: Add asserts for unwanted sections")
--- arch/s390/kernel/vmlinux.lds.S | 6 ++++++ 1 file changed, 6 insertions(+)
arch/s390/kernel/vmlinux.lds.S +6 -0
@@ -280,6 +280,12 @@ SECTIONS *(.igot .igot.plt) } ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!") +#ifndef CONFIG_PIE_BUILD + .rela.dyn : { + *(.rela.*) *(.rela_*) + } + ASSERT(SIZEOF(.rela.dyn) == 0, "Unexpected run-time relocations (.rela) detected!") +#endif /* Sections to be discarded */ DISCARDS
Signature · 1 line
2.40.1
Re: [PATCH 4/4] s390/kernel: vmlinux.lds.S: handle orphan .rela sections
Quoted 20 lines · Sumanth Korikkar
When kernel is built with
CONFIG_LD_ORPHAN_WARNand -fno-PIE, there are several warnings:ld: warning: orphan section
.rela.iplt' fromarch/s390/kernel/head64.o' being placed in section `.rela.dyn'
ld: warning: orphan section.rela.head.text' fromarch/s390/kernel/head64.o' being placed in section `.rela.dyn'
ld: warning: orphan section.rela.init.text' fromarch/s390/kernel/head64.o' being placed in section `.rela.dyn'
ld: warning: orphan section.rela.rodata.cst8' fromarch/s390/kernel/head64.o' being placed in section `.rela.dyn'Orphan sections are sections that exist in an object file but don't have a corresponding output section in the final executable. ld raises a warning when it identifies such sections.
Eliminate the warning by placing all .rela orphan sections in .rela.dyn and raise an error when size of .rela.dyn is greater than zero. i.e. Dont just neglect orphan sections.
Quoted 8 lines
This is similar to adjustment performed in x86, where kernel is built with -fno-PIE.
commit5354e84598f2("x86/build: Add asserts for unwanted sections")Signed-off-by Sumanth Korikkar <[email protected]>--- arch/s390/kernel/vmlinux.lds.S | 6 ++++++ 1 file changed, 6 insertions(+)
Heiko Carstens
maintainerHi Sumanth,
...
Quoted 8 lines
Josh Poimboeuf (2):
s390: Add relocs tool
s390: Compile relocatable kernel without -fPIESumanth Korikkar (2):
s390/vdso64: filter out munaligned-symbols flag for vdso s390/kernel:vmlinux.lds.S: handle orphan .rela sections
Quoted 15 lines
arch/s390/Kconfig | 15 +- arch/s390/Makefile | 8 +- arch/s390/boot/.gitignore | 1 + arch/s390/boot/Makefile | 14 +- arch/s390/boot/boot.h | 6 + arch/s390/boot/startup.c | 80 +++++- arch/s390/boot/vmlinux.lds.S | 18 ++ arch/s390/include/asm/physmem_info.h | 1 + arch/s390/kernel/vdso64/Makefile | 1 + arch/s390/kernel/vmlinux.lds.S | 15 ++ arch/s390/tools/.gitignore | 1 + arch/s390/tools/Makefile | 5 + arch/s390/tools/relocs.c | 390 +++++++++++++++++++++++++++ 13 files changed, 542 insertions(+), 13 deletions(-) create mode 100644 arch/s390/tools/relocs.c
Could you please resend and base this series on the 'features' branch of the s390 tree:
https://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git/log/?h=features
Please also add your Sign-off to all patches.
Thanks a lot!