Bug 7446 - Dlopen succeed in particular cases, but it is illegal in the cases.
Summary: Dlopen succeed in particular cases, but it is illegal in the cases.
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: John Polstra
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 1998-07-30 17:20 UTC by tshiozak
Modified: 2000-10-04 04:42 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description tshiozak 1998-07-30 17:20:00 UTC
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?

Fix: 

correct dlopen function.
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
%
Comment 1 John Polstra freebsd_committer freebsd_triage 1998-07-31 05:36:53 UTC
Responsible Changed
From-To: freebsd-bugs->jdp

I'll take a look at this. 
Comment 2 John Polstra freebsd_committer freebsd_triage 2000-10-04 04:41:34 UTC
State Changed
From-To: open->closed

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.