Under Linux, How C++ source code becomes executable files or static/dynamic libraries. And how a program get loaded into memory when it runs

南楼画角 提交于 2019-12-30 12:38:42

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!