From 39f2a9e2dbcb75fc521ec64c193600724da73d41 Mon Sep 17 00:00:00 2001 From: Nate Williams Date: Tue, 19 Aug 1997 23:33:45 +0000 Subject: [PATCH] - In dlsym(), if the lookup fails using the original symbol, prepend an underscore and try looking it up again. This is a non-issue if we switch to ELF. Reviewed by: sef, jdp --- gnu/usr.bin/ld/rtld/rtld.c | 32 ++++++++++++++++++++++++++++++-- libexec/rtld-aout/rtld.c | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/gnu/usr.bin/ld/rtld/rtld.c b/gnu/usr.bin/ld/rtld/rtld.c index ea33fe897a1c..452e6fffb126 100644 --- a/gnu/usr.bin/ld/rtld/rtld.c +++ b/gnu/usr.bin/ld/rtld/rtld.c @@ -27,7 +27,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: rtld.c,v 1.46 1997/02/22 15:46:48 peter Exp $ + * $Id: rtld.c,v 1.47 1997/08/02 04:56:44 jdp Exp $ */ #include @@ -1916,7 +1916,7 @@ __dlsym(fd, sym) } static void * -__dlsym3(fd, sym, retaddr) +resolvesym(fd, sym, retaddr) void *fd; char *sym; void *retaddr; @@ -1975,6 +1975,34 @@ __dlsym3(fd, sym, retaddr) return (void *)addr; } + static void * +__dlsym3(fd, sym, retaddr) + void *fd; + char *sym; + void *retaddr; +{ + void *result; + + result = resolvesym(fd, sym, retaddr); + /* + * XXX - Ugly, but it makes the least impact on the run-time loader + * sources. We assume that most of the time the error is a + * undefined symbol error from above, so we try again. If it's + * not an undefined symbol we end up getting the same error twice, + * but that's acceptable. + */ + if (result == NULL) { + /* Prepend an underscore and try again */ + char *newsym = malloc(strlen(sym) + 2); + + newsym[0] = '_'; + strcpy(&newsym[1], sym); + result = resolvesym(fd, newsym, retaddr); + free(newsym); + } + return result; +} + static char * __dlerror __P((void)) { diff --git a/libexec/rtld-aout/rtld.c b/libexec/rtld-aout/rtld.c index ea33fe897a1c..452e6fffb126 100644 --- a/libexec/rtld-aout/rtld.c +++ b/libexec/rtld-aout/rtld.c @@ -27,7 +27,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: rtld.c,v 1.46 1997/02/22 15:46:48 peter Exp $ + * $Id: rtld.c,v 1.47 1997/08/02 04:56:44 jdp Exp $ */ #include @@ -1916,7 +1916,7 @@ __dlsym(fd, sym) } static void * -__dlsym3(fd, sym, retaddr) +resolvesym(fd, sym, retaddr) void *fd; char *sym; void *retaddr; @@ -1975,6 +1975,34 @@ __dlsym3(fd, sym, retaddr) return (void *)addr; } + static void * +__dlsym3(fd, sym, retaddr) + void *fd; + char *sym; + void *retaddr; +{ + void *result; + + result = resolvesym(fd, sym, retaddr); + /* + * XXX - Ugly, but it makes the least impact on the run-time loader + * sources. We assume that most of the time the error is a + * undefined symbol error from above, so we try again. If it's + * not an undefined symbol we end up getting the same error twice, + * but that's acceptable. + */ + if (result == NULL) { + /* Prepend an underscore and try again */ + char *newsym = malloc(strlen(sym) + 2); + + newsym[0] = '_'; + strcpy(&newsym[1], sym); + result = resolvesym(fd, newsym, retaddr); + free(newsym); + } + return result; +} + static char * __dlerror __P((void)) {