summaryrefslogtreecommitdiff
path: root/libpthread/nptl/sysdeps/generic
diff options
context:
space:
mode:
authorlinted <linted@users.noreply.github.com>2022-07-23 16:25:41 -0400
committerWaldemar Brodkorb <wbx@openadk.org>2022-07-26 09:56:03 +0200
commit2c58afdb3ae6f900583cf7264cba6ab8a797e3e2 (patch)
treeabb641e31fcab71a4e78905fd0124ca8b9a25eae /libpthread/nptl/sysdeps/generic
parent01961b12bc71d6eb4d9bda3632d73bb6764b8e85 (diff)
Added support for creation of Static Position-Independent Executables (PIE) on i386, x86_64, and arm.
This patch adds the generation of rcrt1.o which is used by gcc when compiling with the --static-pie flag. rcrt1.o differs from crt1.o and Scrt1.o in that it the executable has a dynamic section but no relocations have been performed prior to _start being called. crt1.o assumes there to be no dynamic relocations, and Scrt1.o has all relocations performed prior to execution by lsdo. The new reloc_static_pie function handles parsing the dynamic section, and performing the relocations in a architecture agnostic method. It also sets _dl_load_base which is used when initalizing TLS to ensure loading from the proper location. This allows for easier porting of static-pie support to additional architectures as only modifications to crt1.S to find the load address are required. Signed-off-by: linted <linted@users.noreply.github.com>
Diffstat (limited to 'libpthread/nptl/sysdeps/generic')
-rw-r--r--libpthread/nptl/sysdeps/generic/Makefile.in4
-rw-r--r--libpthread/nptl/sysdeps/generic/libc-tls.c4
2 files changed, 8 insertions, 0 deletions
diff --git a/libpthread/nptl/sysdeps/generic/Makefile.in b/libpthread/nptl/sysdeps/generic/Makefile.in
index eb656ee17..a5ba9bbe8 100644
--- a/libpthread/nptl/sysdeps/generic/Makefile.in
+++ b/libpthread/nptl/sysdeps/generic/Makefile.in
@@ -13,6 +13,10 @@ subdirs += libpthread/nptl/sysdeps/generic
libpthread_generic_DIR := $(top_srcdir)libpthread/nptl/sysdeps/generic
libpthread_generic_OUT := $(top_builddir)libpthread/nptl/sysdeps/generic
+ifeq ($(STATIC_PIE),y)
+CFLAGS-libc-tls.c := -DSTATIC_PIE
+endif
+
libpthread_generic_libc_a_CSRC = libc-tls.c
libpthread_generic_libc_a_COBJ = $(patsubst %.c,$(libpthread_generic_OUT)/%.o,$(libpthread_generic_libc_a_CSRC))
libpthread_generic_libc_a_OBJS = $(libpthread_generic_libc_a_COBJ)
diff --git a/libpthread/nptl/sysdeps/generic/libc-tls.c b/libpthread/nptl/sysdeps/generic/libc-tls.c
index d746c9a38..0c8c558d0 100644
--- a/libpthread/nptl/sysdeps/generic/libc-tls.c
+++ b/libpthread/nptl/sysdeps/generic/libc-tls.c
@@ -142,6 +142,10 @@ __libc_setup_tls (size_t tcbsize, size_t tcbalign)
initimage = (void *) &__tdata_start;
#else
initimage = (void *) phdr->p_vaddr;
+#if !defined(SHARED) && defined(STATIC_PIE)
+ extern ElfW(Addr) _dl_load_base;
+ initimage += _dl_load_base;
+#endif
#endif
align = phdr->p_align;
if (phdr->p_align > max_align)