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@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/bi... + 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
Hi,
applied and pushed,
best regards Waldemar
Max Filippov wrote,
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@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/bi...
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
devel mailing list -- devel@uclibc-ng.org To unsubscribe send an email to devel-leave@uclibc-ng.org