Re: How to just output unoptimized assembly code without any extra annotations?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 29/04/2021 23:32, Peng Yu via Gcc-help wrote:
> Hi,
> 
> https://news.ycombinator.com/item?id=10773849
> 
> According to the above discussion, I use the following command to get
> the unoptimized assembly code. But it still has things like .file,
> .text, .globl, .type., .size, .ident, .section. If I delete them, the
> resulted assembly code still can be compiled. So they are
> nonessential. How to make gcc only generate the essential part of the
> assembly code?

What are you trying to do here?

gcc is a compiler - it is intended to produce assembly code to be
assembled as part of the build process.  It is not designed as a way of
generating sample assembly code, and you cannot look at the generated
code and think "gcc always puts this parameter into this stack frame
slot or this register".

If you want to mix assembly and C, use gcc's inline assembly (Jonathan
gave you a like to the manual page, and google will help you find
tutorials and examples).  If you want to write independent assembly
functions, use an assembler - stick to the documented ABI for your
target and you can use the code from C.  If you just want to see "what
assembly does gcc make for this code", I recommend the online compiler
at <https://godbolt.org>.

If you are trying to do something else, then please explain your aims -
it will make it a lot easier to give you help than trying to answer
various apparently random and unrelated questions.

As a general rule (there are occasional exceptions), I find that
whenever someone starts with "I am using gcc with optimisation
disabled...", they are wrong.  The person is asking the wrong question,
or expecting the wrong kind of answer, or using the wrong methods or
making wrong assumptions.  (IMHO gcc should have at least -O1 enabled by
default - having optimisation disabled is like selling a new car with
the gear stick locked in first gear, and requiring the driver to read
the instruction manual to learn how to unlock other gears.)

David


> 
> $ gcc -O0 -fno-asynchronous-unwind-tables -S -x c -o - - <<< 'int
> f(int x1, int x2, int x3, int x4, int x5, int x6) { return 0; }'
>   .file  ""
>   .text
>   .globl  f
>   .type  f, @function
> f:
>   pushq  %rbp
>   movq  %rsp, %rbp
>   movl  %edi, -4(%rbp)
>   movl  %esi, -8(%rbp)
>   movl  %edx, -12(%rbp)
>   movl  %ecx, -16(%rbp)
>   movl  %r8d, -20(%rbp)
>   movl  %r9d, -24(%rbp)
>   movl  $0, %eax
>   popq  %rbp
>   ret
>   .size  f, .-f
>   .ident  "GCC: (Debian 10.2.1-6) 10.2.1 20210110"
>   .section  .note.GNU-stack,"",@progbits
> 




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux