简体   繁体   English

格式化 c++ 代码时汇编程序和十六进制转储更改

[英]Assembler and hex dump change when formatting c++ code

A C++ project I work on does not have consistent indentation.我从事的一个 C++ 项目没有一致的缩进。 The lead developer told me it might not be safe to reformat the code.首席开发人员告诉我重新格式化代码可能不安全。 I thought it might not matter to the compiled code.我认为编译的代码可能无关紧要。 As a test I tried reformatting one file using a Formatter based on the Eclipse "GNU [built-in]" Profile.作为测试,我尝试使用基于 Eclipse“GNU [内置]”配置文件的格式化程序重新格式化一个文件。 When I recompiled the file the md5sum changed.当我重新编译文件时, md5sum 发生了变化。 I did a hexdump of the file and it showed one byte changed.我做了一个文件的十六进制转储,它显示一个字节改变了。 I disassembled the object file.我反汇编了object文件。 I also compiled with debugging and I got the source code line.我还通过调试进行了编译,并获得了源代码行。 I used diff to get the assembly instruction that changed.我使用 diff 来获取更改的汇编指令。

The source was this line来源是这条线

        logErr
        << xmlutils.GetErrorMessage() << endl;

Below is the diff output showing the changed assembly下面是差异 output 显示更改的程序集

     23be:  89 04 24                mov    %eax,(%esp)
     23c1:  e8 fc ff ff ff          call   23c2 <_ZN12RerouteAdapt11WriteToFileERKSs+0x64>
     23c6:  e8 fc ff ff ff          call   23c7 <_ZN12RerouteAdapt11WriteToFileERKSs+0x69>
-    23cb:  c7 44 24 04 79 01 00    movl   $0x179,0x4(%esp)
+    23cb:  c7 44 24 04 84 01 00    movl   $0x184,0x4(%esp)
     23d2:  00 
     23d3:  89 04 24                mov    %eax,(%esp)
     23d6:  e8 fc ff ff ff          call   23d7 <_ZN12RerouteAdapt11WriteToFileERKSs+0x79>

The ordering of the headers was not changed by the reformat.重新格式化没有改变标题的顺序。

I know some C/C++, but very little about assembly.我知道一些 C/C++,但对汇编知之甚少。 I was wondering if there was a simple explanation for why the object file would change.我想知道是否有一个简单的解释来解释为什么 object 文件会改变。 I thought the C++ compiler (GCC 4.8.2 on RHEL 7) was indifferent to formatting and white space.我认为 C++ 编译器(RHEL 7 上的 GCC 4.8.2)对格式和空白无动于衷。 There were no differences besides this in the assembly.在大会上除此之外没有任何区别。

Thomas and Tim were correct.托马斯和蒂姆是对的。 The value that changed corresponds to the line number before and after formatting.更改的值对应于格式化前后的行号。 I assumed "logErr" was just a stream.我假设“logErr”只是一个 stream。 Turns out it is a macro that uses the __LINE__ macro.原来它是一个使用__LINE__宏的宏。 So the line number is hard-coded in the assembly.所以行号在程序集中是硬编码的。

#define logErr theTracer().SetFuncName(__func__); theTracer().SetFile(__FILE__); theTracer().SetLine(__LINE__); theTracer().SetError(); theTracer()

Thank you for your help.谢谢您的帮助。

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

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