This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] HPPA/IA64 : Don't use broken DL_AUTO_FUNCTION_ADDRESS()
- From: Guy Martin <gmsoft at tuxicoman dot be>
- To: Carlos O'Donell <carlos at redhat dot com>
- Cc: Mike Frysinger <vapier at gentoo dot org>, libc-alpha at sourceware dot org, Andreas Schwab <schwab at linux-m68k dot org>
- Date: Thu, 31 Oct 2013 13:22:58 +0100
- Subject: Re: [PATCH] HPPA/IA64 : Don't use broken DL_AUTO_FUNCTION_ADDRESS()
- Authentication-results: sourceware.org; auth=none
- References: <20131017214754 dot 00555bf3 at dellete> <871u3ina5t dot fsf at igel dot home> <b42704e5527fa00f6e69cacd0d62c19d at tuxicoman dot be> <201310190206 dot 07506 dot vapier at gentoo dot org> <52631FA0 dot 5090403 at redhat dot com> <78728c2956beea68522df0d0e5f8d649 at tuxicoman dot be>
I've reworked the patch to have the macro call the function directly.
This way it is reentrant.
And it's probably more useful if I attach the patch ...
diff --git a/elf/dl-close.c b/elf/dl-close.c
index fe3014c..3735527 100644
--- a/elf/dl-close.c
+++ b/elf/dl-close.c
@@ -274,9 +274,8 @@ _dl_close_worker (struct link_map *map)
/* Next try the old-style destructor. */
if (imap->l_info[DT_FINI] != NULL)
- (*(void (*) (void)) DL_DT_FINI_ADDRESS
- (imap, ((void *) imap->l_addr
- + imap->l_info[DT_FINI]->d_un.d_ptr))) ();
+ DL_DT_FINI (imap, ((void *) imap->l_addr
+ + imap->l_info[DT_FINI]->d_un.d_ptr));
}
#ifdef SHARED
diff --git a/elf/dl-fini.c b/elf/dl-fini.c
index 6b245f0..70fcd44 100644
--- a/elf/dl-fini.c
+++ b/elf/dl-fini.c
@@ -254,7 +254,7 @@ _dl_fini (void)
/* Next try the old-style destructor. */
if (l->l_info[DT_FINI] != NULL)
- ((fini_t) DL_DT_FINI_ADDRESS (l, l->l_addr + l->l_info[DT_FINI]->d_un.d_ptr)) ();
+ DL_DT_FINI(l, l->l_addr + l->l_info[DT_FINI]->d_un.d_ptr);
}
#ifdef SHARED
diff --git a/elf/dl-init.c b/elf/dl-init.c
index a657eb6..02b140d 100644
--- a/elf/dl-init.c
+++ b/elf/dl-init.c
@@ -61,13 +61,7 @@ call_init (struct link_map *l, int argc, char **argv, char **env)
- the others in the DT_INIT_ARRAY.
*/
if (l->l_info[DT_INIT] != NULL)
- {
- init_t init = (init_t) DL_DT_INIT_ADDRESS
- (l, l->l_addr + l->l_info[DT_INIT]->d_un.d_ptr);
-
- /* Call the function. */
- init (argc, argv, env);
- }
+ DL_DT_INIT(l, l->l_addr + 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];
diff --git a/ports/sysdeps/hppa/dl-lookupcfg.h b/ports/sysdeps/hppa/dl-lookupcfg.h
index f3125e5..33afe8e 100644
--- a/ports/sysdeps/hppa/dl-lookupcfg.h
+++ b/ports/sysdeps/hppa/dl-lookupcfg.h
@@ -38,32 +38,34 @@ void _dl_unmap (struct link_map *map);
#define DL_UNMAP(map) _dl_unmap (map)
-#define DL_AUTO_FUNCTION_ADDRESS(map, addr) \
-({ \
- unsigned int fptr[2]; \
- fptr[0] = (unsigned int) (addr); \
- fptr[1] = (map)->l_info[DT_PLTGOT]->d_un.d_ptr; \
- /* Set bit 30 to indicate to $$dyncall that this is a PLABEL. */ \
- (ElfW(Addr))((unsigned int)fptr | 2); \
-})
-
-#define DL_STATIC_FUNCTION_ADDRESS(map, addr) \
-({ \
- static unsigned int fptr[2]; \
- fptr[0] = (unsigned int) (addr); \
- fptr[1] = (map)->l_info[DT_PLTGOT]->d_un.d_ptr; \
- /* Set bit 30 to indicate to $$dyncall that this is a PLABEL. */ \
- (ElfW(Addr))((unsigned int)fptr | 2); \
-})
-
-
-/* The test for "addr & 2" below is to accommodate old binaries which
- violated the ELF ABI by pointing DT_INIT and DT_FINI at a function
- descriptor. */
-#define DL_DT_INIT_ADDRESS(map, addr) \
- ((Elf32_Addr)(addr) & 2 ? (addr) : DL_AUTO_FUNCTION_ADDRESS (map, addr))
-#define DL_DT_FINI_ADDRESS(map, addr) \
- ((Elf32_Addr)(addr) & 2 ? (addr) : DL_AUTO_FUNCTION_ADDRESS (map, addr))
+#define DL_DT_FUNCTION_ADDRESS(map, start, addr) \
+ volatile unsigned int fptr[2]; \
+ /* The test for "start & 2" below is to accommodate old binaries which \
+ violated the ELF ABI by pointing DT_INIT and DT_FINI at a function \
+ descriptor. */ \
+ if ((Elf32_Addr) (start) & 2) \
+ addr = (void*) start; \
+ else \
+ { \
+ fptr[0] = (unsigned int) (start); \
+ fptr[1] = (map)->l_info[DT_PLTGOT]->d_un.d_ptr; \
+ /* Set bit 30 to indicate to $$dyncall that this is a PLABEL. */ \
+ addr = (void*)((unsigned int)fptr | 2); \
+ } \
+
+#define DL_DT_INIT(map, start, argc, argv, env) \
+{ \
+ init_t init; \
+ DL_DT_FUNCTION_ADDRESS(map, start, init) \
+ init (argc, argv, env); \
+}
+
+#define DL_DT_FINI(map, start) \
+{ \
+ fini_t fini; \
+ DL_DT_FUNCTION_ADDRESS(map, start, fini) \
+ fini (); \
+}
/* The type of the return value of fixup/profile_fixup */
#define DL_FIXUP_VALUE_TYPE struct fdesc
diff --git a/ports/sysdeps/hppa/dl-machine.h b/ports/sysdeps/hppa/dl-machine.h
index d2411a6..b8587a5 100644
--- a/ports/sysdeps/hppa/dl-machine.h
+++ b/ports/sysdeps/hppa/dl-machine.h
@@ -490,8 +490,12 @@ asm ( \
#define ELF_MACHINE_NO_REL 1
/* Return the address of the entry point. */
-#define ELF_MACHINE_START_ADDRESS(map, start) \
- DL_STATIC_FUNCTION_ADDRESS (map, start)
+#define ELF_MACHINE_START_ADDRESS(map, start) \
+({ \
+ ElfW(Addr) addr; \
+ static DL_DT_FUNCTION_ADDRESS(map, start, addr) \
+ addr; \
+})
/* We define an initialization functions. This is called very early in
* _dl_sysdep_start. */
diff --git a/ports/sysdeps/ia64/dl-lookupcfg.h b/ports/sysdeps/ia64/dl-lookupcfg.h
index 4da1263..e64f7db 100644
--- a/ports/sysdeps/ia64/dl-lookupcfg.h
+++ b/ports/sysdeps/ia64/dl-lookupcfg.h
@@ -39,24 +39,27 @@ extern void _dl_unmap (struct link_map *map);
#define DL_UNMAP(map) _dl_unmap (map)
-#define DL_AUTO_FUNCTION_ADDRESS(map, addr) \
-({ \
- unsigned long int fptr[2]; \
- fptr[0] = (unsigned long int) (addr); \
- fptr[1] = (map)->l_info[DT_PLTGOT]->d_un.d_ptr; \
- (Elf64_Addr) fptr; \
-})
-
-#define DL_STATIC_FUNCTION_ADDRESS(map, addr) \
-({ \
- static unsigned long int fptr[2]; \
- fptr[0] = (unsigned long int) (addr); \
- fptr[1] = (map)->l_info[DT_PLTGOT]->d_un.d_ptr; \
- (Elf64_Addr) fptr; \
-})
-
-#define DL_DT_INIT_ADDRESS(map, addr) DL_AUTO_FUNCTION_ADDRESS (map, addr)
-#define DL_DT_FINI_ADDRESS(map, addr) DL_AUTO_FUNCTION_ADDRESS (map, addr)
+#define DL_DT_FUNCTION_ADDRESS(map, start, addr) \
+ volatile unsigned int fptr[2]; \
+ fptr[0] = (unsigned int) (start); \
+ fptr[1] = (map)->l_info[DT_PLTGOT]->d_un.d_ptr; \
+ /* Set bit 30 to indicate to $$dyncall that this is a PLABEL. */ \
+ addr = (void*)((unsigned int)fptr | 2); \
+
+#define DL_DT_INIT(map, start, argc, argv, env) \
+{ \
+ init_t init; \
+ DL_DT_FUNCTION_ADDRESS(map, start, init) \
+ init (argc, argv, env); \
+}
+
+#define DL_DT_FINI(map, start) \
+{ \
+ fini_t fini; \
+ DL_DT_FUNCTION_ADDRESS(map, start, fini) \
+ fini (); \
+}
+
/* The type of the return value of fixup/profile_fixup. */
#define DL_FIXUP_VALUE_TYPE struct fdesc
/* Construct a value of type DL_FIXUP_VALUE_TYPE from a code address
diff --git a/ports/sysdeps/ia64/dl-machine.h b/ports/sysdeps/ia64/dl-machine.h
index dd469d7..7b2ad29 100644
--- a/ports/sysdeps/ia64/dl-machine.h
+++ b/ports/sysdeps/ia64/dl-machine.h
@@ -322,7 +322,12 @@ elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)
#define ELF_MACHINE_NO_REL 1
/* Return the address of the entry point. */
-#define ELF_MACHINE_START_ADDRESS(map, start) \
+#define ELF_MACHINE_START_ADDRESS(map, start) \
+({ \
+ ElfW(Addr) addr; \
+ static DL_DT_FUNCTION_ADDRESS(map, start, addr) \
+ addr; \
+})
DL_STATIC_FUNCTION_ADDRESS (map, start)
/* Fixup a PLT entry to bounce directly to the function at VALUE. */
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index e7b0516..5ce3968 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -76,8 +76,8 @@ typedef struct link_map *lookup_t;
# define DL_SYMBOL_ADDRESS(map, ref) \
(void *) (LOOKUP_VALUE_ADDRESS (map) + ref->st_value)
# define DL_LOOKUP_ADDRESS(addr) ((ElfW(Addr)) (addr))
-# define DL_DT_INIT_ADDRESS(map, start) (start)
-# define DL_DT_FINI_ADDRESS(map, start) (start)
+# define DL_DT_INIT(map, start, argc, argv, env) ((init_t) (start)) (argc, argv, env)
+# define DL_DT_FINI(map, start) ((fini_t) (start)) ()
#endif
/* On some architectures dladdr can't use st_size of all symbols this way. */