Subject: Re: dlopen() from libc is broken
To: Jason Thorpe <thorpej@wasabisystems.com>
From: Jason Thorpe <thorpej@wasabisystems.com>
List: tech-toolchain
Date: 07/17/2004 20:12:44
--Apple-Mail-6-144014463
Content-Type: multipart/mixed; boundary=Apple-Mail-5-144014454
--Apple-Mail-5-144014454
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
format=flowed
On Jul 17, 2004, at 5:13 PM, Jason Thorpe wrote:
> What should we do about it?
Well, the attached patch fixes it. It leaves __dlopen(), etc. as the
internal names used by libc, but makes those also weak, the strong
names being ___dlopen(), etc. This allows ld.elf_so to self-resolve
those symbols (they must be weak).
Then, we make __dlopen(), etc. as strong aliases for dlopen(), etc. in
ld.elf_so, and add those symbols to its self-resolve list.
This is the most straight-forward way I could think of to fix this, so
if anyone has a better suggestion, I'd like to check it in.
-- Jason R. Thorpe <thorpej@wasabisystems.com>
--Apple-Mail-5-144014454
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
x-unix-mode=0644;
name="dlfcn-patch.txt"
Content-Disposition: attachment;
filename=dlfcn-patch.txt
Index: lib/libc/dlfcn/dlfcn_elf.c
===================================================================
RCS file: /cvsroot/src/lib/libc/dlfcn/dlfcn_elf.c,v
retrieving revision 1.4
diff -u -r1.4 dlfcn_elf.c
--- lib/libc/dlfcn/dlfcn_elf.c 12 Aug 2003 09:18:43 -0000 1.4
+++ lib/libc/dlfcn/dlfcn_elf.c 18 Jul 2004 02:41:47 -0000
@@ -32,15 +32,33 @@
#include "namespace.h"
+#undef dlopen
+#undef dlclose
+#undef dlsym
+#undef dlerror
+#undef dladdr
+
+#define dlopen ___dlopen
+#define dlclose ___dlclose
+#define dlsym ___dlsym
+#define dlerror ___dlerror
+#define dladdr ___dladdr
+
#define ELFSIZE ARCH_ELFSIZE
#include "rtld.h"
#ifdef __weak_alias
-__weak_alias(dlopen,__dlopen)
-__weak_alias(dlclose,__dlclose)
-__weak_alias(dlsym,__dlsym)
-__weak_alias(dlerror,__dlerror)
-__weak_alias(dladdr,__dladdr)
+__weak_alias(dlopen,___dlopen)
+__weak_alias(dlclose,___dlclose)
+__weak_alias(dlsym,___dlsym)
+__weak_alias(dlerror,___dlerror)
+__weak_alias(dladdr,___dladdr)
+
+__weak_alias(__dlopen,___dlopen)
+__weak_alias(__dlclose,___dlclose)
+__weak_alias(__dlsym,___dlsym)
+__weak_alias(__dlerror,___dlerror)
+__weak_alias(__dladdr,___dladdr)
#endif
/*
Index: libexec/ld.elf_so/rtld.c
===================================================================
RCS file: /cvsroot/src/libexec/ld.elf_so/rtld.c,v
retrieving revision 1.105
diff -u -r1.105 rtld.c
--- libexec/ld.elf_so/rtld.c 17 May 2004 13:16:02 -0000 1.105
+++ libexec/ld.elf_so/rtld.c 18 Jul 2004 02:41:50 -0000
@@ -580,6 +580,7 @@
}
}
+__strong_alias(__dlclose,dlclose)
int
dlclose(void *handle)
{
@@ -600,6 +601,7 @@
return 0;
}
+__strong_alias(__dlerror,dlerror)
char *
dlerror(void)
{
@@ -609,6 +611,7 @@
return msg;
}
+__strong_alias(__dlopen,dlopen)
void *
dlopen(const char *name, int mode)
{
@@ -666,6 +669,7 @@
return(NULL);
}
+__strong_alias(__dlsym,dlsym)
void *
dlsym(void *handle, const char *name)
{
@@ -752,6 +756,7 @@
return NULL;
}
+__strong_alias(__dladdr,dladdr)
int
dladdr(const void *addr, Dl_info *info)
{
Index: libexec/ld.elf_so/rtld.h
===================================================================
RCS file: /cvsroot/src/libexec/ld.elf_so/rtld.h,v
retrieving revision 1.71
diff -u -r1.71 rtld.h
--- libexec/ld.elf_so/rtld.h 5 Jul 2004 11:50:07 -0000 1.71
+++ libexec/ld.elf_so/rtld.h 18 Jul 2004 02:41:51 -0000
@@ -219,6 +219,13 @@
int dlclose(void *);
int dladdr(const void *, Dl_info *);
+/* Strong aliases for the former, matching the weak names used by libc. */
+char *__dlerror(void);
+void *__dlopen(const char *, int);
+void *__dlsym(void *, const char *);
+int __dlclose(void *);
+int __dladdr(const void *, Dl_info *);
+
void _rtld_error(const char *, ...)
__attribute__((__format__(__printf__,1,2)));
void _rtld_die(void);
Index: libexec/ld.elf_so/symbol.c
===================================================================
RCS file: /cvsroot/src/libexec/ld.elf_so/symbol.c,v
retrieving revision 1.35
diff -u -r1.35 symbol.c
--- libexec/ld.elf_so/symbol.c 7 Dec 2003 09:36:06 -0000 1.35
+++ libexec/ld.elf_so/symbol.c 18 Jul 2004 02:41:51 -0000
@@ -62,6 +62,13 @@
(Elf_Addr)dlsym,
(Elf_Addr)dlerror,
(Elf_Addr)dladdr,
+
+ (Elf_Addr)__dlopen,
+ (Elf_Addr)__dlclose,
+ (Elf_Addr)__dlsym,
+ (Elf_Addr)__dlerror,
+ (Elf_Addr)__dladdr,
+
0
};
int i;
--Apple-Mail-5-144014454
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
format=flowed
--Apple-Mail-5-144014454--
--Apple-Mail-6-144014463
content-type: application/pgp-signature; x-mac-type=70674453;
name=PGP.sig
content-description: This is a digitally signed message part
content-disposition: inline; filename=PGP.sig
content-transfer-encoding: 7bit
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (Darwin)
iD8DBQFA+eqvOpVKkaBm8XkRAn36AKCdy9J0Os87akos4Y9UOP9B2OyyoACgzdOu
jkCm4yNCohT1G8tOBB/K6cA=
=wDxN
-----END PGP SIGNATURE-----
--Apple-Mail-6-144014463--