tags:

views:

68

answers:

1

Just curious. Using gcc/gdb under Ubuntu 9.10.

Reading a C book that also often gives the disassembly of the object file. When reading in January, my disassembly looks a lot like the book's; now, it's quite different - possibly more optimized (I notice some re-arrangements in the assembly code now that, at least in the files I checked, look optimized). I have used optimization options -O1 - -O3 for gcc between the first and second read, but not before the first.

(1) Is the use of optimization options persistent, aka, if you use them once, you'll use them until switching them off? That would be weird (browsed man file and at least did not see anything to that sort). In the unlikely case that it is true, how do you switch them off?

(2) Has gcc's assembly changed through any recent upgrade?

(3) Does gcc sometimes produce (significantly) different assembly code although same compile options are chosen?

Thanks much.

+3  A: 

1) No, the options don't persist.

2) Yes, the optimisers are constantly being changed and improved. If your gcc packages have been upgraded, then it is quite likely that the assembly generated for a particular source file will change.

3) Compiling with gcc is a deterministic process; if you compile the same source with the same version of gcc and the same options for the same target, then the assembly produced should be the same (modulo some symbol names).

caf
GCC uses random numbers for some symbol names ( -frandom-seed ), and I think I remember reading that some versions used non-deterministic heuristics on branch probability with -O3 on some architectures unless told not to. I'm having trouble locating info on the second part, though.
nategoose
Thanks, updated.
caf
Actually, some optimisers are order sensitive - if you change the order of things but not the things themselves, the optimisers may produce different output. They may also be sensitive to things like the amount of free memory. I have no idea if the gcc optimiser is sensitive to either of these things,
anon
Thanks much everyone.
gnometorule