breakage of -Bsymbolic-functions as LDFLAGS

Stefan Potyra sistpoty at
Fri May 16 22:24:22 BST 2008


first off all, I'm by far no expert on ELF and shared objects. What I write 
here is mainly based on trial-and-error and on recent observations[2]. I'd be 
highly interested that more experienced people will correct me.

So what does -Bsymbolic-functions:

Let's assume you have a library, which defines the following:

        fprintf(stderr, "hello\n");

extern void

without -Bsymbolic-functions, you can redefine dispatch_write_hello in a 
program (or a shared library depending on this library). At run-time, the new 
function will be called.

e.g. a progam like this:

extern void
        fprintf(stderr, "overridden\n");

main(int argc, char **argv)
        return 0;

this will result in:

With -Bsymbolic-functions, all calls inside the library will be resolved at 
compile time, in case they are defined there. Hence the overridden 
dispatch_write_hello will never be called. The output will be:

So my assumption is, that if you want to look for different behaviours for 
LDFLAGS, you just need to look out for duplicate symbols. To do this, I've 
written a very rough script at [1]. (this is far from complete).

Also, I've found that this behaviour is valid for weak symbols as well. 

In a c-program, I believe that weak symbols are mainly used for excactly this 
purpose (unlike c++, where these are the result of inline implementations 
inside header files). So you might also want to grep for "weak" to check if 
there's like

#pragma weak foobar
or a definition of foobar with 

To conclude, my assumption is that if (a worked over version) of [1] won't 
find any duplicate symbols and you do find functions defined as weak symbols, 
it's done on purpose. 
OTOH, you if should find duplicate symbols with [1] and there are no weak 
definitions, it is likely to be a bug. Of course, if a duplicate symbol is 
found, you should always look at the corresponding function in the source 
code to be sure.

In the hope, that this will help to identify whether -Bsymbolic-functions 
results in a bug found if it fails, or will fail due to software design on 
purpose (and also, that someone more experienced will enlighten me, what 
assumptions here are wrong),
[2]: corresponding bug:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : 

More information about the ubuntu-devel mailing list