public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Alan Modra <amodra@sourceware.org>
To: glibc-cvs@sourceware.org
Subject: [glibc] powerpc: Relocate stinfo->main
Date: Mon, 11 Apr 2022 01:30:40 +0000 (GMT)	[thread overview]
Message-ID: <20220411013040.9B7403855BA6@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=1a85970f41ea1e5abe6da2298a5e8fedcea26b70

commit 1a85970f41ea1e5abe6da2298a5e8fedcea26b70
Author: Alan Modra <amodra@gmail.com>
Date:   Mon Jan 24 10:25:49 2022 +1030

    powerpc: Relocate stinfo->main
    
    start_addresses in sysdeps/powerpc/powerpc64/start.S is historical
    baggage that should disappear.  Until someone does that, relocating
    stinfo->main by hand is one solution to the fact that the field may be
    unrelocated at the time it is accessed.  This is similar to what is
    done for dynamic tags via the D_PTR macro.  stinfo->init and
    stinfo->fini are zero in both powerpc64/start.S and powerpc32/start.S,
    so make it a little more obvious they are unused by passing NULLs to
    LIBC_START_MAIN.  The makefile change is needed to pick up
    elf/dl-static-tls.h from dl-machine.h.
    
    Reviewed-by: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>

Diff:
---
 sysdeps/unix/sysv/linux/powerpc/Makefile     |  6 ++++++
 sysdeps/unix/sysv/linux/powerpc/libc-start.c | 15 +++++++++++++--
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/powerpc/Makefile b/sysdeps/unix/sysv/linux/powerpc/Makefile
index fc7c29c695..93783cae00 100644
--- a/sysdeps/unix/sysv/linux/powerpc/Makefile
+++ b/sysdeps/unix/sysv/linux/powerpc/Makefile
@@ -27,3 +27,9 @@ tests += $(tests-static)
 tests += test-gettimebasefreq
 tests += test-powerpc-linux-sysconf
 endif
+
+ifeq ($(subdir),csu)
+# to relocate stinfo->main
+CPPFLAGS-libc-start.o += -I../elf
+CPPFLAGS-libc-start.op += -I../elf
+endif
diff --git a/sysdeps/unix/sysv/linux/powerpc/libc-start.c b/sysdeps/unix/sysv/linux/powerpc/libc-start.c
index bb97d16145..8413c84783 100644
--- a/sysdeps/unix/sysv/linux/powerpc/libc-start.c
+++ b/sysdeps/unix/sysv/linux/powerpc/libc-start.c
@@ -23,6 +23,10 @@
 #ifndef SHARED
 #include <hwcapinfo.h>
 #endif
+#if ENABLE_STATIC_PIE && !defined SHARED
+/* For elf_machine_load_address.  */
+#include <dl-machine.h>
+#endif
 
 /* The main work is done in the generic function.  */
 #define LIBC_START_MAIN generic_start_main
@@ -95,8 +99,15 @@ __libc_start_main_impl (int argc, char **argv,
   __tcb_parse_hwcap_and_convert_at_platform ();
 #endif
 
-  return generic_start_main (stinfo->main, argc, argv, auxvec,
-			     stinfo->init, stinfo->fini, rtld_fini,
+  void *stmain = stinfo->main;
+#if ENABLE_STATIC_PIE && !defined SHARED
+  struct link_map *map = _dl_get_dl_main_map ();
+  if (!map->l_relocated)
+    stmain = (char *) stmain + elf_machine_load_address ();
+#endif
+
+  return generic_start_main (stmain, argc, argv, auxvec,
+			     NULL, NULL, rtld_fini,
 			     stack_on_entry);
 }
 DEFINE_LIBC_START_MAIN_VERSION


                 reply	other threads:[~2022-04-11  1:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220411013040.9B7403855BA6@sourceware.org \
    --to=amodra@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: link
Be 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).