From nobody  Thu Jul 30 09:17:15 1998
Received: (from nobody@localhost)
          by hub.freebsd.org (8.8.8/8.8.8) id JAA19189;
          Thu, 30 Jul 1998 09:17:15 -0700 (PDT)
          (envelope-from nobody)
Message-Id: <199807301617.JAA19189@hub.freebsd.org>
Date: Thu, 30 Jul 1998 09:17:15 -0700 (PDT)
From: tshiozak@makino.ise.chuo-u.ac.jp
To: freebsd-gnats-submit@freebsd.org
Subject: Dlopen succeed in particular cases, but it is illegal in the cases.
X-Send-Pr-Version: www-1.0

>Number:         7446
>Category:       bin
>Synopsis:       Dlopen succeed in particular cases, but it is illegal in the cases.
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    jdp
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jul 30 09:20:00 PDT 1998
>Closed-Date:    Tue Oct 3 20:41:34 PDT 2000
>Last-Modified:  Tue Oct 03 20:42:31 PDT 2000
>Originator:     Takuya SHIOZAKI
>Release:        FreeBSD-2.2.6R(98)-Rev02
>Organization:
(Personal)
>Environment:
FreeBSD trident 2.2.6-RELEASE FreeBSD 2.2.6-RELEASE #1: Wed Jun 17 22:29:20 JST 1998     tshiozak@trident:/usr/src/sys/compile/trident  i386

>Description:
When shared object which contains the symbols which cannot be resolved
is tried to be loaded twice by using dlopen with RTLD_NOW option,
first dlopen call fail (this is correct action), but second dlopen 
call succeed (this is illegal action).

Perhaps, when dlopen fail to resolve symbols, dlopen doesn't release
mmap and module handle, does it?

>How-To-Repeat:
input follow files:
===========================
foo.c:
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>

int
main()
{
    void *h;
    
    if (NULL == (h=dlopen("var.so", RTLD_NOW))) {
        puts(dlerror());
    } else
        printf("success : %p\n", dlsym(h, "_var"));
    if (NULL == (h=dlopen("var.so", RTLD_NOW))) {
        puts(dlerror());
    } else
        printf("success : %p\n", dlsym(h, "_var"));
    return 0;
}
==============================
and var.c:
extern void hoge(void);

void var(void)
{
    hoge(); /* undefined symbol */
}
===============
And, compile and execute as follow:
% gcc -o foo foo.c
% gcc -c -fPIC var.c
% ld -Bshareable -o var.so var.o
% ./foo
Undefined symbol "_hoge" in foo:var.so
success : 0x2001b020
%

>Fix:
correct dlopen function.

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->jdp 
Responsible-Changed-By: jdp 
Responsible-Changed-When: Thu Jul 30 21:36:53 PDT 1998 
Responsible-Changed-Why:  
I'll take a look at this. 
State-Changed-From-To: open->closed 
State-Changed-By: jdp 
State-Changed-When: Tue Oct 3 20:41:34 PDT 2000 
State-Changed-Why:  
This PR applies to the a.out dynamic linker, which is essentially 
obsolete at this point.  The ELF dynamic linker does not exhibit the 
bug. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=7446 
>Unformatted:
