【发布时间】:2018-12-28 13:47:01
【问题描述】:
我写了以下代码:
// 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));
}
然后使用clang-7 -Oz -pipe -flto -c a.c编译它并使用llc-7 -filetype=asm a.o将其变成人类可读的汇编文件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
在上面的程序集中,指令#APP出现在syscall之前,这是我编写的程序集,指令#NO_APP出现在它之后。
我知道这一定与asm的使用有关,比如防止它被优化出来,但是我在谷歌上搜索后找不到它的任何文档。
多谢了。
【问题讨论】:
标签: c gcc assembly directive inline-assembly