简体   繁体   English

枚举通过Gcc 4.2.4中的优化导致二进制更改

[英]Enumerations cause binary change with optimizations in Gcc 4.2.4

I am using GCC version 4.2.4. 我正在使用GCC版本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. 下面说明的问题无法在Gcc 4.6.x上重现,这是我测试过的仅有的两个版本。

I have an header file that defines enumerations, Header: abc.h 我有一个定义枚举的头文件,头文件: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. 此标头包含在一些源文件中,并且每个源文件在编译时都会创建一个对象(.o)。 And there are few source file that don't reference to any of the enumerations in abc.h. 几乎没有源文件引用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. 我看到的问题是,如果我在abc.h中添加新的常量(VALUE_3),则不使用任何枚举的对象的二进制md5sum也将得到更改。 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. 我怀疑这与通过优化启用的-ftree-vrp和-ftree-dominator-opts标志有关。 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). 将这些标志与-fno一起使用仍会导致某些对象发生更改,但会阻止其他一些对象发生更改(通过这些标志进行更改)。

Another interesting obsevation is that the md5sum comes out to be same for even or odd number of enumerations. 另一个有趣的发现是,对于枚举的偶数或奇数,md5sum都是相同的。

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. 任何人都可以帮助我了解后端发生了什么,当该特定对象没有实际代码更改时,有什么方法可以避免二进制更改来维护md5sum。

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) . 对于其他对象,也几乎没有其他更改(在mov等说明中)。 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 . 要检查Jonathon Reinhart的怀疑“ 可能与分支预测有关 ”,可以尝试使用-fno-guess-branch-probability选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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