Reputation: 4155
If I compile this piece of C code:
void _start() {
}
with this invocation of gcc:
gcc -nostdlib -Os -S foo.c
I get this assembly listing:
.file "foo.c"
.section .text.unlikely,"x"
LCOLDB0:
.text
LHOTB0:
.globl __start
.def __start; .scl 2; .type 32; .endef
__start:
pushl %ebp
movl %esp, %ebp
popl %ebp
ret
.section .text.unlikely,"x"
LCOLDE0:
.text
LHOTE0:
.ident "GCC: (GNU) 4.9.2"
As you see gcc has issued a 'ret' instruction at the end of the code. Is there a way to make it not to issue that?
Upvotes: 2
Views: 654
Reputation: 7925
Calling __builtin_unreachable();
in your function tells gcc that it does not need to return at the end, since it will not reach the end.
Upvotes: 5