我正在重构 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。有没有办法防止这种情况?为什么它首先发生?
还原上述更改并重新编译会得到原始地址,因此地址选择可能不是“随机”问题。