* minimal loader program in C [not found] <CABrM6wnFdprziCNdj7PYzd7S1XAxw0jNT6oEBJew6+2PhLg45w@mail.gmail.com> @ 2021-04-29 13:58 ` Peng Yu 2021-05-02 22:46 ` Peng Yu 0 siblings, 1 reply; 2+ messages in thread From: Peng Yu @ 2021-04-29 13:58 UTC (permalink / raw) To: libc-help 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 ^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: minimal loader program in C 2021-04-29 13:58 ` minimal loader program in C Peng Yu @ 2021-05-02 22:46 ` Peng Yu 0 siblings, 0 replies; 2+ messages in thread From: Peng Yu @ 2021-05-02 22:46 UTC (permalink / raw) To: libc-help Maybe I can just compile /lib64/ld-linux-x86-64.so.2 to learn only the source code relevant to loader. Is there a way to just compile this file? On 4/29/21, Peng Yu <pengyu.ut@gmail.com> wrote: > 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 > -- Regards, Peng ^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-05-02 22:46 UTC | newest] Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <CABrM6wnFdprziCNdj7PYzd7S1XAxw0jNT6oEBJew6+2PhLg45w@mail.gmail.com> 2021-04-29 13:58 ` minimal loader program in C Peng Yu 2021-05-02 22:46 ` Peng Yu
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).