Date: 19 Dec 2000 17:29:49 +0300 From: Andrey Sverdlichenko <blaze@infosec.ru> To: FreeBSD-gnats-submit@freebsd.org Subject: i386/23643: dlopen() can't link to symbols in main program module Message-ID: <868zpcqyaq.fsf@xen.infosec.ru> Resent-Message-ID: <200012191430.eBJEU6l25082@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 23643
>Category: i386
>Synopsis: dlopen() can't link to symbols in main program module
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Tue Dec 19 06:30:03 PST 2000
>Closed-Date:
>Last-Modified:
>Originator: Andrey Sverdlichenko
>Release: FreeBSD 4.1.1-STABLE i386
>Organization:
NIP "Informzaschita"
>Environment:
FreeBSD xen.infosec.ru 4.1.1-STABLE FreeBSD 4.1.1-STABLE #4: Mon Oct 30 15:39:57 MSK 2000 blaze@xen.infosec.ru:/var/tmp/src/sys/compile/XEN i386
>Description:
Call dlopen(..., RTLD_NOW) returns "Undefined symbol" when shared object
uses a symbol from main program.
>How-To-Repeat:
Makefile
----------- begin Makefile -----------
prog: lib.so main.c
gcc -g -fpic -DPIC -Wall -o prog main.c
lib.so: lib.c
gcc -fpic -DPIC -O -pipe -Wall -c lib.c
cc -shared -o lib.so lib.o
clean:
rm -f prog *.o *.so
----------- end Makefile ---------------
main.c
----------- begin main.c ---------------
#include <stdio.h>
#include <sys/types.h>
#include <dlfcn.h>
char *str = "ok";
int main() {
static void * lib_so;
static void (*lib_so_func)();
lib_so = dlopen("./lib.so", RTLD_NOW | RTLD_GLOBAL);
if (!lib_so) {
fprintf(stderr, "dlopen: %s\n", dlerror());
return 1;
}
lib_so_func = dlsym(lib_so, "lib_so_func");
if (!lib_so_func) {
fprintf(stderr, "dlsym: %s\n", dlerror());
return 1;
}
lib_so_func();
return 0;
}
----------- end main.c ------------
lib.c
----------- begin lib.c -----------
#include <stdio.h>
extern char *str;
int lib_so_func() {
printf("%s\n", str);
return 1;
}
----------- end lib.c -----------
0:xen:test_so$ make
gcc -fpic -DPIC -O -pipe -Wall -c lib.c
cc -shared -o lib.so lib.o
gcc -g -fpic -DPIC -Wall -o prog main.c
0:xen:test_so$ ./prog
dlopen: ./lib.so: Undefined symbol "str"
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?868zpcqyaq.fsf>
