public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/arm/morello/main] cheri: elf: elfptr_t fixes for preinit/init/fini array
@ 2022-08-05 19:34 Szabolcs Nagy
  0 siblings, 0 replies; 4+ messages in thread
From: Szabolcs Nagy @ 2022-08-05 19:34 UTC (permalink / raw)
  To: glibc-cvs

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

commit d63bc8be874f42090f3a7a51441221863b83f149
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date:   Thu Apr 7 18:40:25 2022 +0100

    cheri: elf: elfptr_t fixes for preinit/init/fini array
    
    According to the ELF spec:
    
     "Each element of this array is a pointer to a function to be executed
      by the dynamic linker."
    
     "Note that the address of a function need not be the same as a pointer
      to a function as defined by the processor supplement."
    
    so these should be accessed via uintptr_t type instead of ElfW(Addr).

Diff:
---
 csu/libc-start.c |  4 ++--
 elf/dl-close.c   |  6 +++---
 elf/dl-fini.c    |  6 +++---
 elf/dl-init.c    | 12 ++++++------
 4 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/csu/libc-start.c b/csu/libc-start.c
index 543560f36c..2726fbdbec 100644
--- a/csu/libc-start.c
+++ b/csu/libc-start.c
@@ -139,8 +139,8 @@ call_init (int argc, char **argv, char **env)
   if (init_array != NULL)
     {
       unsigned int jm
-	= l->l_info[DT_INIT_ARRAYSZ]->d_un.d_val / sizeof (ElfW(Addr));
-      ElfW(Addr) *addrs = (void *) (init_array->d_un.d_ptr + l->l_addr);
+	= l->l_info[DT_INIT_ARRAYSZ]->d_un.d_val / sizeof (elfptr_t);
+      elfptr_t *addrs = (void *) (init_array->d_un.d_ptr + l->l_addr);
       for (unsigned int j = 0; j < jm; ++j)
 	((dl_init_t) addrs[j]) (argc, argv, env);
     }
diff --git a/elf/dl-close.c b/elf/dl-close.c
index bcd6e206e9..a20cf8cc36 100644
--- a/elf/dl-close.c
+++ b/elf/dl-close.c
@@ -119,11 +119,11 @@ call_destructors (void *closure)
 
   if (map->l_info[DT_FINI_ARRAY] != NULL)
     {
-      ElfW(Addr) *array =
-	(ElfW(Addr) *) (map->l_addr
+      elfptr_t *array =
+	(elfptr_t *) (map->l_addr
 			+ map->l_info[DT_FINI_ARRAY]->d_un.d_ptr);
       unsigned int sz = (map->l_info[DT_FINI_ARRAYSZ]->d_un.d_val
-			 / sizeof (ElfW(Addr)));
+			 / sizeof (elfptr_t));
 
       while (sz-- > 0)
 	((fini_t) array[sz]) ();
diff --git a/elf/dl-fini.c b/elf/dl-fini.c
index 030b1fcbcd..040bda28b2 100644
--- a/elf/dl-fini.c
+++ b/elf/dl-fini.c
@@ -133,11 +133,11 @@ _dl_fini (void)
 		      /* First see whether an array is given.  */
 		      if (l->l_info[DT_FINI_ARRAY] != NULL)
 			{
-			  ElfW(Addr) *array =
-			    (ElfW(Addr) *) (l->l_addr
+			  elfptr_t *array =
+			    (elfptr_t *) (l->l_addr
 					    + l->l_info[DT_FINI_ARRAY]->d_un.d_ptr);
 			  unsigned int i = (l->l_info[DT_FINI_ARRAYSZ]->d_un.d_val
-					    / sizeof (ElfW(Addr)));
+					    / sizeof (elfptr_t));
 			  while (i-- > 0)
 			    ((fini_t) array[i]) ();
 			}
diff --git a/elf/dl-init.c b/elf/dl-init.c
index deefeb099a..4c8aaae7e0 100644
--- a/elf/dl-init.c
+++ b/elf/dl-init.c
@@ -61,11 +61,11 @@ call_init (struct link_map *l, int argc, char **argv, char **env)
     {
       unsigned int j;
       unsigned int jm;
-      ElfW(Addr) *addrs;
+      elfptr_t *addrs;
 
-      jm = l->l_info[DT_INIT_ARRAYSZ]->d_un.d_val / sizeof (ElfW(Addr));
+      jm = l->l_info[DT_INIT_ARRAYSZ]->d_un.d_val / sizeof (elfptr_t);
 
-      addrs = (ElfW(Addr) *) (init_array->d_un.d_ptr + l->l_addr);
+      addrs = (elfptr_t *) (init_array->d_un.d_ptr + l->l_addr);
       for (j = 0; j < jm; ++j)
 	((dl_init_t) addrs[j]) (argc, argv, env);
     }
@@ -88,16 +88,16 @@ _dl_init (struct link_map *main_map, int argc, char **argv, char **env)
   /* Don't do anything if there is no preinit array.  */
   if (__builtin_expect (preinit_array != NULL, 0)
       && preinit_array_size != NULL
-      && (i = preinit_array_size->d_un.d_val / sizeof (ElfW(Addr))) > 0)
+      && (i = preinit_array_size->d_un.d_val / sizeof (elfptr_t)) > 0)
     {
-      ElfW(Addr) *addrs;
+      elfptr_t *addrs;
       unsigned int cnt;
 
       if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_IMPCALLS))
 	_dl_debug_printf ("\ncalling preinit: %s\n\n",
 			  DSO_FILENAME (main_map->l_name));
 
-      addrs = (ElfW(Addr) *) (preinit_array->d_un.d_ptr + main_map->l_addr);
+      addrs = (elfptr_t *) (preinit_array->d_un.d_ptr + main_map->l_addr);
       for (cnt = 0; cnt < i; ++cnt)
 	((dl_init_t) addrs[cnt]) (argc, argv, env);
     }


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

* [glibc/arm/morello/main] cheri: elf: elfptr_t fixes for preinit/init/fini array
@ 2022-11-23 14:45 Szabolcs Nagy
  0 siblings, 0 replies; 4+ messages in thread
From: Szabolcs Nagy @ 2022-11-23 14:45 UTC (permalink / raw)
  To: glibc-cvs

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

commit a5750ba400ec9a2561ac58700fc4ee76491b3984
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date:   Thu Apr 7 18:40:25 2022 +0100

    cheri: elf: elfptr_t fixes for preinit/init/fini array
    
    According to the ELF spec:
    
     "Each element of this array is a pointer to a function to be executed
      by the dynamic linker."
    
     "Note that the address of a function need not be the same as a pointer
      to a function as defined by the processor supplement."
    
    so these should be accessed via uintptr_t type instead of ElfW(Addr) and
    the pointers are derived from the RX pointer of the elf module.

Diff:
---
 csu/libc-start.c |  6 +++---
 elf/dl-close.c   | 10 ++++------
 elf/dl-fini.c    |  9 ++++-----
 elf/dl-init.c    | 15 ++++++++-------
 4 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/csu/libc-start.c b/csu/libc-start.c
index 09235865bd..d71fbec3fe 100644
--- a/csu/libc-start.c
+++ b/csu/libc-start.c
@@ -132,15 +132,15 @@ call_init (int argc, char **argv, char **env)
      the same file.  */
 
   if (ELF_INITFINI && l->l_info[DT_INIT] != NULL)
-    DL_CALL_DT_INIT(l, l->l_addr + l->l_info[DT_INIT]->d_un.d_ptr,
+    DL_CALL_DT_INIT(l, dl_rx_ptr (l, l->l_info[DT_INIT]->d_un.d_ptr),
 		    argc, argv, env);
 
   ElfW(Dyn) *init_array = l->l_info[DT_INIT_ARRAY];
   if (init_array != NULL)
     {
       unsigned int jm
-	= l->l_info[DT_INIT_ARRAYSZ]->d_un.d_val / sizeof (ElfW(Addr));
-      ElfW(Addr) *addrs = (void *) (init_array->d_un.d_ptr + l->l_addr);
+	= l->l_info[DT_INIT_ARRAYSZ]->d_un.d_val / sizeof (elfptr_t);
+      elfptr_t *addrs = (void *) dl_rx_ptr (l, init_array->d_un.d_ptr);
       for (unsigned int j = 0; j < jm; ++j)
 	((dl_init_t) addrs[j]) (argc, argv, env);
     }
diff --git a/elf/dl-close.c b/elf/dl-close.c
index bcd6e206e9..5a45062f09 100644
--- a/elf/dl-close.c
+++ b/elf/dl-close.c
@@ -119,11 +119,10 @@ call_destructors (void *closure)
 
   if (map->l_info[DT_FINI_ARRAY] != NULL)
     {
-      ElfW(Addr) *array =
-	(ElfW(Addr) *) (map->l_addr
-			+ map->l_info[DT_FINI_ARRAY]->d_un.d_ptr);
+      elfptr_t *array =
+	(elfptr_t *) dl_rx_ptr (map, map->l_info[DT_FINI_ARRAY]->d_un.d_ptr);
       unsigned int sz = (map->l_info[DT_FINI_ARRAYSZ]->d_un.d_val
-			 / sizeof (ElfW(Addr)));
+			 / sizeof (elfptr_t));
 
       while (sz-- > 0)
 	((fini_t) array[sz]) ();
@@ -131,8 +130,7 @@ call_destructors (void *closure)
 
   /* Next try the old-style destructor.  */
   if (map->l_info[DT_FINI] != NULL)
-    DL_CALL_DT_FINI (map, ((void *) map->l_addr
-			   + map->l_info[DT_FINI]->d_un.d_ptr));
+    DL_CALL_DT_FINI (map, dl_rx_ptr (map, map->l_info[DT_FINI]->d_un.d_ptr));
 }
 
 void
diff --git a/elf/dl-fini.c b/elf/dl-fini.c
index 030b1fcbcd..18135b2191 100644
--- a/elf/dl-fini.c
+++ b/elf/dl-fini.c
@@ -133,11 +133,10 @@ _dl_fini (void)
 		      /* First see whether an array is given.  */
 		      if (l->l_info[DT_FINI_ARRAY] != NULL)
 			{
-			  ElfW(Addr) *array =
-			    (ElfW(Addr) *) (l->l_addr
-					    + l->l_info[DT_FINI_ARRAY]->d_un.d_ptr);
+			  ElfW(Addr) v = l->l_info[DT_FINI_ARRAY]->d_un.d_ptr;
+			  elfptr_t *array = (elfptr_t *) dl_rx_ptr (l, v);
 			  unsigned int i = (l->l_info[DT_FINI_ARRAYSZ]->d_un.d_val
-					    / sizeof (ElfW(Addr)));
+					    / sizeof (elfptr_t));
 			  while (i-- > 0)
 			    ((fini_t) array[i]) ();
 			}
@@ -145,7 +144,7 @@ _dl_fini (void)
 		      /* Next try the old-style destructor.  */
 		      if (ELF_INITFINI && l->l_info[DT_FINI] != NULL)
 			DL_CALL_DT_FINI
-			  (l, l->l_addr + l->l_info[DT_FINI]->d_un.d_ptr);
+			  (l, dl_rx_ptr (l, l->l_info[DT_FINI]->d_un.d_ptr));
 		    }
 
 #ifdef SHARED
diff --git a/elf/dl-init.c b/elf/dl-init.c
index deefeb099a..7fb2af6a3f 100644
--- a/elf/dl-init.c
+++ b/elf/dl-init.c
@@ -53,7 +53,8 @@ call_init (struct link_map *l, int argc, char **argv, char **env)
      - the others in the DT_INIT_ARRAY.
   */
   if (ELF_INITFINI && l->l_info[DT_INIT] != NULL)
-    DL_CALL_DT_INIT(l, l->l_addr + l->l_info[DT_INIT]->d_un.d_ptr, argc, argv, env);
+    DL_CALL_DT_INIT(l, dl_rx_ptr (l, l->l_info[DT_INIT]->d_un.d_ptr),
+		    argc, argv, env);
 
   /* Next see whether there is an array with initialization functions.  */
   ElfW(Dyn) *init_array = l->l_info[DT_INIT_ARRAY];
@@ -61,11 +62,11 @@ call_init (struct link_map *l, int argc, char **argv, char **env)
     {
       unsigned int j;
       unsigned int jm;
-      ElfW(Addr) *addrs;
+      elfptr_t *addrs;
 
-      jm = l->l_info[DT_INIT_ARRAYSZ]->d_un.d_val / sizeof (ElfW(Addr));
+      jm = l->l_info[DT_INIT_ARRAYSZ]->d_un.d_val / sizeof (elfptr_t);
 
-      addrs = (ElfW(Addr) *) (init_array->d_un.d_ptr + l->l_addr);
+      addrs = (elfptr_t *) dl_rx_ptr (l, init_array->d_un.d_ptr);
       for (j = 0; j < jm; ++j)
 	((dl_init_t) addrs[j]) (argc, argv, env);
     }
@@ -88,16 +89,16 @@ _dl_init (struct link_map *main_map, int argc, char **argv, char **env)
   /* Don't do anything if there is no preinit array.  */
   if (__builtin_expect (preinit_array != NULL, 0)
       && preinit_array_size != NULL
-      && (i = preinit_array_size->d_un.d_val / sizeof (ElfW(Addr))) > 0)
+      && (i = preinit_array_size->d_un.d_val / sizeof (elfptr_t)) > 0)
     {
-      ElfW(Addr) *addrs;
+      elfptr_t *addrs;
       unsigned int cnt;
 
       if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_IMPCALLS))
 	_dl_debug_printf ("\ncalling preinit: %s\n\n",
 			  DSO_FILENAME (main_map->l_name));
 
-      addrs = (ElfW(Addr) *) (preinit_array->d_un.d_ptr + main_map->l_addr);
+      addrs = (elfptr_t *) dl_rx_ptr (main_map, preinit_array->d_un.d_ptr);
       for (cnt = 0; cnt < i; ++cnt)
 	((dl_init_t) addrs[cnt]) (argc, argv, env);
     }

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

* [glibc/arm/morello/main] cheri: elf: elfptr_t fixes for preinit/init/fini array
@ 2022-10-27 13:55 Szabolcs Nagy
  0 siblings, 0 replies; 4+ messages in thread
From: Szabolcs Nagy @ 2022-10-27 13:55 UTC (permalink / raw)
  To: glibc-cvs

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

commit aec15be8ed6e218532f383dd61398125df061de8
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date:   Thu Apr 7 18:40:25 2022 +0100

    cheri: elf: elfptr_t fixes for preinit/init/fini array
    
    According to the ELF spec:
    
     "Each element of this array is a pointer to a function to be executed
      by the dynamic linker."
    
     "Note that the address of a function need not be the same as a pointer
      to a function as defined by the processor supplement."
    
    so these should be accessed via uintptr_t type instead of ElfW(Addr) and
    the pointers are derived from the RX pointer of the elf module.

Diff:
---
 csu/libc-start.c |  6 +++---
 elf/dl-close.c   | 10 ++++------
 elf/dl-fini.c    |  9 ++++-----
 elf/dl-init.c    | 15 ++++++++-------
 4 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/csu/libc-start.c b/csu/libc-start.c
index 09235865bd..d71fbec3fe 100644
--- a/csu/libc-start.c
+++ b/csu/libc-start.c
@@ -132,15 +132,15 @@ call_init (int argc, char **argv, char **env)
      the same file.  */
 
   if (ELF_INITFINI && l->l_info[DT_INIT] != NULL)
-    DL_CALL_DT_INIT(l, l->l_addr + l->l_info[DT_INIT]->d_un.d_ptr,
+    DL_CALL_DT_INIT(l, dl_rx_ptr (l, l->l_info[DT_INIT]->d_un.d_ptr),
 		    argc, argv, env);
 
   ElfW(Dyn) *init_array = l->l_info[DT_INIT_ARRAY];
   if (init_array != NULL)
     {
       unsigned int jm
-	= l->l_info[DT_INIT_ARRAYSZ]->d_un.d_val / sizeof (ElfW(Addr));
-      ElfW(Addr) *addrs = (void *) (init_array->d_un.d_ptr + l->l_addr);
+	= l->l_info[DT_INIT_ARRAYSZ]->d_un.d_val / sizeof (elfptr_t);
+      elfptr_t *addrs = (void *) dl_rx_ptr (l, init_array->d_un.d_ptr);
       for (unsigned int j = 0; j < jm; ++j)
 	((dl_init_t) addrs[j]) (argc, argv, env);
     }
diff --git a/elf/dl-close.c b/elf/dl-close.c
index bcd6e206e9..5a45062f09 100644
--- a/elf/dl-close.c
+++ b/elf/dl-close.c
@@ -119,11 +119,10 @@ call_destructors (void *closure)
 
   if (map->l_info[DT_FINI_ARRAY] != NULL)
     {
-      ElfW(Addr) *array =
-	(ElfW(Addr) *) (map->l_addr
-			+ map->l_info[DT_FINI_ARRAY]->d_un.d_ptr);
+      elfptr_t *array =
+	(elfptr_t *) dl_rx_ptr (map, map->l_info[DT_FINI_ARRAY]->d_un.d_ptr);
       unsigned int sz = (map->l_info[DT_FINI_ARRAYSZ]->d_un.d_val
-			 / sizeof (ElfW(Addr)));
+			 / sizeof (elfptr_t));
 
       while (sz-- > 0)
 	((fini_t) array[sz]) ();
@@ -131,8 +130,7 @@ call_destructors (void *closure)
 
   /* Next try the old-style destructor.  */
   if (map->l_info[DT_FINI] != NULL)
-    DL_CALL_DT_FINI (map, ((void *) map->l_addr
-			   + map->l_info[DT_FINI]->d_un.d_ptr));
+    DL_CALL_DT_FINI (map, dl_rx_ptr (map, map->l_info[DT_FINI]->d_un.d_ptr));
 }
 
 void
diff --git a/elf/dl-fini.c b/elf/dl-fini.c
index 030b1fcbcd..18135b2191 100644
--- a/elf/dl-fini.c
+++ b/elf/dl-fini.c
@@ -133,11 +133,10 @@ _dl_fini (void)
 		      /* First see whether an array is given.  */
 		      if (l->l_info[DT_FINI_ARRAY] != NULL)
 			{
-			  ElfW(Addr) *array =
-			    (ElfW(Addr) *) (l->l_addr
-					    + l->l_info[DT_FINI_ARRAY]->d_un.d_ptr);
+			  ElfW(Addr) v = l->l_info[DT_FINI_ARRAY]->d_un.d_ptr;
+			  elfptr_t *array = (elfptr_t *) dl_rx_ptr (l, v);
 			  unsigned int i = (l->l_info[DT_FINI_ARRAYSZ]->d_un.d_val
-					    / sizeof (ElfW(Addr)));
+					    / sizeof (elfptr_t));
 			  while (i-- > 0)
 			    ((fini_t) array[i]) ();
 			}
@@ -145,7 +144,7 @@ _dl_fini (void)
 		      /* Next try the old-style destructor.  */
 		      if (ELF_INITFINI && l->l_info[DT_FINI] != NULL)
 			DL_CALL_DT_FINI
-			  (l, l->l_addr + l->l_info[DT_FINI]->d_un.d_ptr);
+			  (l, dl_rx_ptr (l, l->l_info[DT_FINI]->d_un.d_ptr));
 		    }
 
 #ifdef SHARED
diff --git a/elf/dl-init.c b/elf/dl-init.c
index deefeb099a..7fb2af6a3f 100644
--- a/elf/dl-init.c
+++ b/elf/dl-init.c
@@ -53,7 +53,8 @@ call_init (struct link_map *l, int argc, char **argv, char **env)
      - the others in the DT_INIT_ARRAY.
   */
   if (ELF_INITFINI && l->l_info[DT_INIT] != NULL)
-    DL_CALL_DT_INIT(l, l->l_addr + l->l_info[DT_INIT]->d_un.d_ptr, argc, argv, env);
+    DL_CALL_DT_INIT(l, dl_rx_ptr (l, l->l_info[DT_INIT]->d_un.d_ptr),
+		    argc, argv, env);
 
   /* Next see whether there is an array with initialization functions.  */
   ElfW(Dyn) *init_array = l->l_info[DT_INIT_ARRAY];
@@ -61,11 +62,11 @@ call_init (struct link_map *l, int argc, char **argv, char **env)
     {
       unsigned int j;
       unsigned int jm;
-      ElfW(Addr) *addrs;
+      elfptr_t *addrs;
 
-      jm = l->l_info[DT_INIT_ARRAYSZ]->d_un.d_val / sizeof (ElfW(Addr));
+      jm = l->l_info[DT_INIT_ARRAYSZ]->d_un.d_val / sizeof (elfptr_t);
 
-      addrs = (ElfW(Addr) *) (init_array->d_un.d_ptr + l->l_addr);
+      addrs = (elfptr_t *) dl_rx_ptr (l, init_array->d_un.d_ptr);
       for (j = 0; j < jm; ++j)
 	((dl_init_t) addrs[j]) (argc, argv, env);
     }
@@ -88,16 +89,16 @@ _dl_init (struct link_map *main_map, int argc, char **argv, char **env)
   /* Don't do anything if there is no preinit array.  */
   if (__builtin_expect (preinit_array != NULL, 0)
       && preinit_array_size != NULL
-      && (i = preinit_array_size->d_un.d_val / sizeof (ElfW(Addr))) > 0)
+      && (i = preinit_array_size->d_un.d_val / sizeof (elfptr_t)) > 0)
     {
-      ElfW(Addr) *addrs;
+      elfptr_t *addrs;
       unsigned int cnt;
 
       if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_IMPCALLS))
 	_dl_debug_printf ("\ncalling preinit: %s\n\n",
 			  DSO_FILENAME (main_map->l_name));
 
-      addrs = (ElfW(Addr) *) (preinit_array->d_un.d_ptr + main_map->l_addr);
+      addrs = (elfptr_t *) dl_rx_ptr (main_map, preinit_array->d_un.d_ptr);
       for (cnt = 0; cnt < i; ++cnt)
 	((dl_init_t) addrs[cnt]) (argc, argv, env);
     }

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

* [glibc/arm/morello/main] cheri: elf: elfptr_t fixes for preinit/init/fini array
@ 2022-10-26 15:16 Szabolcs Nagy
  0 siblings, 0 replies; 4+ messages in thread
From: Szabolcs Nagy @ 2022-10-26 15:16 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=0fd1c9d51bc67c23f184eb6a39848e53c0847e92

commit 0fd1c9d51bc67c23f184eb6a39848e53c0847e92
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date:   Thu Apr 7 18:40:25 2022 +0100

    cheri: elf: elfptr_t fixes for preinit/init/fini array
    
    According to the ELF spec:
    
     "Each element of this array is a pointer to a function to be executed
      by the dynamic linker."
    
     "Note that the address of a function need not be the same as a pointer
      to a function as defined by the processor supplement."
    
    so these should be accessed via uintptr_t type instead of ElfW(Addr) and
    the pointers are derived from the RX pointer of the elf module.

Diff:
---
 csu/libc-start.c |  6 +++---
 elf/dl-close.c   | 10 ++++------
 elf/dl-fini.c    |  9 ++++-----
 elf/dl-init.c    | 15 ++++++++-------
 4 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/csu/libc-start.c b/csu/libc-start.c
index 09235865bd..d71fbec3fe 100644
--- a/csu/libc-start.c
+++ b/csu/libc-start.c
@@ -132,15 +132,15 @@ call_init (int argc, char **argv, char **env)
      the same file.  */
 
   if (ELF_INITFINI && l->l_info[DT_INIT] != NULL)
-    DL_CALL_DT_INIT(l, l->l_addr + l->l_info[DT_INIT]->d_un.d_ptr,
+    DL_CALL_DT_INIT(l, dl_rx_ptr (l, l->l_info[DT_INIT]->d_un.d_ptr),
 		    argc, argv, env);
 
   ElfW(Dyn) *init_array = l->l_info[DT_INIT_ARRAY];
   if (init_array != NULL)
     {
       unsigned int jm
-	= l->l_info[DT_INIT_ARRAYSZ]->d_un.d_val / sizeof (ElfW(Addr));
-      ElfW(Addr) *addrs = (void *) (init_array->d_un.d_ptr + l->l_addr);
+	= l->l_info[DT_INIT_ARRAYSZ]->d_un.d_val / sizeof (elfptr_t);
+      elfptr_t *addrs = (void *) dl_rx_ptr (l, init_array->d_un.d_ptr);
       for (unsigned int j = 0; j < jm; ++j)
 	((dl_init_t) addrs[j]) (argc, argv, env);
     }
diff --git a/elf/dl-close.c b/elf/dl-close.c
index bcd6e206e9..5a45062f09 100644
--- a/elf/dl-close.c
+++ b/elf/dl-close.c
@@ -119,11 +119,10 @@ call_destructors (void *closure)
 
   if (map->l_info[DT_FINI_ARRAY] != NULL)
     {
-      ElfW(Addr) *array =
-	(ElfW(Addr) *) (map->l_addr
-			+ map->l_info[DT_FINI_ARRAY]->d_un.d_ptr);
+      elfptr_t *array =
+	(elfptr_t *) dl_rx_ptr (map, map->l_info[DT_FINI_ARRAY]->d_un.d_ptr);
       unsigned int sz = (map->l_info[DT_FINI_ARRAYSZ]->d_un.d_val
-			 / sizeof (ElfW(Addr)));
+			 / sizeof (elfptr_t));
 
       while (sz-- > 0)
 	((fini_t) array[sz]) ();
@@ -131,8 +130,7 @@ call_destructors (void *closure)
 
   /* Next try the old-style destructor.  */
   if (map->l_info[DT_FINI] != NULL)
-    DL_CALL_DT_FINI (map, ((void *) map->l_addr
-			   + map->l_info[DT_FINI]->d_un.d_ptr));
+    DL_CALL_DT_FINI (map, dl_rx_ptr (map, map->l_info[DT_FINI]->d_un.d_ptr));
 }
 
 void
diff --git a/elf/dl-fini.c b/elf/dl-fini.c
index 030b1fcbcd..18135b2191 100644
--- a/elf/dl-fini.c
+++ b/elf/dl-fini.c
@@ -133,11 +133,10 @@ _dl_fini (void)
 		      /* First see whether an array is given.  */
 		      if (l->l_info[DT_FINI_ARRAY] != NULL)
 			{
-			  ElfW(Addr) *array =
-			    (ElfW(Addr) *) (l->l_addr
-					    + l->l_info[DT_FINI_ARRAY]->d_un.d_ptr);
+			  ElfW(Addr) v = l->l_info[DT_FINI_ARRAY]->d_un.d_ptr;
+			  elfptr_t *array = (elfptr_t *) dl_rx_ptr (l, v);
 			  unsigned int i = (l->l_info[DT_FINI_ARRAYSZ]->d_un.d_val
-					    / sizeof (ElfW(Addr)));
+					    / sizeof (elfptr_t));
 			  while (i-- > 0)
 			    ((fini_t) array[i]) ();
 			}
@@ -145,7 +144,7 @@ _dl_fini (void)
 		      /* Next try the old-style destructor.  */
 		      if (ELF_INITFINI && l->l_info[DT_FINI] != NULL)
 			DL_CALL_DT_FINI
-			  (l, l->l_addr + l->l_info[DT_FINI]->d_un.d_ptr);
+			  (l, dl_rx_ptr (l, l->l_info[DT_FINI]->d_un.d_ptr));
 		    }
 
 #ifdef SHARED
diff --git a/elf/dl-init.c b/elf/dl-init.c
index deefeb099a..7fb2af6a3f 100644
--- a/elf/dl-init.c
+++ b/elf/dl-init.c
@@ -53,7 +53,8 @@ call_init (struct link_map *l, int argc, char **argv, char **env)
      - the others in the DT_INIT_ARRAY.
   */
   if (ELF_INITFINI && l->l_info[DT_INIT] != NULL)
-    DL_CALL_DT_INIT(l, l->l_addr + l->l_info[DT_INIT]->d_un.d_ptr, argc, argv, env);
+    DL_CALL_DT_INIT(l, dl_rx_ptr (l, l->l_info[DT_INIT]->d_un.d_ptr),
+		    argc, argv, env);
 
   /* Next see whether there is an array with initialization functions.  */
   ElfW(Dyn) *init_array = l->l_info[DT_INIT_ARRAY];
@@ -61,11 +62,11 @@ call_init (struct link_map *l, int argc, char **argv, char **env)
     {
       unsigned int j;
       unsigned int jm;
-      ElfW(Addr) *addrs;
+      elfptr_t *addrs;
 
-      jm = l->l_info[DT_INIT_ARRAYSZ]->d_un.d_val / sizeof (ElfW(Addr));
+      jm = l->l_info[DT_INIT_ARRAYSZ]->d_un.d_val / sizeof (elfptr_t);
 
-      addrs = (ElfW(Addr) *) (init_array->d_un.d_ptr + l->l_addr);
+      addrs = (elfptr_t *) dl_rx_ptr (l, init_array->d_un.d_ptr);
       for (j = 0; j < jm; ++j)
 	((dl_init_t) addrs[j]) (argc, argv, env);
     }
@@ -88,16 +89,16 @@ _dl_init (struct link_map *main_map, int argc, char **argv, char **env)
   /* Don't do anything if there is no preinit array.  */
   if (__builtin_expect (preinit_array != NULL, 0)
       && preinit_array_size != NULL
-      && (i = preinit_array_size->d_un.d_val / sizeof (ElfW(Addr))) > 0)
+      && (i = preinit_array_size->d_un.d_val / sizeof (elfptr_t)) > 0)
     {
-      ElfW(Addr) *addrs;
+      elfptr_t *addrs;
       unsigned int cnt;
 
       if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_IMPCALLS))
 	_dl_debug_printf ("\ncalling preinit: %s\n\n",
 			  DSO_FILENAME (main_map->l_name));
 
-      addrs = (ElfW(Addr) *) (preinit_array->d_un.d_ptr + main_map->l_addr);
+      addrs = (elfptr_t *) dl_rx_ptr (main_map, preinit_array->d_un.d_ptr);
       for (cnt = 0; cnt < i; ++cnt)
 	((dl_init_t) addrs[cnt]) (argc, argv, env);
     }

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

end of thread, other threads:[~2022-11-23 14:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-05 19:34 [glibc/arm/morello/main] cheri: elf: elfptr_t fixes for preinit/init/fini array Szabolcs Nagy
2022-10-26 15:16 Szabolcs Nagy
2022-10-27 13:55 Szabolcs Nagy
2022-11-23 14:45 Szabolcs Nagy

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