kern/103312: dlsym(NULL,) doesn't work properly

Dmitry Karasik dmitry at
Sat Sep 16 05:40:21 PDT 2006

>Number:         103312
>Category:       kern
>Synopsis:       dlsym(NULL,) doesn't work properly
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Sep 16 12:40:19 GMT 2006
>Originator:     Dmitry Karasik
>Release:        FreeBSD 6.1-PRERELEASE i386
System: FreeBSD 6.1-PRERELEASE FreeBSD 6.1-PRERELEASE #1: Fri Mar 31 20:36:29 CEST 2006 root at i386


	man 3 dlsym states:

     If dlsym() is called with the special handle NULL, it is interpreted as a
     reference to the executable or shared object from which the call is being

	however, dlsym(NULL,) returns NULL always.

#include <stdio.h>
#include <dlfcn.h>
#include <math.h>

int main()
	void * ptr;

	ptr = fabs;
	printf("fabs: %x\n", fabs);

	ptr = dlsym( NULL, "fabs");
	if ( ptr) {
		printf("dlsym(NULL,fabs)=%x\n", fabs);
	} else {
		printf("dlsym(NULL,fabs) error:%s\n", dlerror());

	ptr = dlopen( NULL, RTLD_LOCAL);
	printf("dlopen(NULL): %x\n", ptr);

	ptr = dlsym( ptr, "fabs");
	if ( ptr) {
		printf("dlsym(dlopen(NULL),fabs)=%x\n", fabs);
	} else {
		printf("dlsym(dlopen(NULL),fabs) error:%s\n", dlerror());

	return 0;


More information about the freebsd-bugs mailing list