https://sourceware.org/bugzilla/show_bug.cgi?id=20152
Bug ID: 20152 Summary: constructors for c++ objects are sometimes discarded when linked via a .a archive Product: binutils Version: 2.27 (HEAD) Status: NEW Severity: normal Priority: P2 Component: ld Assignee: unassigned at sourceware dot org Reporter: dmalcolm at redhat dot com Target Milestone: --- I noticed when developing a patch for GCC that C++ objects with global constructors are sometimes discarded if linked via a .a archive. I've created a minimal reproducer for this here: https://github.com/davidmalcolm/test-ctor I can turn that into an archive and attach it if that's preferably. In the example, test-ctor.C contains objects with constructors that should be run before main. If linked as a .o file into the final executable, the constructors are run. If converted to a .a archive first, the constructors are only run if there's another symbol in the file that's consumed by something in another file. Note how in test-1 and test-2a, four ctors are run, but in test-2b, only two ctors are run; the ctors in test-ctors.C appear to be being discarded: $ ./test-1 foo:foo(test-ctor.C, static foo in emptyish file) foo:foo(test-ctor.C, foo in anon ns in emptyish file) foo:foo(test-ctor-main.C, static foo in main file) foo:foo(test-ctor-main.C, foo in anon ns in main file) main() $ ./test-2a foo:foo(test-ctor-main.C, static foo in main file) foo:foo(test-ctor-main.C, foo in anon ns in main file) foo:foo(test-ctor.C, static foo in emptyish file) foo:foo(test-ctor.C, foo in anon ns in emptyish file) main() $ ./test-2b foo:foo(test-ctor-main.C, static foo in main file) foo:foo(test-ctor-main.C, foo in anon ns in main file) main() Seen with binutils-2.23.88.0.1-13.fc20.x86_64, reproduced with trunk (f3ad76370f8c79e4ae74ca6826e23bf417d5283a, 2016-05-25). -- You are receiving this mail because: You are on the CC list for the bug. _______________________________________________ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils