2

I want to create some assembly code with gcc. When I use gcc -masm=intel -S test.c I get assembly code full of .def and .cfi labels which I cannot assemble. Is there a way to create assembly code without this labels?

E.g.: A simple c code like:

int main() {
    return 0;
}

Compiles to:

.file   "test.c"
.intel_syntax noprefix
.def    ___main;    .scl    2;  .type   32; .endef
.text
.globl  _main
.def    _main;  .scl    2;  .type   32; .endef
_main:
LFB0:
.cfi_startproc
push    ebp
.cfi_def_cfa_offset 8
.cfi_offset 5, -8
mov ebp, esp
.cfi_def_cfa_register 5
and esp, -16
call    ___main
mov eax, 0
leave
.cfi_restore 5
.cfi_def_cfa 4, 4
ret
.cfi_endproc
LFE0:

But what I want is something like:

_main:
    push    ebp
    mov ebp, esp
    and esp, -16
    call    ___main
    mov eax, 0
    leave
    ret

I hope there's a way to do this. Thanks in advanced.

kaetzacoatl
  • 1,419
  • 1
  • 19
  • 27
  • 1
    Probably you cannot. gcc produces assembly intended for the gnu assembler - Which will assemble your first example fine. Which assembler are you using ? You can probably get rid of the directives with `cat main.s | grep -v '^\s*\.'` though. – nos Sep 05 '14 at 10:00
  • @nos I use nasm and some other assemblers using nasm syntax. – kaetzacoatl Sep 05 '14 at 10:05
  • @nos I'm not sure if I need them, but if not your solution should work fine. – kaetzacoatl Sep 05 '14 at 10:13
  • You can always use a perl script to clean up the output – doron Sep 05 '14 at 11:50
  • 1
    CFI is Call Frame Information. It's used by debuggers, and possibly for exception unwinding, but you don't need it in ordinary C. – ams Sep 05 '14 at 12:26

0 Answers0