I wrote the following code:
// a.c
#include <stdlib.h>
#include <sys/syscall.h>
#include <unistd.h>
_Noreturn void _start()
{
register int syscall_num asm ("rax") = __NR_exit;
register int exit_code asm ("rdi") = 0;
// The actual syscall to exit
asm volatile ("syscall"
: /* no output Operands */
: "r" (syscall_num), "r" (exit_code));
}
And then compiled it using clang-7 -Oz -pipe -flto -c a.c
and used llc-7 -filetype=asm a.o
to turn it into an human-readable assembly file a.o.s
:
.text
.file "a.c"
.globl _start # -- Begin function _start
.type _start,@function
_start: # @_start
.cfi_startproc
# %bb.0:
pushq $60
.cfi_adjust_cfa_offset 8
popq %rax
.cfi_adjust_cfa_offset -8
xorl %edi, %edi
#APP
syscall
#NO_APP
retq
.Lfunc_end0:
.size _start, .Lfunc_end0-_start
.cfi_endproc
# -- End function
.ident "clang version 7.0.1-svn348686-1~exp1~20181211133235.57 (branches/release_70)"
.section ".note.GNU-stack","",@progbits
In the assembly above, the directive #APP
appears before syscall
, which is the assembly I wrote and the directive #NO_APP
appears right after it.
I know it must have something to do with the use of asm
, like to prevent it from being optimized out, but I can't find any documentation of it after googling.
Thanks advanced.