public inbox for glibc-cvs@sourceware.org help / color / mirror / Atom feed
From: Fangrui Song <maskray@sourceware.org> To: glibc-cvs@sourceware.org Subject: [glibc/maskray/lld] csu: Skip ARCH_SETUP_IREL if _dl_relocate_static_pie applied IRELATIVE relocations Date: Mon, 1 Feb 2021 18:01:14 +0000 (GMT) [thread overview] Message-ID: <20210201180114.50DBA3945C06@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=c67127a88540f6de4b92370158b5da61bec23f4f commit c67127a88540f6de4b92370158b5da61bec23f4f Author: Siva Chandra Reddy <sivachandra@google.com> Date: Fri Jan 29 10:42:50 2021 -0800 csu: Skip ARCH_SETUP_IREL if _dl_relocate_static_pie applied IRELATIVE relocations For static pie, _dl_relocate_static_pie applies IRELATIVE relocations so ARCH_SETUP_IREL should not apply relocations again. LLD defines __rela_iplt_start/__rela_iplt_end regardless of -no-pie or -pie, so in an LLD linked static pie, ARCH_SETUP_IREL would otherwise apply the relocations in the range of [__rela_iplt_start, __rela_iplt_end). Co-authored-by: Fangrui Song <maskray@google.com> Diff: --- csu/libc-start.c | 8 +++++--- csu/static-reloc.c | 3 ++- elf/dl-reloc-static-pie.c | 4 +++- sysdeps/generic/ldsodefs.h | 4 ++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/csu/libc-start.c b/csu/libc-start.c index feb0d7ce11..44d9d875d2 100644 --- a/csu/libc-start.c +++ b/csu/libc-start.c @@ -200,10 +200,11 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL), /* Do static pie self relocation after tunables and cpu features are setup for ifunc resolvers. Before this point relocations must be avoided. */ - _dl_relocate_static_pie (); + int irel_applied = _dl_relocate_static_pie (); /* Perform IREL{,A} relocations. */ - ARCH_SETUP_IREL (); + if (!irel_applied) + ARCH_SETUP_IREL (); /* The stack guard goes into the TCB, so initialize it early. */ ARCH_SETUP_TLS (); @@ -211,7 +212,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 (!irel_applied) + 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 972c524f28..9046d9f6a3 100644 --- a/csu/static-reloc.c +++ b/csu/static-reloc.c @@ -19,8 +19,9 @@ #if ENABLE_STATIC_PIE #include <ldsodefs.h> -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 d5bd2f31e9..b707ef4bf1 100644 --- a/elf/dl-reloc-static-pie.c +++ b/elf/dl-reloc-static-pie.c @@ -25,7 +25,7 @@ /* Relocate static executable with PIE. */ -void +int _dl_relocate_static_pie (void) { struct link_map *main_map = _dl_get_dl_main_map (); @@ -66,5 +66,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 aab7245e93..a0b1e3a34e 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -1148,13 +1148,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
next reply other threads:[~2021-02-01 18:01 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-02-01 18:01 Fangrui Song [this message] -- strict thread matches above, loose matches on Subject: below -- 2021-02-01 17:23 Fangrui Song 2021-01-29 18:44 Fangrui Song
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210201180114.50DBA3945C06@sourceware.org \ --to=maskray@sourceware.org \ --cc=glibc-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).