使用otool在重构代码中进行二进制比较

时间:2016-11-28 05:43:39

标签: c++ c++11 refactoring binaryfiles otool

我正在重构C ++代码,删除using namespace std;并将std::添加到字符串,向量等。我希望输出是二进制的,但是cmp给出了差异,即使对于最小的变化。我使用otool进行反汇编,但在地址中遇到了奇怪的偏移。

E.g。有了这个改变

diff --git a/src/core_read.cpp b/src/core_read.cpp
@@ -26,7 +26,7 @@ CScript ParseScript(const std::string& s)
{
    CScript result;

-    static map<string, opcodetype> mapOpNames;
+    static std::map<string, opcodetype> mapOpNames;

    if (mapOpNames.empty())
    {

otool -XVt给出一个奇数地址偏移量:

bench_bitcoin.s:
8c8
<       movq    0x392f7b(%rip), %rbx ## literal pool symbol address: ___stack_chk_guard
---
>       movq    0x392f8b(%rip), %rbx ## literal pool symbol address: ___stack_chk_guard
19c19
<       jne     0x100003fa9
---
>       jne     0x100003f99
25c25
<       callq   0x100229c44 ## symbol stub for: ___stack_chk_fail
---
>       callq   0x100229c34 ## symbol stub for: ___stack_chk_fail
33c33
<       movq    0x392f2b(%rip), %rbx ## literal pool symbol address: ___stack_chk_guard
---
>       movq    0x392f3b(%rip), %rbx ## literal pool symbol address: ___stack_chk_guard
[…]

它实际上会移动所有地址+/- 0x10。有办法防止这种情况吗?为什么它首先发生?

恢复上述更改并重新编译会提供原始地址,因此可能不是&#34;随机性&#34;在地址选择中。

1 个答案:

答案 0 :(得分:0)

在这种情况下(比特币核心),W.J。van der Laan显然为此目的编写了一个工具。如果其他人想要类似的东西,这可能是鼓舞人心的。 (麻省理工学院许可)

https://github.com/laanwj/bitcoin-maintainer-tools