【发布时间】:2015-07-19 03:21:35
【问题描述】:
我有以下测试程序来检查 GCC 生成的代码。 rotlFixed 在标头misc.h 中提供,并将其声明为内联。它还使用模板特化来调用 GCC 内联汇编:
int main(int argc, char* argv[])
{
byte r1 = rotlFixed(1, 1);
byte r2 = rotlFixed(1, 255);
word16 r3 = rotlFixed(1, 1);
word16 r4 = rotlFixed(1, 255);
word16 r5 = rotlFixed(1, 256);
word16 r6 = rotlFixed(1, 65535);
cout << r1 << "," << r2 << "," << r3 << "," << r4 << ",";
cout << r5 << "," << r6 << endl;
return 0;
}
根据How to get GCC to generate assembly code,我编译源文件为:
g++ -O1 -S -c cryptopp-test.cxx
但是当我猫时,我没有看到对旋转的调用:
$ cat cryptopp-test.s
.file "cryptopp-test.cxx"
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "misc.h"
.LC1:
.string "y < THIS_SIZE"
.text
.globl main
.type main, @function
main:
.LFB2196:
.cfi_startproc
subq $8, %rsp
.cfi_def_cfa_offset 16
movl $_ZZN8CryptoPP9rotlFixedIiEET_S1_jE19__PRETTY_FUNCTION__, %ecx
movl $692, %edx
movl $.LC0, %esi
movl $.LC1, %edi
call __assert_fail
.cfi_endproc
.LFE2196:
.size main, .-main
.type _GLOBAL__sub_I_main, @function
_GLOBAL__sub_I_main:
.LFB2311:
.cfi_startproc
subq $8, %rsp
.cfi_def_cfa_offset 16
movl $_ZStL8__ioinit, %edi
call _ZNSt8ios_base4InitC1Ev
movl $__dso_handle, %edx
movl $_ZStL8__ioinit, %esi
movl $_ZNSt8ios_base4InitD1Ev, %edi
call __cxa_atexit
addq $8, %rsp
.cfi_def_cfa_offset 8
ret
.cfi_endproc
.LFE2311:
.size _GLOBAL__sub_I_main, .-_GLOBAL__sub_I_main
.section .init_array,"aw"
.align 8
.quad _GLOBAL__sub_I_main
.section .rodata
.align 32
.type _ZZN8CryptoPP9rotlFixedIiEET_S1_jE19__PRETTY_FUNCTION__, @object
.size _ZZN8CryptoPP9rotlFixedIiEET_S1_jE19__PRETTY_FUNCTION__, 54
_ZZN8CryptoPP9rotlFixedIiEET_S1_jE19__PRETTY_FUNCTION__:
.string "T CryptoPP::rotlFixed(T, unsigned int) [with T = int]"
.local _ZStL8__ioinit
.comm _ZStL8__ioinit,1,1
.hidden __dso_handle
.ident "GCC: (GNU) 5.1.1 20150618 (Red Hat 5.1.1-4)"
.section .note.GNU-stack,"",@progbits
我显然做错了什么,因为我要检查的调用丢失了。
如何生成列表?或者,如果我正在生成它,如何显示所有相关部分?
提前致谢。
如果重要的话,系统是 Fedora 22 x86_64 和 GCC 5.1.1:
$ uname -a
Linux localhost.localdomain 4.0.4-301.fc22.x86_64 #1 SMP Thu May 21 13:10:33 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
$ gcc --version
gcc (GCC) 5.1.1 20150618 (Red Hat 5.1.1-4)
...
相关,这是导致我想查看生成的代码How to force const propagation through an inline function?的潜在问题@
【问题讨论】:
-
尝试编译可执行文件并将其转储为
objdump -d。