简体   繁体   中英

Enumerations cause binary change with optimizations in Gcc 4.2.4

I am using GCC version 4.2.4. The issue explained below can't be reproduced on Gcc 4.6.x and these are the only two versions I tested.

I have an header file that defines enumerations, Header: abc.h

enum test
{
    VALUE_1 = 1,
    VALUE_2 = 2,

    VALUE_MAX = 0xFFFF,
};

This header is included in a few source files and each source file creates an object (.o) at compilation time. And there are few source file that don't reference to any of the enumerations in abc.h.

The issue I am seeing is that if I add a new constant (VALUE_3) in abc.h, then the binary md5sum of the objects that don't use any enumerations also gets changes. This only happen when i apply optimizaions and not otherwise at compilation.

I suspect that it has something to do with flags -ftree-vrp and -ftree-dominator-opts that gets enabled with optimizations. using these flags with -fno still cause some of the objects to change but prevents other few from changing (that gets changes with these flags).

Another interesting obsevation is that the md5sum comes out to be same for even or odd number of enumerations.

Can anyone please help me understand that what's going on in the back end and is there any way to avoid binary change to maintain md5sum when there is no actual code change for that specific object.

Thanks in advance.

Edited:

For one object, following is the diff. For other objects there are few other changes as well (in mov etc instructions) . As you can see only the operand registers in some instructions are swapped. I want to understand the reason and how to avoid it with optimizations.

# diff test.o.1 test.o.2
1548,1549c1548,1549
<     cmpl    %eax, %ecx
<     jg      .L442
---
>     cmpl    %ecx, %eax
>     jl      .L442

is there any way to avoid binary change

To check Jonathon Reinhart's suspicion " it may have to do with branch prediction ", you could try the option -fno-guess-branch-probability .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM