From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1944) id 3FF17394741A; Tue, 19 Jan 2021 15:59:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3FF17394741A Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Szabolcs Nagy To: glibc-cvs@sourceware.org Subject: [glibc/nsz/bug27072] csu: Move static pie self relocation later [BZ #27072] X-Act-Checkin: glibc X-Git-Author: Szabolcs Nagy X-Git-Refname: refs/heads/nsz/bug27072 X-Git-Oldrev: a14c2bc43c0aadc8b5edb11072a9cc298c0ba225 X-Git-Newrev: 6b468d65b6c580acd82218b88b4150729c8921b2 Message-Id: <20210119155929.3FF17394741A@sourceware.org> Date: Tue, 19 Jan 2021 15:59:29 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Jan 2021 15:59:29 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=6b468d65b6c580acd82218b88b4150729c8921b2 commit 6b468d65b6c580acd82218b88b4150729c8921b2 Author: Szabolcs Nagy Date: Wed Jan 6 14:28:02 2021 +0000 csu: Move static pie self relocation later [BZ #27072] IFUNC resolvers may depend on tunables and cpu feature setup so move static pie self relocation after those. It is hard to guarantee that the ealy startup code does not rely on relocations so this is a bit fragile. It would be more robust to handle RELATIVE relocs early and only IRELATIVE relocs later, but the current relocation processing code cannot do that. The early startup code up to relocation processing includes _dl_aux_init (auxvec); __libc_init_secure (); __tunables_init (__environ); ARCH_INIT_CPU_FEATURES (); _dl_relocate_static_pie (); These are simple enough that RELATIVE relocs can be avoided. The following steps include ARCH_SETUP_IREL (); ARCH_SETUP_TLS (); ARCH_APPLY_IREL (); __ehdr_start may require RELATIVE relocation so it was moved after relocation processing but before tls setup which needs the program headers. This also means that targets that need ifunc resolution to be after tls setup cannot support static pie without splitting RELATIVE and IRELATIVE processing (or removing some of the dependencies between these steps). Fixes bug 27072. Diff: --- csu/libc-start.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/csu/libc-start.c b/csu/libc-start.c index 1e90dcb0a7..3239125202 100644 --- a/csu/libc-start.c +++ b/csu/libc-start.c @@ -146,8 +146,6 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL), int result; #ifndef SHARED - _dl_relocate_static_pie (); - char **ev = &argv[argc + 1]; __environ = ev; @@ -169,6 +167,24 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL), } # endif _dl_aux_init (auxvec); +# endif + + /* Initialize very early so that tunables can use it. */ + __libc_init_secure (); + + __tunables_init (__environ); + + ARCH_INIT_CPU_FEATURES (); + + /* 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 (); + + /* Perform IREL{,A} relocations. */ + ARCH_SETUP_IREL (); + +# ifdef HAVE_AUX_VECTOR if (GL(dl_phdr) == NULL) # endif { @@ -188,16 +204,6 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL), } } - /* Initialize very early so that tunables can use it. */ - __libc_init_secure (); - - __tunables_init (__environ); - - ARCH_INIT_CPU_FEATURES (); - - /* Perform IREL{,A} relocations. */ - ARCH_SETUP_IREL (); - /* The stack guard goes into the TCB, so initialize it early. */ ARCH_SETUP_TLS ();