⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ld.1

📁 早期freebsd实现
💻 1
📖 第 1 页 / 共 2 页
字号:
and the abbreviated library-names specified by.RB ` \-l '.These may appearanywhere, and their influence is dependent upon their location.  Some options may be obtained fromenvironment variables, such options are interpreted before anyon the command line (see.SM ENVIRONMENT\s0,below)..SS Object File Processing.LPThe files specified on the command line are processed inthe order listed.  Information is extracted from each file,and concatenated to form the output.  The specificprocessing performed on a given file depends upon whether it isa simple object file, a library archive, or a shared library..LPSimple object.RB ( .o )files are concatenated to the output as they are encountered..LPLibrary archive.RB  ( .a )files are searched exactly once each, as each is encountered;only those archive entries matching an unresolved external referenceare extracted and concatenated to the output.  If a member of anarchive references a symbol defined by another member of that samearchive, the member making the reference must appear before themember containing the definition..LPOn Sun386i, a library contains a dictionary of symbols,  Onother Sun systems, processing library archives through.BR ranlib (1)provides this dictionary.  In addition, you can use .BR lorder (1),in combination with.BR tsort (1)to place library members in calling order (see .BR lorder (1)for details), or both (for fastest symbol lookup).The first member of an archived processed by.B ranlib has the reserved name of.BR _\^_.\s-1SYMDEF\s0 ,which.B ldtakes to be the dictionary of all symbols defined bymembers of the archive..LPSharable objects.RB ( .so )are scanned for symbol definitions and references, but are not normally included in the output from.BR ld ,except in cases where a shared library exports initialized datastructures and the.B \-dcoption is in effect.  However, theoccurrence of each sharable object file in the.BR ldcommand line is noted in the resulting executable file; thisnotation is utilized by an execution-time variant of.BR ld ,.BR ld.so ,for.I deferredand.I dynamicloading and binding during execution.See.BR "Execution-Time Loading" ,below, for details..LPThe.B \-loption specifies a short name for an objectfile or archive used as a library.The full name of the object file isderived by adding the prefix .B liband a suffix of either.B .aor.BR .so [ .\c.IR v ]to indicate an .BR ar (1V)archive or a shared library, respectively.The specific suffix used is determined through rules discussed in.BR "Binding and Relocation Semantics" ,below..LP.B ldsearches for the desired object file through a list ofdirectories specified by.B \-Loptions, the environment variable.BR \s-1LD_LIBRARY_PATH\s0 ,and finally, the built-in list of standard library directories:.BR /lib ,.BR /usr/lib ,and.BR /usr/local/lib ...SS Binding and Relocation Semantics.LPThe manner in which.B ldprocesses a given object file isdependent in part upon the \*(lqbinding mode\*(rq in which it is operatingat the time the file is encountered.This binding mode is specified by the.B \-Bflag, which takes the keyword arguments:.RS.TP 10.B dynamicAllow dynamic binding, do not resolve symbolic references, and allowcreation of execution-time symbol and relocation information.This is the default setting..TP.B staticForce static binding, implied by options that generate non-sharableexecutable formats..RE.LP.B \-Bdynamicand.B \-Bstaticmay be specified several times, and may be used to toggle each otheron and off.Like.BR \-l ,the influence of each depends upon its location within thecommand line. When.B \-Bdynamicis in effect, .B \-lsearches may be satisfied by the first occurrence of either form oflibrary .RB ( .soor.BR .a ), but if both are encountered, the.B .soform is preferred.  When.B \-Bstaticis in effect,.B ldrefuses to use any.B .solibraries it encounters; it continue searchingfor the.B .aform.  Furthermore, an explicit request to load a.B .sofile is treated as an error.  .LPAfter.B ldhas processed all input files and command line options, the form ofthe output it produces is based on the information provided inboth.  .B ldfirst tries to reduce all symbolic references torelative numerical offsets within the executable it is building.  Toperform this \*(lqsymbolic reduction,\*(rq.B ldmust be able to determine that:.RS.TP 3\(buall information relating to the program has been provided, inparticular, no.B .sois to be added at execution time; and/or.TP\(buthe program has an entry point, and symbolic reduction canbe performed for all symbols having definitions existing in thematerial provided..RE.LPIt should be noted that uninitialized \*(lqcommon\*(rq areas (for example, uninitialized C globals) are allocated by thelink editor.I afterit has collected all references.In particular, this allocation can not occur in a program that stillrequires the addition of information contained in a .B \&.sofile, as the missing information may affect the allocation process.  Initialized \*(lqcommons\*(rq however,  are allocated within the executablein which their definition appears..LPAfter.B ldhas performed all the symbolic reductions it can, itattempts to transform all relative references to absolute addresses..B ldis able to perform this \*(lqrelative reduction\*(rqonly if it has been provided.I someabsolute address, either implicitly through the specification of anentry point, or explicitly through.B ldcommand-line options. If, after performing all the reductions it can,there are no further relocations or definitions to perform, then.B ldhas produced a completely linked executable..SS Execution-Time Loading.LPIn the event that one or more reductions can not be completed,the executable will require further link editing at executiontime in order to be usable.  Such executables contain andata structure identified with the symbol.BR _\^_\s-1DYNAMIC\s0 .An incompletely linked \*(lqmain\*(rq program should belinked with a \*(lqbootstrap\*(rq routine that invokes.BR ld.so ,which uses the informationcontained in the main program's .SB _\^_DYNAMICto assemble the restof the executables constituting the entire program.  A standardSun compilation driver (such as .BR cc (1V))automatically includes such a module in each \*(lqmain\*(rq executable..LPWhen.B ld.sois given control on program startup, it finds all.B .sofiles specified when the program was constructed (andall.BR .so 'son which they depend), and loadsthem into the address space.  The algorithm by which such files are foundmimics that used when.B ldis run, and like.BR ld ,can be influenced by the setting of.SB LD_LIBRARY_PATH and any.B \-Loptions specified to.B ldwhen the program was built..B ld.sothen completes allremaining relocations, with the exception of procedure callrelocations; failure to resolve a given non-procedural relocationresults in termination of the program with an appropriate diagnostic..LPProcedure relocations are resolved when the referencing instructionis first executed.  It should be noted that it is possible for\*(lqundefined symbol\*(rq diagnostics to be produced during programexecution if a given target is not defined when referenced..LPAlthough it is possible for binding errors to occur at execution-time,such an occurrence generally indicates something wrong in themaintenance of shared objects..BR ld 's.B "\-assert  nodefinitions"function (on by default) checks at.BR ld -timewhether or not an execution-time binding error would occur..SS Version Handling for Shared Libraries.LPTo allow the independent evolution of.BR .so 'sused as libraries and the programs which use them,.BR ld 'shandling of.B .sofiles found through.B \-loptions involves the retention andmanagement of version control information.  The.B .sofiles used as such \*(lqshared libraries\*(rq are post-fixed with aDewey-decimal format string describing the version of the \*(lqlibrary\*(rqcontained in the file..LPThe first decimal component is called the library's\*(lqmajor version\*(rq number,and the second component its \*(lqminor version\*(rq number.  When.B ldrecords a .B .soused as a library, it also records these twonumbers in the database used by.B ld.soat execution time.  In turn,.B ld.souses these numbers todecide which of multiple versions of a given library is \*(lqbest\*(rq orwhether.I anyof the available versions are acceptable.  Therules are:.RS.TP 3\(buMajor Versions Identical: the major version used atexecution time must exactly match the version found at.BR ld -time.Failure to find an instance of the library with a matching majorversion causes a diagnostic to be issued and the program'sexecution to be terminated..TP\(buHighest Minor Version: in the presence of multiple instances oflibraries that match the desired major version, .B ld.souses the highest minor version it finds.  However, if the highest minorversion found at execution time is less than the version found at.BR ld -time,a warning diagnostic is issued; program execution continues..RE.LPThe semantics of version numbers are such that major version numbersshould be changed whenever interfaces are changed.  Minor versionsshould be changed to reflect compatible updates to libraries, andprograms will silently favor the highest compatible version they canobtain.  .SS Special Symbols.LPA number of symbols have special meanings to .B ldand programs should not define these symbols.  The symbols describedbelow are those actually seen by.BR ld .Note: C and severalother languages prepend symbols they use with .RB ` _ '..TP.BR _etextThe first location after the text of the program..TP.BR _edataThe first location after initialized data..TP.B _endThe first location after all data..br.ne 5.TP.SB _\^_DYNAMICIdentifies an.BR ld -produceddata structure.  It is defined with a non-zero value inexecutables which require execution-time link editing.By convention, if defined, it is thefirst symbol in the symbol table associated with an.B a.outfile..br.ne 8.TP.SB _\^_GLOBAL_OFFSET_TABLE_A position-independent reference to an.BR ld -constructedtable of addresses.  This table is constructed from\*(lqposition-independent\*(rq data references occurring in objectsthat have been assembled with the assembler's.B \-kflag (invoked on behalf of C compilationsperformed with the.B \-picflag).  A related table (for which nosymbol is currently defined) contains a series of transferinstructions and is created from \*(lqposition-independent\*(rq procedurecalls or, if.B \-dpis specified to.BR ld ,a list of undefined symbols..LPSymbols in object files beginning with the letter.B Lare taken to belocal symbols and unless otherwise specified are purged from.B ldoutput files..br.ne 6.SH ENVIRONMENT.TP.SB LD_LIBRARY_PATHA colon-separated list of directories in which to search forlibraries specified with the.B \-loption.  Similar to the .SB PATHenvironment variable..SB LD_LIBRARY_PATHalso affects library searching during execution-time loading, causingthe search to use first those directories found in the environment variable, then any directories specified by.B \-L options, and finally the standard directories.B /usr/liband.BR /usr/local/lib ..SB NOTE:when running a set-user- or set-group-ID program,.BR ld.sowill only search for libraries in directories it \*(lqtrusts\*(rq, whichare.BR /usr/lib ,.BR /usr/5lib ,.BR /usr/local/lib ,and any directories specified within the executable as a result of.B \-Loptions given when the executable was constructed..br.ne 5.TP.SB LD_OPTIONSA default set of options to.BR ld ..SB LD_OPTIONSis interpreted by.B ldjust as though its value had been placed on the command line,immediately following the name used to invoke.BR ld ,as in:.IP.ft Bexample% ld $LD_OPTIONS \fR.\|.\|. \fIother-arguments \fR.\|.\|..LPNote: Environment variable-names beginning with the characters.RB ` LD_ 'are reserved for possible future enhancements to .BR ld ..SH FILES.PD 0.TP 20.B /usr/lib/lib*.alibraries.TP.B lib*.so.vshared libraries.TP.B lib*.sa.vexported, initialized shared library data.TP.B /usr/lib/ld.soexecution-time.B ld.TP.B /usr/lib/*crt*.odefault program bootstraps.TP.B a.outoutput file.TP.B /usr/local/lib.PD.SH SEE ALSO.BR ar (1V),.BR as (1),.BR cc (1V),.BR lorder (1),.BR ranlib (1),.BR strip (1),.BR tsort (1),.BR ldconfig (8).br.ne 8.SH BUGS.LPOptions are being overloaded and are an inappropriate vehicle for describingto.B ldthe wide variety of things it can do. There needs to bea link-editing language which can be used in the more complex situations..LPThe.B \-roption does not properly handle programs assembled withthe.B \-k(position-independent) flag, invoked from.B ccwith.B \-picor.BR \-\s-1PIC\s0 .

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -