Skip to content

s390: compile relocatable kernel with/without fPIE

Sumanth Korikkar linux-s390 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest4 patches 9 repliesIn review
  2. v14 patches 5 repliesSuperseded

Changes in v2 from the cover letter

* Add Acked-by
* Add my signed-off by:
* Rebase it to features branch

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4s390/vdso64: filter out munaligned-symbols flag for vdsoarch/s390/kernel/vdso64/Makefile+1 -00 replies
2/4s390: Add relocs toolarch/s390/tools/.gitignore arch/s390/tools/Makefile arch/s390/tools/relocs.c+396 -01 reply
3/4s390: Compile relocatable kernel without -fPIEarch/s390/Kconfig arch/s390/Makefile arch/s390/boot/.gitignore +6 more+139 -130 replies
4/4s390/kernel: vmlinux.lds.S: handle orphan .rela sectionsarch/s390/kernel/vmlinux.lds.S+6 -00 replies

Reviews trailers per patch

All 4 patches have a Reviewed-by or Acked-by.

PatchVasily GorbikSumanth Korikkar
1/4A-b
2/4A-b
3/4A-b T-b
4/4A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/4] 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.

v2:
* Add Acked-by
* Add my signed-off by:
* Rebase it to features branch

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