I run gcc -S filename.c or gcc filename.c -s successfully but no output. So how do you view the assembly code itself?
Asked
Active
Viewed 434 times
0
-
It compiles into `filename.s`. View it with `less`. Or use `-o -` to set the output file to `-` (which means stdout). – Peter Cordes Jan 28 '20 at 07: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'. – Jonathan Leffler Jan 28 '20 at 08: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. – Peter Cordes Jan 28 '20 at 08: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 `ld` — `ld: warning: option -s is obsolete and being ignored`. – Jonathan Leffler Jan 28 '20 at 08: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` – Peter Cordes Jan 28 '20 at 08:16
-
@PeterCordes I didn't use them together but different times to check both. I'm sure only about gcc -S foo.c which now worked. I have seen the .s file – Mohamed Ahmed Jan 28 '20 at 08:19
-
@JonathanLeffler I was wrong to use -s. That compiles to a.out. Agreed! Thanks. – Mohamed Ahmed Jan 28 '20 at 08:32