0

Hi I compiled my c++ code with -S flag:

int main(){
   int x = 10;
   x++;
   return x;
}

And after that a got this assembly code:

.file   "test.cpp"
    .text
    .def    __main; .scl    2;      .type   32;     .endef
    .globl  main
    .def    main;   .scl    2;      .type   32;     .endef
    .seh_proc       main
 main:
.LFB0:
    pushq   %rbp
    .seh_pushreg    %rbp
    movq    %rsp, %rbp
    .seh_setframe   %rbp, 0
    subq    $48, %rsp
    .seh_stackalloc 48
    .seh_endprologue
    call    __main
    movl    $10, -4(%rbp)
    addl    $1, -4(%rbp)
    movl    -4(%rbp), %eax
    addq    $48, %rsp
    popq    %rbp
    ret
    .seh_endproc
    .ident  "GCC: (GNU) 11.2.0"

And my question is What are lines:

  1. .def __main; .scl 2; .type 32; .endef
  2. .seh_proc main
  • 1. Defines the entry point function `__main` which is called at `call __main` 2. Probably is the entry point of a `.seh_proc main` – πάντα ῥεῖ Oct 15 '22 at 15:53
  • 2
    Did you check the manual of the assembler this code was generated for? – fuz Oct 15 '22 at 19:06
  • [How to remove "noise" from GCC/clang assembly output?](https://stackoverflow.com/q/38552116) re: filtering out those directives that are basically irrelevant for understanding the program logic. SEH is Windows Structured Exception Handling. MinGW adds a call to a `__main` init function from *inside* the C or C++ `main`, so stuff you're seeing about that is just MinGW shenanigans to get its standard library initialized that way, instead of via a dynamic linker hook. – Peter Cordes Oct 17 '22 at 06:34

0 Answers0