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

后端 未结 17 1796
天命终不由人
天命终不由人 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:03

    This will generate assembly code with the C code + line numbers interweaved, to more easily see which lines generate what code:

    # create assembler code:
    g++ -S -fverbose-asm -g -O2 test.cc -o test.s
    # create asm interlaced with source lines:
    as -alhnd test.s > test.lst
    

    Found in Algorithms for programmers, page 3 (which is the overall 15th page of the PDF).

提交回复
热议问题