Opened 14 years ago

Closed 14 years ago

#6491 closed bug (fixed)

dlsym() / dladdr() work strange

Reported by: Guest One Owned by: nobody
Priority: normal Milestone: R1
Component: System/POSIX Version: R1/Development
Keywords: Cc:
Blocked By: Blocking:
Platform: All

Description

I am not sure if it is a real bug or just my improper usage, but attached example works different on Linux and Haiku.

(test.lib.c)

int exoprted_symbol[]= {1, 2, 3, 4, 5, -1};

(test.app.c)

void *ptr;
void *symbol;
Dl_info info;

ptr = dlopen("./test.lib.so", RTLD_LAZY);

if(ptr==NULL)
{
    printf( "%s\n", dlerror() );
    return 1;
}

symbol = dlsym( ptr,  "exoprted_symbol") ;

if ( symbol == NULL )
{
    printf( "%s\n", dlerror() );
    return 1;
}

if( ! dladdr( symbol, &info ) )
{
    printf( "Error mapping address.\n" );
}

printf( "fname=%s\n",  info.dli_fname );
printf( "fbase=%p\n",  info.dli_fbase );
printf( "sname=%s\n",  info.dli_sname );
printf( "saddr=%p\n", info.dli_saddr );

On Linux we have:

fname=./test.lib.so
fbase=0xb78be000
sname=exoprted_symbol
saddr=0xb78c000c

On Haiku:

Error mapping address.
fname=
fbase=0x7ffeef9c
sname=
saddr=(nil)

Attachments (1)

dladdr-example.tgz (810 bytes ) - added by Guest One 14 years ago.

Download all attachments as: .zip

Change History (5)

by Guest One, 14 years ago

Attachment: dladdr-example.tgz added

comment:1 by Guest One, 14 years ago

Summary: ldsym() / dladdr() work strangedlsym() / dladdr() work strange

comment:2 by axeld, 14 years ago

This looks indeed more like a bug in Haiku, although the code in dladdr() looks pretty much okay.

comment:3 by Guest One, 14 years ago

I have an idea on this problem, but I won't have a single minute to test it for some time.

Here ( http://dev.haiku-os.org/browser/haiku/trunk/src/system/libroot/posix/dlfcn.c?rev=29112 ) we have such condition:

                if (symType == B_SYMBOL_TYPE_TEXT
                    && symLocation <= addr
                    && symLocation >= info->dli_saddr)

If I see things right this means that dladdr() search only for exported functions, not variables, so problem could be solved by:

                if ( (symType == B_SYMBOL_TYPE_TEXT || symType == B_SYMBOL_TYPE_DATA )
                    && symLocation <= addr
                    && symLocation >= info->dli_saddr)

comment:4 by axeld, 14 years ago

Resolution: fixed
Status: newclosed

Got rid of the extra check in hrev38373; since dladdr() is a GNU extension, it should better work like it does there.

Note: See TracTickets for help on using tickets.