[英]Examine generated assembly code?
我有以下測試程序來檢查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;
}
根據如何獲取GCC生成匯編代碼 ,我使用以下命令編譯了源文件:
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)
...
相關,這是使我想看一下生成的代碼的基本問題。 如何通過內聯函數強制const傳播?
看來g ++已將您的main()
優化為斷言"y < THIS_SIZE"
失敗
如果您需要更多信息,則應向我們展示rotlFixed()
的實現。
該標志-O1
被優化掉你的函數調用rotlFixed(...)
用-O0
。
另外,如果您使用-S
,則不需要-c
。
如果您想在編譯器優化后查看機器代碼,請將其放入沒有main()的文件中並進行編譯。 然后,編譯器會認為它正在構建要從其他地方調用的函數。
通過在main()中擁有全部內容的方式,編譯器將看到您永遠不會使用結果,並丟棄未使用的函數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.