0

我正在重构 C++ 代码,删除using namespace std;和添加std::字符串、向量等。我希望输出在二进制方面是相同的,但cmp即使是最小的更改也会产生差异。我求助于反汇编 usingotool但在地址中遇到奇怪的偏移量。

例如,有了这个变化

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
[…]

它从字面上改变了所有的addies +/-0x10。有没有办法防止这种情况?为什么它首先发生?

还原上述更改并重新编译会得到原始地址,因此地址选择可能不是“随机”问题。

4

1 回答 1

0

在这种情况下(比特币核心),WJ van der Laan 显然为此目的编写了一个工具。如果其他人想要类似的东西,这可能会很有启发性。(麻省理工学院许可)

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

于 2016-11-28T07:49:18.777 回答