[v8,0/6] elf: Allow RPATH/RUNPATH for static-pie

Message ID 20260318193454.2466865-1-adhemerval.zanella@linaro.org (mailing list archive)
Headers
Series elf: Allow RPATH/RUNPATH for static-pie |

Message

Adhemerval Zanella Netto March 18, 2026, 7:34 p.m. UTC
  Although static binaries do not support rpath (since they lack dynamic
sections), adding static-pie support only affects the dlopen function.
It is one less unexpected behavior (where dynamic and static binaries
support and behave differently), and if/when static dlopen support is
removed, this will become a no-op.

The testcase from BZ 33236 triggered a deep issue with an assert in
startup code, which required changes to multiple ABIs to properly fix
(even though the assert itself was removed in the last patch). There
are still other assert usage, although most, if not all, are for
ill-formatted ELF files.

Chagnes from v7:
* Also raise SIGABRT on assert for ld.so.  The hurd __raise_direct
  is no-op that requires a proper implementation (so current semantic
  is kept).

Changes from v6:
* Improve comments.
* Remove unused files.

Changes from v5:
* Move _dl_writev and _dl_mmap to their own TU for i386 to avoid
  I386_USE_SYSENTER redefinition.
* Fixed generic __raise_direct and add a TODO for Hurd.

Changes from 4:
* Rename __raise_nocancel to __raise_direct and remove default
  implementation.
* Simplify _dl_writev.

Changes from v3:
* Added Wilco's suggestion on fallback implementation for ctz/clz.
* Rebased against master.
* Fixed another riscv issues.

Changes from v2:
* Fixed a build for x86_64-linux-gnu-v3.
* Adjust the elf/tst-pie-rpath-static to run correctly when
  --enable-hardcoded-path-in-tests is not used

Changes from v1:
* Change the ctz/clz fallback to simpler algorithms and use a different
  header/macro with a better explanation of its intend.
* Rename __pthread_kill_self to __raise_nostatus.
* Fixed assert also for powerpc-power4 and riscv.

Adhemerval Zanella (6):
  nptl: Add __raise_direct
  Use _dl_writev on __libc_message_impl
  Fix assert during static startup (BZ 33326)
  elf: Allow RPATH/RUNPATH for static-pie (BZ 33326)
  elf: Remove __chk_fail from dl-minimal.c
  elf: Raise SIGABRT for assert within ld.so

Adhemerval Zanella (6):
  nptl: Add __raise_direct
  Use _dl_writev on __libc_message_impl
  Fix assert during static startup (BZ 33326)
  elf: Allow RPATH/RUNPATH for static-pie (BZ 33326)
  elf: Remove __chk_fail from dl-minimal.c
  elf: Raise SIGABRT for assert within ld.so

 assert/Makefile                               |  5 ++
 elf/Makefile                                  | 29 +++++-
 elf/dl-load.c                                 |  2 +-
 elf/dl-minimal.c                              | 90 +++++++++++++------
 elf/dl-reloc-static-pie.c                     |  2 +-
 elf/get-dynamic-info.h                        |  5 +-
 elf/rtld.c                                    |  8 +-
 elf/setup-vdso.h                              |  2 +-
 elf/tst-assert-startup-static.c               | 40 +++++++++
 elf/tst-pie-rpath-mod.c                       | 19 ++++
 elf/tst-pie-rpath-static.c                    | 52 +++++++++++
 include/assert.h                              |  2 +
 include/rtld-assert.h                         | 55 ++++++++++++
 include/rtld-malloc.h                         | 14 ---
 include/signal.h                              |  3 +
 include/stdio.h                               |  2 +
 include/sys/cdefs.h                           |  1 -
 libio/Makefile                                |  5 ++
 nptl/pthread_kill.c                           | 21 ++---
 stdlib/Makefile                               |  5 ++
 string/Makefile                               |  1 +
 .../aarch64/multiarch/dl-symbol-redir-ifunc.h |  1 +
 sysdeps/aarch64/multiarch/memcpy_generic.S    |  4 +
 .../armv7/multiarch/dl-symbol-redir-ifunc.h   | 27 ++++++
 sysdeps/generic/dl-mmap.h                     | 34 +++++++
 {elf => sysdeps/generic}/dl-writev.h          | 18 ++--
 sysdeps/generic/ldsodefs.h                    | 16 ++++
 .../lp64/multiarch/dl-symbol-redir-ifunc.h    |  2 +
 sysdeps/mach/hurd/Makefile                    |  6 ++
 sysdeps/mach/hurd/raise_direct.c              | 29 ++++++
 sysdeps/posix/libc_fatal.c                    | 27 +++---
 sysdeps/posix/raise.c                         |  2 +-
 .../powerpc32/power4/multiarch/Makefile       |  5 ++
 .../be/multiarch/dl-symbol-redir-ifunc.h      | 27 ++++++
 .../le/multiarch/dl-symbol-redir-ifunc.h      |  1 +
 sysdeps/powerpc/powerpc64/multiarch/Makefile  |  1 +
 .../riscv/multiarch/dl-symbol-redir-ifunc.h   |  1 +
 sysdeps/s390/Makefile                         |  5 ++
 .../s390/multiarch/dl-symbol-redir-ifunc.h    |  4 +
 sysdeps/s390/string-bitops.h                  | 27 ++++++
 .../sparcv9/multiarch/dl-symbol-redir-ifunc.h |  3 +
 .../sparc64/multiarch/dl-symbol-redir-ifunc.h |  3 +
 sysdeps/unix/sysv/linux/Makefile              | 16 ++++
 sysdeps/unix/sysv/linux/dl-writev.h           | 12 +--
 sysdeps/unix/sysv/linux/i386/Makefile         | 14 +++
 sysdeps/unix/sysv/linux/i386/dl-mmap.c        | 36 ++++++++
 sysdeps/unix/sysv/linux/i386/dl-mmap.h        | 27 ++++++
 .../linux/{libc_fatal.c => i386/dl-writev.c}  | 28 +++---
 sysdeps/unix/sysv/linux/i386/dl-writev.h      | 15 ++--
 sysdeps/unix/sysv/linux/i386/raise_direct.c   | 26 ++++++
 sysdeps/unix/sysv/linux/raise_direct.c        | 29 ++++++
 .../unix/sysv/linux/riscv/multiarch/Makefile  |  7 ++
 .../x86_64/multiarch/dl-symbol-redir-ifunc.h  | 32 +++++++
 53 files changed, 731 insertions(+), 117 deletions(-)
 create mode 100644 elf/tst-assert-startup-static.c
 create mode 100644 elf/tst-pie-rpath-mod.c
 create mode 100644 elf/tst-pie-rpath-static.c
 create mode 100644 include/rtld-assert.h
 create mode 100644 sysdeps/arm/armv7/multiarch/dl-symbol-redir-ifunc.h
 create mode 100644 sysdeps/generic/dl-mmap.h
 rename {elf => sysdeps/generic}/dl-writev.h (80%)
 create mode 100644 sysdeps/mach/hurd/raise_direct.c
 create mode 100644 sysdeps/powerpc/powerpc64/be/multiarch/dl-symbol-redir-ifunc.h
 create mode 100644 sysdeps/s390/string-bitops.h
 create mode 100644 sysdeps/unix/sysv/linux/i386/dl-mmap.c
 create mode 100644 sysdeps/unix/sysv/linux/i386/dl-mmap.h
 rename sysdeps/unix/sysv/linux/{libc_fatal.c => i386/dl-writev.c} (58%)
 create mode 100644 sysdeps/unix/sysv/linux/i386/raise_direct.c
 create mode 100644 sysdeps/unix/sysv/linux/raise_direct.c