Subject: port-alpha/17726: NetBSD/alpha dlopen() problem?
To: None <gnats-bugs@gnats.netbsd.org>
From: Ray Phillips <r.phillips@jkmrc.uq.edu.au>
List: netbsd-bugs
Date: 07/26/2002 10:47:35
>Number:         17726
>Category:       port-alpha
>Synopsis:       dlopen() generates core dump
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    port-alpha-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jul 25 17:48:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Ray Phillips
>Release:        NetBSD 1.6_BETA2
>Organization:
JKMRC
>Environment:

System: NetBSD jkalpha2.jkmrc.uq.edu.au 1.6_BETA2 NetBSD 1.6_BETA2 
(GENERIC) #0: Wed Jun 19 18:30:37 MEST 2002 
bouyer@java:/home/tmp/alpha/obj/sys/arch/alpha/compile/GENERIC alpha
Architecture: alpha
Machine: alpha

>Description:
         Making a shared libary, then using dlopen() to resolve the 
symbols in it causes a core dump.  This problem didn't occur with 
NetBSD/alpha 1.5.2.  This example is used by perl 5.6.1's Configure 
script.  The output to stdout when Configure is run in interactive 
mode is:


Checking whether your dlsym() needs a leading underscore ...
pid 18412 (fred): unaligned access: va=0x16001447c pc=0x1600144dc 
ra=0x16008caa8 sp=0x1fffffa68 op=ldq
Segmentation fault - core dumped


(Sorry, if this is a false report.  I could well be out of my depth 
here, but I think this code should work--on the face of it anyway. 
Perhaps there's something about the way Configure creates dyna.so 
which I don't understand.)

>How-To-Repeat:

Configure creates a shared library, dyna.so, from dyna.c [1] then 
compiles and runs fred.c [2] to see if it's possible to resolve 
dyna.so's single symbol.  By trial and error I found the core dump 
occurs when dlopen() is called.

[1]
% cat dyna.c
fred () { }
%

[2]
% cat fred.c

#include <stdio.h>
#define I_DLFCN
#ifdef I_DLFCN
#include <dlfcn.h>      /* the dynamic linker include file for Sunos/Solaris */
#else
#include <sys/types.h>
#include <nlist.h>
#include <link.h>
#endif

extern int fred() ;

int main()
{
     void * handle ;
     void * symbol ;
#ifndef RTLD_LAZY
     int mode = 1 ;
#else
     int mode = RTLD_LAZY ;
#endif
     handle = dlopen("./dyna.so", mode) ;
     if (handle == NULL) {
         printf ("1\n") ;
         fflush (stdout) ;
         exit(0);
     }
     symbol = dlsym(handle, "fred") ;
     if (symbol == NULL) {
         /* try putting a leading underscore */
         symbol = dlsym(handle, "_fred") ;
         if (symbol == NULL) {
             printf ("2\n") ;
             fflush (stdout) ;
             exit(0);
         }
         printf ("3\n") ;
     }
     else
         printf ("4\n") ;
     fflush (stdout) ;
     exit(0);
}
%

>Fix:
unknown.
>Release-Note:
>Audit-Trail:
>Unformatted: