This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

shared objects .init section not executed !?


Hi everyone,

I've stumbled across this yesterday, and after a little examination it seems
that libdl / ld.so is the culprit. Obviously "ld -shared" bravely collects
all the .ctors of library objects, wraps them, constructs a .init section to
call them all, only for ld.so to ignore the whole work.

Here is the test case, with C++ constructors used for the demonstration: the
main program links to a library containing a static/global object, and calls
a library function to read its state:


#include <ostream.h>

extern int libfunc();

int
main (int argc, char ** argv)
{
  cout << libfunc() << "\n";
  return 0;
}

Here's an extract of the library file:

class cl {...};

cl cl_obj;

int
libfunc()
{
  return cl_obj.getval();
}

where getval depends on cl_obj's initializer having been called or
not. Linking "statically" with the library object shows the constructor
properly has been called, while making it an .so file exposes the bug.

Have I overlooked something fundamentally, is this intentional for some
obscure reason or is it simply a yet undiscovered bug ?

	Torsten

whole test case for your convenience:

--[[application/octet-stream; type=tar+gzip
Content-Disposition: attachment; filename="solib-inittest.tar.gz"][base64]]
H4sIAOTFjzkAA+2WUW/aMBDHeY0/xYn2AdASEghBCnTa1KnbpG2t1Id1ElpljAGvwUGOQ1dV
9LPvnMBoq9E+jLaa5t9DEtt3Z8f2/+wsTcTQFVJozTPdrDwFvh/63W4H33672yrerSAIzXtN
xe8GYbsbtqIoqPhBuxV2K9B5ktHcI880VQCVUX7JH7JLMs1S9aDJv0h2d/0/0ws+Fsluf9MP
fD+Kwq3rH/nRev2DKMT6IOxiFfg7HcUW/vP1J4dHn96+P40PHPc4APcrTRJwJ+C+O/l4CO4Y
n+Tw7OxRG0KwMgbcS16Wwlylk+Lh4eRqwQgxhRhmVEgvJc5+DWPWixgp7L+B/T54zdK3NF35
rT2KuH/y+05I6VZ0fT4XzKPESUaFSTalio+MaWnjOM08U6afJlN6yCdCnmLsAXFc93KaJtyl
ik3Fgm9i3fHgcoT2RY9la7weF24gxRblnxDinXw4/vItBpZwKknxjImjZjhV0LiBBvbZMLPU
8GgxSQ1CXm797+m/mG/GdtvHY/oPzNlg9N9p4TkRGf13/LbV/3NA9oRkST7i0E8zrTidedPX
hPCfmisJQmqzx8e5ZLV6jxAsE7NFoGZaqJqwV8BQZtBomNKiTq4JAEtzDf3+xtMUqgNZ7WGj
4jrHyH6PLF9w21tW3NO/SWi7lv/j53+rtbn/4cUP9d9GM6v/Z4AlNMvwqELhzpVYUM1jFKlR
t+yReT5M8BQ2kk5QxdfyoNNbGhEvhNI5TeCmrC/qblUb9wnXC5qYrLEsEwfGiON1LbleJwLZ
gyXBUxKbz9Phj1WS+Z06ioSyMi0tvFuRCaavMfgO0mzCUarA7GKYUnYh5ART0lBoRdUVZJxp
kcqMlBcLM0Iyymezq1UP6A00m9WqA+2tbMEzqhjIgWbmwuObr02bxgxZrfe2uTKdqqzwSFIc
yFbn29lwDy8YYmyTosVisVgsFovFYrFYLBaLxWKxWCwWi+Uv+AX32QeZACgAAA==

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]