2 msgCommon Tail Elimination
1 msgInstallation failure: `GLIBC_2.3' not found
3 msgmix of sse and x87 code on x86_64
3 msgCreating and using header files
7 msgInconsistent results casting double to int on x86
1 msgconstraints for saving stack pointer
4 msgShared variables (between ELF executables)
3 msgfunction template specialization problem

Constructors of library objects doesn't get called
\ Rüdiger Ranft (21 Mar 2006)
. \ Andrew Haley (21 Mar 2006)

1 msgnewbie question: linking problem
1 msgwhere can I find tools info and example steps t...
2 msgmd files language
1 msgfor getting millisecond resolution in profiling...
1 msgBuilding with gcc 2.95 on a gcc 3.x distro
4 msgHelp in GIMPLE to RTL transformation
1 msgGCC 4.1.0 build failure on solaris 2.8
1 msgCan not build gcc-4.0.2
1 msg--program-transform-name option doesn't do anyt...
4 msgefficiency
2 msgUsing a compiler from a program
Subject:Re: Constructors of library objects doesn't get called
Group:Gcc-help
From:Andrew Haley
Date:21 Mar 2006



Rüdiger Ranft writes:

> I figured out a stange behavior, when a progamm is linked aginst a lib
> archive. If there are object files in the archive, which have
> constrution functions, they do not get called, unless some other symbol
> of the object file is referenced by the using program. When the linking
> is done directly with the .o files instead an .a file, the ctors are
> called. Also the ctors are get called when a symbol of the library is
> referenced from another program part. So I guess when there is no
> referencing part to the library during linking, the whole archive gets
> silently dropped by the linker.
>
> I attached a test case for this behavior, which builds 4 demonstration
> programs:
> ~ | Residence of i | link | result
> - ----+----------------+---------+-------
> vll | lib | lib | ok
> vlo | lib | objects | ok
> vpl | program | lib | BAD
> vpo | program | objects | ok
>
> The main problem for me is that I use a tool for generating some
> autoregistration stuff for a plugin system, which relies on the call to
> the constructors of a c++ object inside the sources.

If a file is wholly unreferenced it won't be included: this is
desirable linker behaviour.

Do this:

~/testcase $ gcc -o vpl zzz.o -Wl,-whole-archive libblubb.a -Wl,-no-whole-archive
~/testcase $ ./vpl
i=42

This isn't a gcc but a binutils issue.

Andrew.


© 2004-2008 readlist.com