bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ld.so bug? extern weak symbol


From: Grigory Zagorodnev
Subject: ld.so bug? extern weak symbol
Date: Mon, 01 Oct 2001 09:08:29 +0000 (GMT)

Hi!

I have an situation wich needs to be clarified... 

Please take look at the testcase description and make me wise:
        - Is checking for weak symbol linking correct or not?
        - Is this a dynamic loader (ld.so) problem or not? 
                If "Yes":
                o Is this problem already known?
                o When it will be fixed?

The idea and scenario of the testcase is:
-----------------------------------------

My executable (main.c) has extern-weak declaration of 'hello' routine. So it 
could check is symbol linked in or not. If hello is linked, executable will 
call it...
                extern void hello() __attribute__((weak));
                ...
                if( hello ) 
                        hello();

Also I have the shared library with desired symbol defined (library libfoo.c, 
symbol 'hello').
Next I built this shared library and linked execitable against it. Everythin 
fine here: 'hello' linked, check succeed, routine called.
After that, I rebuilt the library with NO symbol 'hello' defined and ran 
executable (executable was not rebuilt).

*** And I've got coredump! ***

This is not what I expected. As I can see, check condition is true at this case 
but 'hello' does not exists within the application.

Ok, where is the true?

Testcase sources:
-----------------
=== main.c =================================
extern void hello() __attribute__((weak));
extern void bye();

int main(){
    if( hello )
        hello();
    bye();
    return 0;
}

=== libfoo.c ===============================
#include <stdio.h>

#if defined HELLO
void hello(){
    puts("Hello, world!");
}
#endif

void bye(){
    puts("Bye, world!");
}

=== go.ksh =================================
# Build shared library with 'hello' symbol defined
gcc -fPIC -DHELLO=1 -shared libfoo.c -o libfoo.so

# Build executable linked against shared library
gcc main.c -L. -lfoo

# Rebuild shared library with NO 'hello' symbol defined
gcc -fPIC -shared libfoo.c -o libfoo.so

# Execute test
export LD_LIBRARY_PATH=.
./a.out

============================================

Thanks and regards,
 Grigory Zagorodnev

PS: Sorry for writing from free mail service - our server is slightly buggy 8-)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]