diff --git a/csu/libc-start.c b/csu/libc-start.c index 5d9c3675fa..315ad2ea6f 100644 --- a/csu/libc-start.c +++ b/csu/libc-start.c @@ -141,7 +141,7 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL), __libc_multiple_libcs = &_dl_starting_up && !_dl_starting_up; #ifndef SHARED - _dl_relocate_static_pie (); + int relocs_done = _dl_relocate_static_pie (); char **ev = &argv[argc + 1]; @@ -191,7 +191,8 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL), ARCH_INIT_CPU_FEATURES (); /* Perform IREL{,A} relocations. */ - ARCH_SETUP_IREL (); + if (!relocs_done) + ARCH_SETUP_IREL (); /* The stack guard goes into the TCB, so initialize it early. */ ARCH_SETUP_TLS (); @@ -199,7 +200,8 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL), /* In some architectures, IREL{,A} relocations happen after TLS setup in order to let IFUNC resolvers benefit from TCB information, e.g. powerpc's hwcap and platform fields available in the TCB. */ - ARCH_APPLY_IREL (); + if (!relocs_done) + ARCH_APPLY_IREL (); /* Set up the stack checker's canary. */ uintptr_t stack_chk_guard = _dl_setup_stack_chk_guard (_dl_random); diff --git a/csu/static-reloc.c b/csu/static-reloc.c index 38bbb0ff6a..eedb26f8b5 100644 --- a/csu/static-reloc.c +++ b/csu/static-reloc.c @@ -19,8 +19,9 @@ #if ENABLE_STATIC_PIE #include -void +int _dl_relocate_static_pie (void) { + return 0; } #endif diff --git a/elf/dl-reloc-static-pie.c b/elf/dl-reloc-static-pie.c index 95aee984e8..e057149155 100644 --- a/elf/dl-reloc-static-pie.c +++ b/elf/dl-reloc-static-pie.c @@ -23,7 +23,7 @@ /* Relocate static executable with PIE. */ -void +int _dl_relocate_static_pie (void) { struct link_map *main_map = _dl_get_dl_main_map (); @@ -64,5 +64,7 @@ _dl_relocate_static_pie (void) with the run-time address of the r_debug structure */ main_map->l_info[DT_DEBUG]->d_un.d_ptr = (ElfW(Addr)) r; # endif + + return 1; } #endif diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index a7f6b82da6..2b00982547 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -1062,13 +1062,13 @@ void __libc_setup_tls (void); # if ENABLE_STATIC_PIE /* Relocate static executable with PIE. */ -extern void _dl_relocate_static_pie (void) attribute_hidden; +extern int _dl_relocate_static_pie (void) attribute_hidden; /* Get a pointer to _dl_main_map. */ extern struct link_map * _dl_get_dl_main_map (void) __attribute__ ((visibility ("hidden"))); # else -# define _dl_relocate_static_pie() +# define _dl_relocate_static_pie() 0 # endif #endif