breakage of -Bsymbolic-functions as LDFLAGS
Stefan Potyra
sistpoty at ubuntu.com
Fri May 16 22:24:22 BST 2008
Hi,
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:
dispatch_write_hello(void)
{
fprintf(stderr, "hello\n");
}
extern void
print_hello(void)
{
dispatch_write_hello();
}
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
dispatch_write_hello(void)
{
fprintf(stderr, "overridden\n");
}
int
main(int argc, char **argv)
{
print_hello();
return 0;
}
this will result in:
"overridden".
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:
"hello".
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 s.th. like
#pragma weak foobar
or a definition of foobar with
"__attribute__((__weak__))"
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),
Stefan.
--
[1]: http://launchpadlibrarian.net/14522776/find_dupes.sh
[2]: corresponding bug: https://bugs.launchpad.net/ubuntu/+bug/230460
-------------- 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 : https://lists.ubuntu.com/archives/ubuntu-devel/attachments/20080516/eb61006d/attachment.pgp
More information about the ubuntu-devel
mailing list