This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Same source generates different object code for gcc 4.1.2
- From: Ian Lance Taylor <iant at google dot com>
- To: sudhakar govindavajhala <sudhakarg79spam at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Fri, 27 Jan 2012 13:53:26 -0800
- Subject: Re: Same source generates different object code for gcc 4.1.2
- References: <CAGdJZsD0JXMVWi-yRvMbgOB9fNJN+Px+5MGz_g5M31xLkznA9g@mail.gmail.com>
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