minimal loader program in C
Peng Yu
pengyu.ut@gmail.com
Thu Apr 29 03:32:46 GMT 2021
I see the following system calls are used when a program is run. I'd
like to understand how this process is done in detail. Is there a
minimal loader C program that just covers the basics of loading this
simple program?
$ cat main.c
int main() { return 0; }
$ gcc main.c
$ strace ./a.out
execve("./a.out", ["./a.out"], 0x7ffe586d5e60 /* 50 vars */) = 0
brk(NULL) = 0x562f27c1c000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=116056, ...}) = 0
mmap(NULL, 116056, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f71ab750000
close(3) = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0@n\2\0\0\0\0\0"...,
832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1839792, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0x7f71ab74e000
mmap(NULL, 1852680, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f71ab589000
mprotect(0x7f71ab5ae000, 1662976, PROT_NONE) = 0
mmap(0x7f71ab5ae000, 1355776, PROT_READ|PROT_EXEC,
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x25000) = 0x7f71ab5ae000
mmap(0x7f71ab6f9000, 303104, PROT_READ,
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x170000) = 0x7f71ab6f9000
mmap(0x7f71ab744000, 24576, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1ba000) = 0x7f71ab744000
mmap(0x7f71ab74a000, 13576, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f71ab74a000
close(3) = 0
arch_prctl(ARCH_SET_FS, 0x7f71ab74f540) = 0
mprotect(0x7f71ab744000, 12288, PROT_READ) = 0
mprotect(0x562f2789d000, 4096, PROT_READ) = 0
mprotect(0x7f71ab797000, 4096, PROT_READ) = 0
munmap(0x7f71ab750000, 116056) = 0
exit_group(0) = ?
+++ exited with 0 +++
--
Regards,
Peng
More information about the Binutils
mailing list