Linker and Libraries Guide
Total Page:16
File Type:pdf, Size:1020Kb
Linker and Libraries Guide Sun Microsystems, Inc. 4150 Network Circle Santa Clara, CA 95054 U.S.A. Part No: 816–7777–10 April 2003 Copyright 2003 Sun Microsystems, Inc. 4150 Network Circle, Santa Clara, CA 95054 U.S.A. All rights reserved. This product or document is protected by copyright and distributed under licenses restricting its use, copying, distribution, and decompilation. No part of this product or document may be reproduced in any form by any means without prior written authorization of Sun and its licensors, if any. Third-party software, including font technology, is copyrighted and licensed from Sun suppliers. Parts of the product may be derived from Berkeley BSD systems, licensed from the University of California. UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open Company, Ltd. Sun, Sun Microsystems, the Sun logo, docs.sun.com, AnswerBook, AnswerBook2, and Solaris are trademarks, registered trademarks, or service marks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the U.S. and other countries. Products bearing SPARC trademarks are based upon an architecture developed by Sun Microsystems, Inc. The OPEN LOOK and Sun™ Graphical User Interface was developed by Sun Microsystems, Inc. for its users and licensees. Sun acknowledges the pioneering efforts of Xerox in researching and developing the concept of visual or graphical user interfaces for the computer industry. Sun holds a non-exclusive license from Xerox to the Xerox Graphical User Interface, which license also covers Sun’s licensees who implement OPEN LOOK GUIs and otherwise comply with Sun’s written license agreements. Federal Acquisitions: Commercial Software–Government Users Subject to Standard License Terms and Conditions. DOCUMENTATION IS PROVIDED “AS IS” AND ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD TO BE LEGALLY INVALID. Copyright 2003 Sun Microsystems, Inc. 4150 Network Circle, Santa Clara, CA 95054 U.S.A. Tous droits réservés. Ce produit ou document est protégé par un copyright et distribué avec des licences qui en restreignent l’utilisation, la copie, la distribution, et la décompilation. Aucune partie de ce produit ou document ne peut être reproduite sous aucune forme, par quelque moyen que ce soit, sans l’autorisation préalable et écrite de Sun et de ses bailleurs de licence, s’il y en a. Le logiciel détenu par des tiers, et qui comprend la technologie relative aux polices de caractères, est protégé par un copyright et licencié par des fournisseurs de Sun. Des parties de ce produit pourront être dérivées du système Berkeley BSD licenciés par l’Université de Californie. UNIX est une marque déposée aux Etats-Unis et dans d’autres pays et licenciée exclusivement par X/Open Company, Ltd. Sun, Sun Microsystems, le logo Sun, docs.sun.com, AnswerBook, AnswerBook2, et Solaris sont des marques de fabrique ou des marques déposées, ou marques de service, de Sun Microsystems, Inc. aux Etats-Unis et dans d’autres pays. Toutes les marques SPARC sont utilisées sous licence et sont des marques de fabrique ou des marques déposées de SPARC International, Inc. aux Etats-Unis et dans d’autres pays. Les produits portant les marques SPARC sont basés sur une architecture développée par Sun Microsystems, Inc. L’interface d’utilisation graphique OPEN LOOK et Sun™ a été développée par Sun Microsystems, Inc. pour ses utilisateurs et licenciés. Sun reconnaît les efforts de pionniers de Xerox pour la recherche et le développement du concept des interfaces d’utilisation visuelle ou graphique pour l’industrie de l’informatique. Sun détient une licence non exclusive de Xerox sur l’interface d’utilisation graphique Xerox, cette licence couvrant également les licenciés de Sun qui mettent en place l’interface d’utilisation graphique OPEN LOOK et qui en outre se conforment aux licences écrites de Sun. CETTE PUBLICATION EST FOURNIE “EN L’ETAT” ET AUCUNE GARANTIE, EXPRESSE OU IMPLICITE, N’EST ACCORDEE, Y COMPRIS DES GARANTIES CONCERNANT LA VALEUR MARCHANDE, L’APTITUDE DE LA PUBLICATION A REPONDRE A UNE UTILISATION PARTICULIERE, OU LE FAIT QU’ELLE NE SOIT PAS CONTREFAISANTE DE PRODUIT DE TIERS. CE DENI DE GARANTIE NE S’APPLIQUERAIT PAS, DANS LA MESURE OU IL SERAIT TENU JURIDIQUEMENT NUL ET NON AVENU. 030224@5533 Contents Preface 13 1 Introduction to the Solaris Linkers 17 Link-Editing 18 Runtime Linking 19 Related Topics 20 Dynamic Linking 20 Application Binary Interfaces 20 32–Bit and 64–Bit Environments 20 Environment Variables 21 Support Tools 21 2 Link-Editor 23 Invoking the Link-Editor 24 Direct Invocation 24 Using a Compiler Driver 25 Specifying the Link-Editor Options 25 Input File Processing 26 Archive Processing 27 Shared Object Processing 28 Linking With Additional Libraries 29 Initialization and Termination Sections 34 Symbol Processing 36 Symbol Resolution 36 Undefined Symbols 40 3 Tentative Symbol Order Within the Output File 44 Defining Additional Symbols 44 Reducing Symbol Scope 49 External Bindings 53 String Table Compression 54 Generating the Output File 54 Relocation Processing 55 Displacement Relocations 56 Debugging Aids 57 3 Runtime Linker 61 Shared Object Dependencies 62 Locating Shared Object Dependencies 62 Directories Searched by the Runtime Linker 62 Configuring the Default Search Paths 65 Dynamic String Tokens 65 Relocation Processing 66 Symbol Lookup 67 When Relocations Are Performed 68 Relocation Errors 70 Loading Additional Objects 71 Lazy Loading of Dynamic Dependencies 72 Initialization and Termination Routines 74 Initialization and Termination Order 75 Security 77 Runtime Linking Programming Interface 79 Loading Additional Objects 80 Relocation Processing 81 Obtaining New Symbols 87 Feature Checking 90 Debugging Aids 90 Debugging Library 90 Debugger Module 93 4 Shared Objects 97 Naming Conventions 98 Recording a Shared Object Name 99 4 Linker and Libraries Guide • April 2003 Shared Objects With Dependencies 101 Dependency Ordering 102 Shared Objects as Filters 103 Generating a Standard Filter 103 Generating an Auxiliary Filter 106 Filtee Processing 107 Performance Considerations 107 Analyzing Files 108 Underlying System 109 Lazy Loading of Dynamic Dependencies 110 Position-Independent Code 110 Remove Unused Material 113 Maximizing Shareability 113 Minimizing Paging Activity 115 Relocations 115 Using -Bsymbolic 120 Profiling Shared Objects 120 5 Application Binary Interfaces and Versioning 123 Interface Compatibility 124 Internal Versioning 125 Creating a Version Definition 125 Binding to a Version Definition 130 Specifying a Version Binding 134 Version Stability 138 Relocatable Objects 139 External Versioning 139 Coordination of Versioned Filenames 139 6 Support Interfaces 143 Link-Editor Support Interface 143 Invoking the Support Interface 144 Support Interface Functions 145 Support Interface Example 147 Runtime Linker Auditing Interface 149 Establishing a Namespace 150 Creating an Audit Library 150 Contents 5 Invoking the Auditing Interface 151 Recording Local Auditors 152 Audit Interface Functions 152 Audit Interface Example 157 Audit Interface Demonstrations 157 Audit Interface Limitations 158 Runtime Linker Debugger Interface 158 Interaction Between Controlling and Target Process 159 Debugger Interface Agents 160 Debugger Exported Interface 161 Debugger Import Interface 169 7 Object File Format 171 File Format 171 Data Representation 173 ELF Header 174 ELF Identification 178 Data Encoding 180 Sections 181 Section Groups 192 Special Sections 193 String Table 198 Symbol Table 199 Syminfo Table 206 Relocation 208 Comdat Section 218 Versioning Information 218 Note Section 223 Move Section 224 Thread-Local Storage 226 Dynamic Linking 227 Program Header 228 Program Loading (Processor-Specific) 233 Runtime Linker 239 Dynamic Section 240 Global Offset Table (Processor-Specific) 252 Procedure Linkage Table (Processor-Specific) 253 6 Linker and Libraries Guide • April 2003 Hash Table 261 8 Mapfile Option 263 Mapfile Structure and Syntax 263 Segment Declarations 264 Mapping Directives 268 Section-Within-Segment Ordering 269 Size-Symbol Declarations 270 File Control Directives 270 Mapping Example 270 Mapfile Option Defaults 272 Internal Map Structure 273 A Link-Editor Quick Reference 277 Static Mode 277 Creating a Relocatable Object 278 Creating a Static Executable 278 Dynamic Mode 278 Creating a Shared Object 278 Creating a Dynamic Executable 280 B Versioning Quick Reference 281 Naming Conventions 281 Defining a Shared Object’s Interface 283 Versioning a Shared Object 283 Versioning an Existing (Non-versioned) Shared Object 284 Updating a Versioned Shared Object 285 Adding New Symbols 285 Internal Implementation Changes 286 New Symbols and Internal Implementation Changes 286 Migrating Symbols to a Standard Interface 287 C Establishing Dependencies with Dynamic String Tokens 291 Instruction Set Specific Shared Objects 291 Reducing Auxiliary Searches 292 System Specific Shared Objects 293 Contents 7 Locating Associated Dependencies 293 Dependencies Between Unbundled Products 295 Security 296 D New Linker and Libraries Features and Updates 299 Solaris 9 12/02 Release 299 Solaris 9 Release 299 Solaris 8 07/01 Release 300 Solaris 8 01/01 Release 300 Solaris 8 10/00 Release 301 Solaris 8 Release 301