How do you get assembler output from C/C++ source in gcc?

后端 未结 17 1827
天命终不由人
天命终不由人 2020-11-22 02:43

How does one do this?

If I want to analyze how something is getting compiled, how would I get the emitted assembly code?

17条回答
  •  后悔当初
    2020-11-22 03:16

    The following command line is from Christian Garbin's blog

    g++ -g -O -Wa,-aslh horton_ex2_05.cpp >list.txt
    

    I ran G++ from a DOS window on Win-XP, against a routine that contains an implicit cast

    c:\gpp_code>g++ -g -O -Wa,-aslh horton_ex2_05.cpp >list.txt
    horton_ex2_05.cpp: In function `int main()':
    horton_ex2_05.cpp:92: warning: assignment to `int' from `double'
    

    The output is asssembled generated code iterspersed with the original C++ code (the C++ code is shown as comments in the generated asm stream)

      16:horton_ex2_05.cpp **** using std::setw;
      17:horton_ex2_05.cpp ****
      18:horton_ex2_05.cpp **** void disp_Time_Line (void);
      19:horton_ex2_05.cpp ****
      20:horton_ex2_05.cpp **** int main(void)
      21:horton_ex2_05.cpp **** {
     164                    %ebp
     165                            subl $128,%esp
    ?GAS LISTING C:\DOCUME~1\CRAIGM~1\LOCALS~1\Temp\ccx52rCc.s
    166 0128 55                    call ___main
    167 0129 89E5          .stabn 68,0,21,LM2-_main
    168 012b 81EC8000      LM2:
    168      0000
    169 0131 E8000000      LBB2:
    169      00
    170                    .stabn 68,0,25,LM3-_main
    171                    LM3:
    172                            movl $0,-16(%ebp)
    

提交回复
热议问题