Skip to content

RFC nolibc: Add static-pie support

Daniel Palmer lkml 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 RFC Latest10 patches 11 repliesIn review
  2. v1 RFC9 patches 9 repliesSuperseded

Changes in v2 from the cover letter

- This is still RFC quality
- I have gotten a few more archs to work (not crash in nolibc-test) so I have added them to show the that the arch specific parts are pretty small.
- This should now only add this extra code if NOLIBC_WANT_RELOC is defined, which happens automatically if you compile with -fpie. Should address Willy's concern with the size blowing up for even binaries that don't need this.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/10elf: Add relocation types used by nolibcinclude/uapi/linux/elf-r.h include/uapi/linux/elf.h+28 -02 replies
2/10tools/nolibc: crt: Split _start_c() into stack-only and normal partstools/include/nolibc/compiler.h tools/include/nolibc/crt.h+38 -253 replies
3/10tools/nolibc: Add basic ELF self-relocation support for static PIEtools/include/nolibc/Makefile tools/include/nolibc/crt.h tools/include/nolibc/reloc.h+232 -01 reply
4/10tools/nolibc: m68k: Add relocation supporttools/include/nolibc/arch-m68k.h+26 -11 reply
5/10tools/nolibc: x86: Add relocation supporttools/include/nolibc/arch-x86.h+53 -01 reply
6/10tools/nolibc: riscv: Add relocation supporttools/include/nolibc/arch-riscv.h+26 -00 replies
7/10tools/nolibc: arm: Add relocation supporttools/include/nolibc/arch-arm.h+25 -00 replies
8/10tools/nolibc: sh: Add relocation supporttools/include/nolibc/arch-sh.h+24 -00 replies
9/10tools/nolibc: ppc: Add relocation supporttools/include/nolibc/arch-powerpc.h+24 -00 replies
10/10selftests/nolibc: Add option for building with -static-pietools/testing/selftests/nolibc/Makefile tools/testing/selftests/nolibc/Makefile.nolibc tools/testing/selftests/nolibc/run-tests.sh+14 -61 reply

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [RFC PATCH v2 00/10] nolibc: Add static-pie support

v2:

- This is still RFC quality
- I have gotten a few more archs to work (not crash in nolibc-test) so I have added them to show the that the arch specific parts are pretty small.
- This should now only add this extra code if NOLIBC_WANT_RELOC is defined, which happens automatically if you compile with -fpie. Should address Willy's concern with the size blowing up for even binaries that don't need this.

Size difference on ppc64 is massive, I guess PIC code is big there.

static:

  $ file nolibc-test
nolibc-test: ELF 64-bit MSB executable, 64-bit PowerPC or cisco 7500, Power ELF V1 ABI, version 1 (SYSV), statically linked, not stripped
$ size nolibc-test
   text    data     bss     dec     hex filename
  59560    3240     104   62904    f5b8 nolibc-test

static pie:

  $ file nolibc-test
nolibc-test: ELF 64-bit MSB pie executable, 64-bit PowerPC or cisco 7500, Power ELF V1 ABI, version 1 (SYSV), static-pie linked, with debug_info, not stripped
  $ size nolibc-test
   text    data     bss     dec     hex filename
  67801    3656     104   71561   11789 nolibc-test

- Each of the archs checks that the relocations they need (just the one at the moment) is defined before defining the relocation defines. So this shouldn't break with older UAPI headers.

- I think maybe you might want to set NOLIBC_WANT_RELOC even if __pie__ is not defined, maybe for testing? So I didn't make it _NOLIBC_WANT_RELOC.

- I was worried some archs didn't work because calling the relocation functions was causing things like accessing the stack canary before it was accessible. So I added __inline__ to all of the relocation functions to force them to get inlined into _start_c(). This might be too much. checkpatch certainly hates it.

- I think I addressed most of Thomas' code style comments, prefixing etc. Maybe added some new problems :)

- I cleaned up the REL/RELA differences a bit more so the lines of code has dropped a bit in reloc.h.

- I fixed working out where the dynamic section is, this fixed SuperH and PPC. I suspect I can get all of the others except maybe mips working now.

- new elf UAPI header for the relocation types is still wrong, script to run the self-tests is still wonky.

Thanks in advance,

Daniel

v1: https://lore.kernel.org/lkml/[email protected]/
v0: https://lore.kernel.org/lkml/[email protected]/

Daniel Palmer (10):
elf: Add relocation types used by nolibc
tools/nolibc: crt: Split _start_c() into stack-only and normal parts tools/nolibc: Add basic ELF self-relocation support for static PIE tools/nolibc: m68k: Add relocation support
tools/nolibc: x86: Add relocation support
tools/nolibc: riscv: Add relocation support
tools/nolibc: arm: Add relocation support
tools/nolibc: sh: Add relocation support
tools/nolibc: ppc: Add relocation support selftests/nolibc: Add option for building with -static-pie

 include/uapi/linux/elf-r.h                    |  27 +++
 include/uapi/linux/elf.h                      |   1 +
 tools/include/nolibc/Makefile                 |   1 +
 tools/include/nolibc/arch-arm.h               |  25 ++
 tools/include/nolibc/arch-m68k.h              |  27 ++-
 tools/include/nolibc/arch-powerpc.h           |  24 ++
 tools/include/nolibc/arch-riscv.h             |  26 ++
 tools/include/nolibc/arch-sh.h                |  24 ++
 tools/include/nolibc/arch-x86.h               |  53 +++++
 tools/include/nolibc/compiler.h               |   6 +
 tools/include/nolibc/crt.h                    |  62 +++--
 tools/include/nolibc/reloc.h                  | 224 ++++++++++++++++++
 tools/testing/selftests/nolibc/Makefile       |   2 +-
 .../testing/selftests/nolibc/Makefile.nolibc  |   8 +-
 tools/testing/selftests/nolibc/run-tests.sh   |  10 +-
 15 files changed, 489 insertions(+), 31 deletions(-)
 create mode 100644 include/uapi/linux/elf-r.h
 create mode 100644 tools/include/nolibc/reloc.h
Signature · 1 line
2.51.0