转自:http://unix.stackexchange.com/questions/5719/linux-gnu-gcc-ld-version-scripts-and-the-elf-binary-format-how-does-it-wor/10317#10317

First of all, ELF is the specification use by Linux for executable files (programs), shared libraries, and also object files which are the intermediate files found when compiling software. Object files end in .o, shared libraries end with .so followed by zero or more digits separated by periods, and executable files don't have any extension normally.

There are typically three forms to name a shared library, the first form simply ends in .so. For example, a library called readline is stored in a file called libreadline.so and is located under one of /lib, /usr/lib, or /usr/local/lib normally. That file is located when compiling software with an option like -lreadline. -l tells the compiler to link with the following library. Because libraries change from time to time, it may become obsolete so libraries embed something called a SONAME. The SONAME for readline might look like libreadline.so.2 for the second version major version of libreadline. There may also be many minor versions of readline that are compatible and do not require software to be recompiled. A minor version of readline might be named libreadline.so.2.14. Normally libreadline.so is just a symbolic link to the most recent major version of readline, libreadline.so.2 in this case. libreadline.so.2 is also a symbolic link to libreadline.so.2.14 which is actually the file being used.

The SONAME of a library is embedded inside the library file itself. Somewhere inside the file libreadline.so.2.14 is the string libreadline.so.2. When a program is compiled and linked with readline, it will look for the file libreadline.so and read the SONAME embedded in it. Later, when the program is actually executed, it will load libreadline.so.2, not just libreadline.so, since that was the SONAME that was read when it was first linked. This allows a system to have multiple incompatible versions of readline installed, and each program will load the appropriate major version it was linked with. Also, when upgrading readline, say, to 2.17, I can just install libreadline.so.2.17 alongside the existing library, and once I move the symbolic link libreadline.so.2 from libreadline.so.2.13 to libreadline.so.2.17, all software using that same major version will now see the new minor update to it.

最新文章

  1. CentOS个人目录下中文路径转英文路径
  2. php提供更快的文件下载
  3. android 数据存储Ⅰ
  4. IIS7 / IIS7.5 URL 重写 HTTP 重定向到 HTTPS(转)
  5. selenium中处理不带ID的弹出窗口
  6. jquery的学习
  7. WinDbg x 64 使用 SOS: 无法找到运行时 DLL (clr.dll)
  8. 如何使用jQuery设置背景的透明度
  9. [置顶] linux内核启动2-setup_arch中的内存初始化(目前分析高端内存)
  10. virtual-虚方法
  11. Java开发笔记(八十五)通过字符流读写文件
  12. css之overflow应用
  13. 记事本:js简介
  14. 使用Excel自动生成sql语句
  15. VirtualBox网络连接方式
  16. mysql主从调优
  17. mapreduce深入剖析5大视频
  18. Spring AOP 源码分析 - 创建代理对象
  19. HDU1698 Just a Hook(线段树&区间覆盖)题解
  20. 【HDU】2191 多重背包问题

热门文章

  1. 随手记一 2018/04/23 Ajax基础了解
  2. [C++ Primer Plus] 第8章、函数探幽(二)课后习题
  3. redis.exceptions.ConnectionError: Error 111 connecting to localhost:6379. Connection refused.
  4. 一键git push脚本(python版)
  5. 2019-4-21 - plan
  6. 洛谷 P3376 【【模板】网络最大流】
  7. Table组件设置文字超出宽度显示省略号,鼠标悬停以悬浮框显示
  8. day6_自定义类型转换
  9. rtf乱码解决办法
  10. 用JavaScript比较两个数组是否相等