public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/1] __libc_start_main() now uses auxv to obtain phdr's address [BZ #29864]
@ 2022-12-07 12:16 Yago Gutiérrez
  2022-12-08 17:07 ` Adhemerval Zanella
  2022-12-08 18:54 ` Florian Weimer
  0 siblings, 2 replies; 8+ messages in thread
From: Yago Gutiérrez @ 2022-12-07 12:16 UTC (permalink / raw)
  To: libc-alpha

[-- Attachment #1: Type: text/plain, Size: 339 bytes --]

Yago Gutiérrez (1):
  __libc_start_main() now uses auxv to obtain phdr's address [BZ #29864]

 csu/libc-start.c                        | 34 +++++++++++++------------
 sysdeps/generic/ldsodefs.h              |  3 +++
 sysdeps/unix/sysv/linux/dl-parse_auxv.h |  1 +
 3 files changed, 22 insertions(+), 16 deletions(-)

-- 
2.38.1

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-__libc_start_main-now-uses-auxv-to-obtain-phdr-s-add.patch --]
[-- Type: text/x-patch; name=0001-__libc_start_main-now-uses-auxv-to-obtain-phdr-s-add.patch, Size: 3435 bytes --]

From bf2371ce732194f652719aff4af0f9021f9cbd90 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Yago=20Guti=C3=A9rrez?= <yagogl@protonmail.com>
Date: Wed, 7 Dec 2022 12:49:22 +0100
Subject: [PATCH 1/1] __libc_start_main() now uses auxv to obtain phdr's
 address [BZ #29864]
To: libc-alpha@sourceware.org

---
 csu/libc-start.c                        | 34 +++++++++++++------------
 sysdeps/generic/ldsodefs.h              |  3 +++
 sysdeps/unix/sysv/linux/dl-parse_auxv.h |  1 +
 3 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/csu/libc-start.c b/csu/libc-start.c
index 543560f36c..f6e0fbf60a 100644
--- a/csu/libc-start.c
+++ b/csu/libc-start.c
@@ -262,28 +262,30 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
   }
 #  endif
   _dl_aux_init (auxvec);
-  if (GL(dl_phdr) == NULL)
 # endif
-    {
-      /* Starting from binutils-2.23, the linker will define the
-         magic symbol __ehdr_start to point to our own ELF header
-         if it is visible in a segment that also includes the phdrs.
-         So we can set up _dl_phdr and _dl_phnum even without any
-         information from auxv.  */
 
-      extern const ElfW(Ehdr) __ehdr_start
+  /* Starting from binutils-2.23, the linker will define the
+     magic symbol __ehdr_start to point to our own ELF header
+     if it is visible in a segment that also includes the phdrs.
+     So we can set up _dl_phdr and _dl_phnum even without any
+     information from auxv.  */
+  extern const ElfW(Ehdr) __ehdr_start
 # if BUILD_PIE_DEFAULT
-	__attribute__ ((visibility ("hidden")));
+  __attribute__ ((visibility ("hidden")));
 # else
-	__attribute__ ((weak, visibility ("hidden")));
-      if (&__ehdr_start != NULL)
+  __attribute__ ((weak, visibility ("hidden")));
+  if (&__ehdr_start != NULL)
+# endif
+  {
+# ifdef HAVE_AUX_VECTOR
+    if (GL(dl_phdr) == NULL)
 # endif
-        {
-          assert (__ehdr_start.e_phentsize == sizeof *GL(dl_phdr));
-          GL(dl_phdr) = (const void *) &__ehdr_start + __ehdr_start.e_phoff;
-          GL(dl_phnum) = __ehdr_start.e_phnum;
-        }
+    {
+      assert (__ehdr_start.e_phentsize == sizeof *GL(dl_phdr));
+      GL(dl_phdr) = (const void *) &__ehdr_start + __ehdr_start.e_phoff;
     }
+    GL(dl_phnum) = __ehdr_start.e_phnum;
+  }
 
   __tunables_init (__environ);
 
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index 9dae72b1ed..ccdb42837f 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -395,6 +395,9 @@ struct rtld_global
 
   /* Structure describing the dynamic linker itself.  */
   EXTERN struct link_map _dl_rtld_map;
+
+  EXTERN const ElfW(Phdr)* _dl_phdr;
+
 #ifdef SHARED
   /* Used to store the audit information for the link map of the
      dynamic loader.  */
diff --git a/sysdeps/unix/sysv/linux/dl-parse_auxv.h b/sysdeps/unix/sysv/linux/dl-parse_auxv.h
index bf9374371e..2cc666cbd6 100644
--- a/sysdeps/unix/sysv/linux/dl-parse_auxv.h
+++ b/sysdeps/unix/sysv/linux/dl-parse_auxv.h
@@ -52,6 +52,7 @@ void _dl_parse_auxv (ElfW(auxv_t) *av, dl_parse_auxv_t auxv_values)
   _dl_random = (void *) auxv_values[AT_RANDOM];
   GLRO(dl_minsigstacksize) = auxv_values[AT_MINSIGSTKSZ];
   GLRO(dl_sysinfo_dso) = (void *) auxv_values[AT_SYSINFO_EHDR];
+  GL(dl_phdr) = (void*) auxv_values[AT_PHDR];
 #ifdef NEED_DL_SYSINFO
   if (GLRO(dl_sysinfo_dso) != NULL)
     GLRO(dl_sysinfo) = auxv_values[AT_SYSINFO];
-- 
2.38.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-12-09 13:50 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-07 12:16 [PATCH 0/1] __libc_start_main() now uses auxv to obtain phdr's address [BZ #29864] Yago Gutiérrez
2022-12-08 17:07 ` Adhemerval Zanella
2022-12-08 18:42   ` Florian Weimer
2022-12-08 18:54 ` Florian Weimer
2022-12-08 19:15   ` Adhemerval Zanella Netto
2022-12-09  9:02   ` Yago Gutiérrez
     [not found]     ` <Zh0QVJP4RDa4zdV2FwJIKo4bZwKIHjPNcx_A8J7KIg24u5hoGj9lXet5H4FiLvVNPg4zAErbNQkuNnUnSBkhEXiLAnBjs5SUFKtN-x9fR5U=@protonmail.com>
2022-12-09 13:13       ` Florian Weimer
2022-12-09 13:50         ` Adhemerval Zanella Netto

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).