Why would gnu ld link order causes Signal 11 (SEGV) on startup?
Posted
by Benoit
on Stack Overflow
See other posts from Stack Overflow
or by Benoit
Published on 2010-03-22T14:22:43Z
Indexed on
2010/03/22
15:41 UTC
Read the original article
Hit count: 160
We are building a large application in C++ that includes the use of many (static) libraries. We have a problem where the application crashes on startup with a Signal 11, before we even reach main.
After much debugging, we have observed that if we explicitly reference an object file so its link order is early, the program crashes on startup. If the file is referenced later (or not referenced at all), the program does not crash.
To be clear, there is NO code invoked directly from this object file. However, as it is C++, there might be static objects that do get constructed (it's a CORBA IDL generated file).
We use the -Wl,--start-group ... --end-group arguments to multi-pass link the symbols since the libraries are interdependent.
Here is a representation of what I mean. This is what the linker's object file order is:
Order 1 Order 2 Order 3
foo.o foo.o foo.o
... ... ...
main.o main.o main.o
crasher.o
libA.o libA.o libA.o
LibB.o LibB.o LibB.o
LibC.o LibC.o LibC.o
crasher.o
Results:
NO CRASH NO CRASH CRASH
Does any one have an idea why the linkage order has an effect on the crash? It would be nice if we could force the crasher.o to link later, but we're really after an explanation. Also, is there a way to force the linker to place crasher.o towards the end? Just to add to the fun, in actuality, crasher.o is part of a Library in the --start/--end-group.
© Stack Overflow or respective owner