Hello again!
Since we have the steps pretty well fleshed out, I figured it was about
time to update the porting docs to describe how to add support for
static-pie. Here is a patch with some notes about the steps I usually take
when updating another architecture to support it.
--
From afaa287e28e8e120bf55a7de368253f445a6deea Mon Sep 17 00:00:00 2001
From: linted <linted(a)users.noreply.github.com>
Date: Mon, 26 Sep 2022 13:40:50 -0400
Subject: [PATCH] Added some documentation on how to add static-pie support
to
the porting guide
Signed-off-by: linted <linted(a)users.noreply.github.com>
---
docs/porting.txt | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/docs/porting.txt b/docs/porting.txt
index 380645801..31c188ae1 100644
--- a/docs/porting.txt
+++ b/docs/porting.txt
@@ -12,6 +12,8 @@ you are hacking on.
the shared library loader work requires you first have basic
architecture
support working. Thus you should add ARCH_HAS_NO_SHARED and
ARCH_HAS_NO_LDSO to Config.ARCH's TARGET_ARCH
+- When static pie support is added this TARGET_arch can be appended to the
+ list in extra/Configs/Config.in
====================
=== libc sysdeps ===
@@ -56,6 +58,15 @@ you are hacking on.
usually these are written in assembler, but you may be able to cheat and
write them in C ... see other ports for more information
+- Once static and pie executables are stable, static-pie support can be
+ added by modifying crt1.S to calculate the address that the kernel
loaded
+ the main elf. Once the elf load address is found, call reloc_static_pie
to
+ perform all the dynamic relocations normally handled by ldso. This new
+ code should be placed at the begining of _start and surrounded by defines
+ so that it is only compiled into rcrt1.o and not the static or shared
+ versions. This is usually done by using the special L_rcrt1 preprocessor
+ define. i386 and x86_64 have good reference implementations.
+
====================
=== ldso sysdeps ===
====================
--
2.34.1
From: Pavel Kozlov <pavel.kozlov(a)synopsys.com>
Hello,
The first patch allows to use general ARC TLS macro for ARCv3 and allows
to build tests for ARCv3. The second patch contains fix for the TLS_GD
macro.
This patch series is associated with uclibc-ng ARCv3 patches:
Link: https://mailman.openadk.org/mailman3/hyperkitty/list/devel@uclibc-ng.org/th…
Pavel Kozlov (1):
arc: fix TLS_GD macro, bad clobber list
Sergey Matyukevich (1):
arc: use existing tls macros for ARCv3 32-bit CPUs
test/tls/tls-macros-arc.h | 14 ++++++--------
test/tls/tls-macros.h | 2 +-
2 files changed, 7 insertions(+), 9 deletions(-)
base-commit: 728e1e0ea5adf1bd9b479e4edc456b637e26c031
--
2.25.1
From: Pavel Kozlov <pavel.kozlov(a)synopsys.com>
Hello,
this patch series adds base support for ARCv3 32-bit architecture,
adds new machine identifer and handle changes in ISA and ARC toolchain.
New ARCv3 ISA includes both 64-bit and 32-bit CPU family.
This patch series adds support for 32-bit ARCv3 HS5x processors.
Sergey Matyukevich (4):
arc: minor cleanup for ARCv2
ldso: arc: add compiler option check
arc: add asm macros
arc: add support for ARCv3 32-bit processors
include/elf.h | 3 +-
ldso/ldso/Makefile.in | 3 +-
ldso/ldso/arc/dl-sysdep.h | 3 ++
ldso/ldso/arc/resolve.S | 45 +++++++++++-----------
libc/sysdeps/linux/arc/asm.h | 52 ++++++++++++++++++++++++++
libc/sysdeps/linux/arc/bits/syscalls.h | 4 +-
libc/sysdeps/linux/arc/crt1.S | 4 +-
utils/ldd.c | 7 +++-
8 files changed, 93 insertions(+), 28 deletions(-)
create mode 100644 libc/sysdeps/linux/arc/asm.h
base-commit: d46709504efa46e5b9b52739a48ab61b39fd4971
--
2.25.1
Hello,
this series does a couple cleanups in the ldso, static PIE code and
xtensa code and enables static PIE support for the xtensa architecture.
Changes v1->v2:
- clean up PERFORM_BOOTSTRAP_GOT condition in the ldso
- drop patch that adds PERFORM_BOOTSTRAP_GOT to reloc_static_pie
Max Filippov (5):
static pie: fix building static PDE
ldso: clean up PERFORM_BOOTSTRAP_GOT ifdeferry
xtensa: ldso: make GOT protection adjustment conditional
xtensa: drop ARCH_NEEDS_BOOTSTRAP_RELOCS
xtensa: add static pie support
extra/Configs/Config.in | 4 +++-
ldso/ldso/dl-startup.c | 3 ---
ldso/ldso/xtensa/dl-startup.h | 15 ++++--------
ldso/ldso/xtensa/dl-sysdep.h | 3 ---
libc/misc/internals/reloc_static_pie.c | 6 ++---
libc/sysdeps/linux/xtensa/crt1.S | 27 ++++++++++++++++++++++
libpthread/nptl/sysdeps/generic/libc-tls.c | 7 ++++--
7 files changed, 42 insertions(+), 23 deletions(-)
--
2.30.2
Hello,
this series does a couple cleanups in the static PIE code and xtensa
code and enables static PIE support for the xtensa architecture.
Max Filippov (5):
static pie: fix building static PDE
static pie: replicate PERFORM_BOOTSTRAP_GOT conditions from
dl-startup.c
xtensa: make GOT protection adjustment conditional
xtensa: drop ARCH_NEEDS_BOOTSTRAP_RELOCS
xtensa: add static pie support
extra/Configs/Config.in | 4 +++-
ldso/ldso/xtensa/dl-startup.h | 19 ++++++++++++---
ldso/ldso/xtensa/dl-sysdep.h | 3 ---
libc/misc/internals/reloc_static_pie.c | 9 +++++---
libc/sysdeps/linux/xtensa/crt1.S | 27 ++++++++++++++++++++++
libpthread/nptl/sysdeps/generic/libc-tls.c | 7 ++++--
6 files changed, 57 insertions(+), 12 deletions(-)
--
2.30.2
Static PIE ELFs may be loaded on noMMU linux platforms with FDPIC
support, but they don't have adjustable brk, and thus cannot allocate
memory for the TLS. Use mmap instead of sbrk to allocate initial TLS
memory when building with static PIE support for noMMU.
Signed-off-by: Max Filippov <jcmvbkbc(a)gmail.com>
---
Change v1->v2:
- fix typo and add clarification in comment
libpthread/nptl/sysdeps/generic/libc-tls.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/libpthread/nptl/sysdeps/generic/libc-tls.c b/libpthread/nptl/sysdeps/generic/libc-tls.c
index d9c09fdd6667..7cfe9ac1a85c 100644
--- a/libpthread/nptl/sysdeps/generic/libc-tls.c
+++ b/libpthread/nptl/sysdeps/generic/libc-tls.c
@@ -169,10 +169,13 @@ __libc_setup_tls (size_t tcbsize, size_t tcbalign)
for FDPIC MMU-less platforms:
fs/binfmt_elf_fdpic.c: fix brk area overlap with stack on NOMMU
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/fs/b…
+ Loading static PIE ELFs on noMMU is possible since the linux kernel commit
+ 1bde925d2354 ("fs/binfmt_elf_fdpic.c: provide NOMMU loader for regular ELF binaries")
+ and it is subject to the same brk restriction.
*/
# if defined(TLS_TCB_AT_TP)
tcb_offset = roundup (memsz + GL(dl_tls_static_size), tcbalign);
-# if defined(__FDPIC__)
+# if defined(__FDPIC__) || (!defined(__ARCH_USE_MMU__) && defined(STATIC_PIE))
tlsblock = mmap (NULL, tcb_offset + tcbsize + max_align,
PROT_READ|PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
# else
@@ -180,7 +183,7 @@ __libc_setup_tls (size_t tcbsize, size_t tcbalign)
# endif
# elif defined(TLS_DTV_AT_TP)
tcb_offset = roundup (tcbsize, align ?: 1);
-# if defined(__FDPIC__)
+# if defined(__FDPIC__) || (!defined(__ARCH_USE_MMU__) && defined(STATIC_PIE))
tlsblock = mmap (NULL, tcb_offset + memsz + max_align + TLS_PRE_TCB_SIZE + GL(dl_tls_static_size),
PROT_READ|PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
# else
--
2.30.2
Static PIE ELFs may be loaded on noMMU linux platforms with FDPIC
support, but they don't have adjustable brk, and thus cannot allocate
memory for the TLS. Use mmap instead of sbrk to allocate initial TLS
memory when building with static PIE support for noMMU.
Signed-off-by: Max Filippov <jcmvbkbc(a)gmail.com>
---
libpthread/nptl/sysdeps/generic/libc-tls.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/libpthread/nptl/sysdeps/generic/libc-tls.c b/libpthread/nptl/sysdeps/generic/libc-tls.c
index d9c09fdd6667..374ba2a48620 100644
--- a/libpthread/nptl/sysdeps/generic/libc-tls.c
+++ b/libpthread/nptl/sysdeps/generic/libc-tls.c
@@ -169,10 +169,13 @@ __libc_setup_tls (size_t tcbsize, size_t tcbalign)
for FDPIC MMU-less platforms:
fs/binfmt_elf_fdpic.c: fix brk area overlap with stack on NOMMU
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/fs/b…
+ Loading static PIE ELFs is possible since linux kernel commit
+ 1bde925d2354 ("fs/binfmt_elf_fdpic.c: provide NOMMU loader for regular ELF binaries")
+ and it is subject to the same brk restrixtion.
*/
# if defined(TLS_TCB_AT_TP)
tcb_offset = roundup (memsz + GL(dl_tls_static_size), tcbalign);
-# if defined(__FDPIC__)
+# if defined(__FDPIC__) || (!defined(__ARCH_USE_MMU__) && defined(STATIC_PIE))
tlsblock = mmap (NULL, tcb_offset + tcbsize + max_align,
PROT_READ|PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
# else
@@ -180,7 +183,7 @@ __libc_setup_tls (size_t tcbsize, size_t tcbalign)
# endif
# elif defined(TLS_DTV_AT_TP)
tcb_offset = roundup (tcbsize, align ?: 1);
-# if defined(__FDPIC__)
+# if defined(__FDPIC__) || (!defined(__ARCH_USE_MMU__) && defined(STATIC_PIE))
tlsblock = mmap (NULL, tcb_offset + memsz + max_align + TLS_PRE_TCB_SIZE + GL(dl_tls_static_size),
PROT_READ|PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
# else
--
2.30.2