linker and loader 中文版+英文版
几乎从有计算机以来,链接器和加载器就是软件开发工具包中的一部分,因为他们是允许使用模块(而不是一个单独的大文件)来构建程序的关键工具。早在1947年,程序员们就开始使用原始的加载器:将程序的例程存储在多个不同的磁带上,并将他们合并、重定位为一个程序。在上世纪60年代早期,这些加载器就已经发展的相当完善了。由于那时内存很贵且容量有限,计算机的速度(以今天的标准)很慢,为了创建复杂的内存覆盖策略(将大容量的程序加在到少量的内存中),以及重复编辑之前链接过的文件(节省重新创建程序的时间),这些链接器都包含了很多复杂的特性。上世纪70到80年代,链接技术几乎没有什么进展。链接器趋向于更加简单,虚拟内存技术将应用程序和覆盖机制中的大多数存储管理工作都转移给了操作系统,越来越快的计算机和越来越大的磁盘也使得重新链接一个程序或替换个别模块比仅仅链接改变过的地方更加容易了。从上世纪90年代起,由于增加了诸如动态链接共享库和C++的诸多现代特性,链接器又 开始变得复杂起来。像IA64这样具有长指令字和编译时访存调度等特性的先进处理器架构,也需要将一些新的特性加入到链接器中以确保在被链接的程序中可以满足代码的这些复杂需求。Table of ContentsChapter 0: Front Matter ........................................................ 1Dedication .............................................................................................. 1Introduction ............................................................................................ 1Who is this book for? ......................................................................... 2Chapter summaries ............................................................................. 3The project ......................................................................................... 4Acknowledgements ............................................................................ 5Contact us ........................................................................................... 6Chapter 1: Linking and Loading ........................................... 7What do linkers and loaders do? ............................................................ 7Address binding: a historical perspective .............................................. 7Linking vs. loading .............................................................................. 10Two-pass linking .............................................................................. 12Object code libraries ........................................................................ 15Relocation and code modification .................................................... 17Compiler Drivers .................................................................................. 18Linker command languages ............................................................. 19Linking: a true-life example ................................................................. 20Exercises .............................................................................................. 25Chapter 2: Architectural Issues ........................................... 27Application Binary Interfaces .............................................................. 27Memory Addresses .............................................................................. 28Byte Order and Alignment ............................................................... 28Address formation ................................................................................ 30Instruction formats ............................................................................... 31Procedure Calls and Addressability ..................................................... 32Procedure calls ................................................................................. 332 Table of ContentsData and instruction references ............................................................ 36IBM 370 ........................................................................................... 37SPARC ............................................................................................. 40SPARC V8 ................................................................................... 40SPARC V9 ................................................................................... 42Intel x86 ........................................................................................... 43Paging and Virtual Memory ................................................................. 45The program address space .............................................................. 48Mapped files ..................................................................................... 49Shared libraries and programs ......................................................... 51Position-independent code ............................................................... 51Intel 386 Segmentation ........................................................................ 53Embedded architectures ....................................................................... 55Address space quirks ........................................................................ 56Non-uniform memory ...................................................................... 56Memory alignment ........................................................................... 57Exercises .............................................................................................. 57Chapter 3: Object Files ........................................................ 59What goes into an object file? .............................................................. 59Designing an object format .............................................................. 60The null object format: MS-DOS .COM files ...................................... 61Code sections: Unix a.out files ............................................................. 61a.out headers .................................................................................... 64Interactions with virtual memory ..................................................... 65Relocation: MS-DOS EXE files ........................................................... 72Symbols and relocation ........................................................................ 74Relocatable a.out .................................................................................. 75Relocation entries ............................................................................. 78Symbols and strings ......................................................................... 80a.out summary .................................................................................. 82Unix ELF ............................................................................................. 82Relocatable files ............................................................................... 85ELF executable files ......................................................................... 92ELF summary ................................................................................... 94Table of Contents 3IBM 360 object format ......................................................................... 94ESD records ..................................................................................... 95TXT records ..................................................................................... 97RLD records ..................................................................................... 97END records ..................................................................................... 98Summary .......................................................................................... 98Microsoft Portable Executable format ................................................. 99PE special sections ......................................................................... 105Running a PE executable ............................................................... 107PE and COFF ................................................................................. 107PE summary ................................................................................... 108Intel/Microsoft OMF files .................................................................. 108OMF records .................................................................................. 110Details of an OMF file ................................................................... 111Summary of OMF .......................................................................... 114Comparison of object formats ............................................................ 114Project ................................................................................................ 115Exercises ............................................................................................ 117Chapter 4: Storage allocation ............................................ 119Segments and addresses ..................................................................... 119Simple storage layout ......................................................................... 120Multiple segment types ...................................................................... 121Segment and page alignment ............................................................. 124Common blocks and other special segments ..................................... 125Common ......................................................................................... 125C++ duplicate removal ................................................................... 127Initializers and finalizers ................................................................ 130IBM pseudo-registers ..................................................................... 131Special tables ................................................................................. 134X86 segmented storage allocation ................................................. 134Linker control scripts ......................................................................... 136Embedded system storage allocation ................................................. 138Storage allocation in practice ............................................................. 138Storage allocation in Unix a.out linkers ......................................... 1394 Table of ContentsStorage allocation in ELF .............................................................. 141Storage allocation in Windows linkers .......................................... 144Exercises ............................................................................................ 146Project ................................................................................................ 147Chapter 5: Symbol management ....................................... 149Binding and name resolution ............................................................. 149Symbol table formats ......................................................................... 150Module tables ................................................................................. 153Global symbol table ....................................................................... 154Symbol resolution .......................................................................... 157Special symbols ............................................................................. 158Name mangling .................................................................................. 158Simple C and Fortran name mangling ........................................... 158C++ type encoding: types and scopes ............................................ 160Link-time type checking ................................................................ 163Weak external and other kinds of symbols ........................................ 164Maintaining debugging information .................................................. 164Line number information ............................................................... 164Symbol and variable information ................................................... 165Practical issues ............................................................................... 166Exercises ............................................................................................ 167Project ................................................................................................ 167Chapter 6: Libraries ........................................................... 169Purpose of libraries ............................................................................ 169Library formats .................................................................................. 169Using the operating system ............................................................ 169Unix and Windows Archive files ................................................... 170Unix archives ............................................................................. 170Extension to 64 bits ........................................................................ 174Intel OMF libraries ........................................................................ 174Creating libraries ................................................................................ 176Searching libraries ............................................................................. 177Table of Contents 5Performance issues ............................................................................. 179Weak external symbols ...................................................................... 179Exercises ............................................................................................ 181Project ................................................................................................ 181Chapter 7: Relocation ......................................................... 183Hardware and software relocation ..................................................... 183Link time and load time relocation .................................................... 184Symbol and segment relocation ......................................................... 185Symbol lookups ............................................................................. 186Basic relocation techniques ................................................................ 186Instruction relocation ..................................................................... 188X86 instruction relocation .......................................................... 189SPARC instruction relocation .................................................... 189ECOFF segment relocation ............................................................ 191ELF relocation ............................................................................... 193OMF relocation .............................................................................. 193Relinkable and relocatable output formats ........................................ 194Other relocation formats .................................................................... 194Chained references ......................................................................... 195Bit maps ......................................................................................... 195Special segments ............................................................................ 196Relocation special cases ..................................................................... 197Exercises ............................................................................................ 197Project ................................................................................................ 198Chapter 8: Loading and overlays ...................................... 201Basic loading ...................................................................................... 201Basic loading, with relocation ............................................................ 202Position-independent code ................................................................. 203TSS/360 position independent code ............................................... 203Per-routine pointer tables ............................................................... 206Table of Contents ........................................................................... 207ELF position independent code ..................................................... 2086 Table of ContentsPIC costs and benefits .................................................................... 212Bootstrap loading ............................................................................... 213Tree structured overlays ..................................................................... 214Defining overlays ........................................................................... 217Implementation of overlays ........................................................... 220Overlay fine points ......................................................................... 222Data ............................................................................................ 222Duplicated code ......................................................................... 222Multiple regions ......................................................................... 223Overlay summary ........................................................................... 223Exercises ............................................................................................ 223Project ................................................................................................ 224Chapter 9: Shared libraries ............................................... 227Binding time ...................................................................................... 230Shared libraries in practice ................................................................. 231Address space management ............................................................... 231Structure of shared libraries ............................................................... 232Creating shared libraries .................................................................... 233Creating the jump table .................................................................. 234Creating the shared library ............................................................. 235Creating the stub library ................................................................. 235Version naming .............................................................................. 237Linking with shared libraries ............................................................. 238Running with shared libraries ............................................................ 238The malloc hack, and other shared library problems ......................... 240Exercises ............................................................................................ 243Project ................................................................................................ 244Chapter 10: Dynamic Linking and Loading .................... 247ELF dynamic linking ......................................................................... 248Contents of an ELF file ...................................................................... 248Loading a dynamically linked program ............................................. 253Starting the dynamic linker ............................................................ 253Table of Contents 7Finding the libraries ....................................................................... 254Shared library initialization ............................................................ 255Lazy procedure linkage with the PLT ................................................ 256Other peculiarities of dynamic linking .............................................. 258Static initializations ........................................................................ 258Library versions ............................................................................. 259Dynamic loading at runtime ............................................................... 260Microsoft Dynamic Link Libraries .................................................... 260Imported and exported symbols in PE files ................................... 261Lazy binding .................................................................................. 266DLLs and threads ........................................................................... 267OSF/1 pseudo-static shared libraries ................................................. 267Making shared libraries fast ............................................................... 268Comparison of dynamic linking approaches ...................................... 270Exercises ............................................................................................ 271Project ................................................................................................ 271Chapter 11: Advanced techniques ..................................... 273Techniques for C++ ........................................................................... 273Trial linking .................................................................................... 274Duplicate code elimination ............................................................ 276Database approaches ...................................................................... 278Incremental linking and relinking ...................................................... 278Link time garbage collection ............................................................. 281Link time optimization ....................................................................... 282Link time code generation ................................................................. 284Link-time profiling and instrumentation ........................................ 284Link time assembler ....................................................................... 285Load time code generation ............................................................. 285The Java linking model ...................................................................... 287Loading Java classes ...................................................................... 288Exercises ............................................................................................ 290Project ................................................................................................ 2918 Table of ContentsChapter 12: References ...................................................... 293Perl books ....................................................................................... 295
用户评论
多谢分享,这资源太完美了。
经典的书籍,完全是可以看的
感谢楼主分享