问题
I know that source code can be compiled and linked to shared/static library or ELF executable files. And when program runs, it loads into memory and creates a process image according to ELF format. But I am not sure how programs loading shared libraries. How a linker looking for symbols in extern libraries and how the .a archive works. What else should I know if program runs on 64 bit OS?
I am trying to draw a whole picture of it. Can someone give a general talk about the whole thing and gives references/documents/llinks so I can study them one by one.
Thanks in advance.
I think my question can be described as:
Under Linux, How C++ source code becomes executable files or static/dynamic libraries. And how a program get loaded into memory when it runs. In GREATE details!
And how many tools I can use to examine/manipulate the Linux binary files(executable files and libraries)? I know some as “nm" "readelf".
回答1:
You could read:
- the Assembly HowTo
- From Powerup to Bash prompt
- Wikipedia about system calls, Linux kernel, Virtual memory, address space, Process, Compiler, Linker, Assembly language, GCC, ELF
- Levine's book on Linkers and Loaders
- x86-84, notably about the x86-64 ABI specification
- the Advanced Linux Programming book
- several syscalls(2) man pages, notably intro(2), execve(2), mmap(2), fork(2)
- ELF virus writing howto
- GCC documentation (notably internals)
- Binutils documentation
- Program Library Howto
- Drepper's paper: how to write shared libraries
and good books about Linux kernel & application programming.
回答2:
Try to real something like this http://www.symantec.com/connect/articles/dynamic-linking-linux-and-windows-part-one or this http://www.linuxjournal.com/article/6463
回答3:
For a start:
man pages to read: ld.so, ld, ar, gcc
utilities: readelf, nm, ldd, objdump, c++filt, gdb
32 vs 64 bit note: do a readelf -a on 32-bit and 64-bit versions of the same program and diff the output. Note the difference between "Requesting program interpreter" /lib/ld-linux.so.2 vs /lib64/ld-linux-x86-64.so.2.
来源:https://stackoverflow.com/questions/9494182/under-linux-how-c-source-code-becomes-executable-files-or-static-dynamic-libr