作者:阿连AND王进_893_799 | 来源:互联网 | 2022-11-23 13:43
我写了下面的代码来调用syscall exit
而不用glibc链接:
// a.c
#include
#include
#include
_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));
}
的Makefile
:
.PHONY: clean
a.out: a.o
$(CC) -nostartfiles -nostdlib -Wl,--strip-all a.o
a.o: a.c
$(CC) -Oz -c a.c
clean:
rm a.o a.out
我用make
它CC=clang-7
并且它工作得很好,除了当我检查生成的组件时objdump -d a.out
:
a.out: file format elf64-x86-64
Disassembly of section .text:
0000000000201000 <.text>:
201000: 6a 3c pushq $0x3c
201002: 58 pop %rax
201003: 31 ff xor %edi,%edi
201005: 0f 05 syscall
201007: c3 retq
有一个无用的retq
跟随syscall
.我想知道,有没有办法删除它而不需要在汇编中编写整个函数?
1> prl..:
在不返回的系统调用之后添加:
__builtin_unreachable();