execve 如何调用动态链接器/加载器(ld-linux.so.2) [英] How does execve call dynamic linker/loader (ld-linux.so.2)
本文介绍了execve 如何调用动态链接器/加载器(ld-linux.so.2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用gcc编译链接了最基本的C程序test.c:
I used gcc to compile and link the most basic C program, test.c:
int
main() {
}
正如预期的那样,输出是一个动态链接的可执行文件:
As expected, the output is a dynamically linked executable:
$ file test
test: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.26, BuildID[sha1]=0x0f806c099f74132a158d98aebde4639ae0998971, not stripped
运行 strace 给出以下输出:
Running strace gives the following output:
$ strace -f ./test
execve("./test", ["./test"], [/* 31 vars */]) = 0
brk(0) = 0x248d000
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f77eeb27000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=109292, ...}) = 0
mmap(NULL, 109292, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f77eeb0c000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY) = 3
read(3, "177ELF211 3 >