Same source generates different object code for gcc 4.1.2
Ian Lance Taylor
iant@google.com
Sat Jan 28 08:46:00 GMT 2012
sudhakar govindavajhala <sudhakarg79spam@gmail.com> writes:
> I am wondering why code generated by the same gcc 4.1.2 compiler on
> the same source and the same machine generates different codes at
> different times. I find this behavior very odd. Could someone please
> add me some perspective on this?
In gcc 4.1 doing a #include of <iostream.h> causes your object file to
include a global constructor. That global constructor would normally be
given a name associated with the first global symbol in your object
file. Since your object file does not have any global symbols, the
constructor is given a randomly chosen name in the hopes of avoiding
collisions (the name also includes the name of the file you are
compiling). You can see this if you run "readelf -s --wide" on your
object files. That randomly chosen name will be different each time the
compiler is run (unless of course you use the -frandom-seed option).
This works differently in current mainline and the objects files are now
consistently identical.
Ian
More information about the Gcc-help
mailing list