0

I run gcc -S filename.c or gcc filename.c -s successfully but no output. So how do you view the assembly code itself?

7
  • It compiles into filename.s. View it with less. Or use -o - to set the output file to - (which means stdout). Commented Jan 28, 2020 at 7:59
  • The lower-case -s used to be for stripping executables when linking; are you sure that does anything with assembler? Upper-case -S is for 'generate assembly'. Commented Jan 28, 2020 at 8:01
  • @JonathanLeffler: both those commands are valid. gcc -S foo.c compiles to foo.s. gcc -s foo.c compiles and links to a stripped binary called a.out. You're correct that using both together is useless (gcc -S -s foo.c), but that's not what the OP said they did. Commented Jan 28, 2020 at 8:03
  • @PeterCordes — the main point of my comment is that it is pointless to look for assembler files after running gcc filename.c -s — there won't be any generated and kept. Thanks for confirming that -s is nominally for 'stripping the executable'. On my Macs, it (-s) is a no-op, or generates a warning from ldld: warning: option -s is obsolete and being ignored. Commented Jan 28, 2020 at 8:05
  • @JonathanLeffler: oh, yeah I see what you mean. I assume the OP didn't run ls -lrt to see recently-modified files in the directory, and was expecting output to the terminal directly, not a file. That's why I commented about using gcc foo.c -O1 -S -fverbose-asm -masm=intel -o - | less. But yes, -s is an option you definitely don't want to use if you're going to disassemble an executable with objdump -drwC -Mintel a.out | less Commented Jan 28, 2020 at 8:16

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.