Ignore:
Timestamp:
Aug 16, 2003, 6:59:22 PM (22 years ago)
Author:
bird
Message:

binutils v2.14 - offical sources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/binutils/ld/ldint.texinfo

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    8585* Emulations::                  How linker emulations are generated
    8686* Emulation Walkthrough::       A Walkthrough of a Typical Emulation
     87* Architecture Specific::       Some Architecture Specific Notes
    8788* GNU Free Documentation License::  GNU Free Documentation License
    8889@end menu
     
    239240
    240241The @file{genscripts.sh} script will invoke the @file{scripttempl}
    241 script 5 or 6 times.  Each time it will set the shell variable
     242script 5 to 8 times.  Each time it will set the shell variable
    242243@code{LD_FLAG} to a different value.  When the linker is run, the
    243244options used will direct it to select a particular script.  (Script
     
    278279with the @code{-shared} option.  The output has an extension of
    279280@file{.xs}.
     281@item c
     282The @file{scripttempl} script is only invoked with @code{LD_FLAG} set to
     283this value if @code{GENERATE_COMBRELOC_SCRIPT} is defined in the
     284@file{emulparams} file or if @code{SCRIPT_NAME} is @code{elf}. The
     285@file{emultempl} script must arrange to use this script at the appropriate
     286time, normally when the linker is invoked with the @code{-z combreloc}
     287option.  The output has an extension of
     288@file{.xc}.
     289@item cshared
     290The @file{scripttempl} script is only invoked with @code{LD_FLAG} set to
     291this value if @code{GENERATE_COMBRELOC_SCRIPT} is defined in the
     292@file{emulparams} file or if @code{SCRIPT_NAME} is @code{elf} and
     293@code{GENERATE_SHLIB_SCRIPT} is defined in the @file{emulparms} file.
     294The @file{emultempl} script must arrange to use this script at the
     295appropriate time, normally when the linker is invoked with the @code{-shared
     296-z combreloc} option.  The output has an extension of @file{.xsc}.
    280297@end table
    281298
     
    301318This will be set to a non-empty string when generating a @code{-shared}
    302319script.
     320
     321@item COMBRELOC
     322This will be set to a non-empty string when generating @code{-z combreloc}
     323scripts to a temporary file name which can be used during script generation.
    303324@end table
    304325
     
    571592
    572593@end itemize
     594
     595@node Architecture Specific
     596@chapter Some Architecture Specific Notes
     597
     598This is the place for notes on the behavior of @code{ld} on
     599specific platforms.  Currently, only Intel x86 is documented (and
     600of that, only the auto-import behavior for DLLs).
     601
     602@menu
     603* ix86::                        Intel x86
     604@end menu
     605
     606@node ix86
     607@section Intel x86
     608
     609@table @emph
     610@code{ld} can create DLLs that operate with various runtimes available
     611on a common x86 operating system.  These runtimes include native (using
     612the mingw "platform"), cygwin, and pw.
     613
     614@item auto-import from DLLs
     615@enumerate
     616@item
     617With this feature on, DLL clients can import variables from DLL
     618without any concern from their side (for example, without any source
     619code modifications).  Auto-import can be enabled using the
     620@code{--enable-auto-import} flag, or disabled via the
     621@code{--disable-auto-import} flag.  Auto-import is disabled by default.
     622
     623@item
     624This is done completely in bounds of the PE specification (to be fair,
     625there's a minor violation of the spec at one point, but in practice
     626auto-import works on all known variants of that common x86 operating
     627system)  So, the resulting DLL can be used with any other PE
     628compiler/linker.
     629
     630@item
     631Auto-import is fully compatible with standard import method, in which
     632variables are decorated using attribute modifiers. Libraries of either
     633type may be mixed together.
     634
     635@item
     636Overhead (space): 8 bytes per imported symbol, plus 20 for each
     637reference to it; Overhead (load time): negligible; Overhead
     638(virtual/physical memory): should be less than effect of DLL
     639relocation.
     640@end enumerate
     641
     642Motivation
     643
     644The obvious and only way to get rid of dllimport insanity is
     645to make client access variable directly in the DLL, bypassing
     646the extra dereference imposed by ordinary DLL runtime linking.
     647I.e., whenever client contains someting like
     648
     649@code{mov dll_var,%eax,}
     650
     651address of dll_var in the command should be relocated to point
     652into loaded DLL. The aim is to make OS loader do so, and than
     653make ld help with that.  Import section of PE made following
     654way: there's a vector of structures each describing imports
     655from particular DLL. Each such structure points to two other
     656parellel vectors: one holding imported names, and one which
     657will hold address of corresponding imported name. So, the
     658solution is de-vectorize these structures, making import
     659locations be sparse and pointing directly into code.
     660
     661Implementation
     662
     663For each reference of data symbol to be imported from DLL (to
     664set of which belong symbols with name <sym>, if __imp_<sym> is
     665found in implib), the import fixup entry is generated. That
     666entry is of type IMAGE_IMPORT_DESCRIPTOR and stored in .idata$3
     667subsection. Each fixup entry contains pointer to symbol's address
     668within .text section (marked with __fuN_<sym> symbol, where N is
     669integer), pointer to DLL name (so, DLL name is referenced by
     670multiple entries), and pointer to symbol name thunk. Symbol name
     671thunk is singleton vector (__nm_th_<symbol>) pointing to
     672IMAGE_IMPORT_BY_NAME structure (__nm_<symbol>) directly containing
     673imported name. Here comes that "om the edge" problem mentioned above:
     674PE specification rambles that name vector (OriginalFirstThunk) should
     675run in parallel with addresses vector (FirstThunk), i.e. that they
     676should have same number of elements and terminated with zero. We violate
     677this, since FirstThunk points directly into machine code. But in
     678practice, OS loader implemented the sane way: it goes thru
     679OriginalFirstThunk and puts addresses to FirstThunk, not something
     680else. It once again should be noted that dll and symbol name
     681structures are reused across fixup entries and should be there
     682anyway to support standard import stuff, so sustained overhead is
     68320 bytes per reference. Other question is whether having several
     684IMAGE_IMPORT_DESCRIPTORS for the same DLL is possible. Answer is yes,
     685it is done even by native compiler/linker (libth32's functions are in
     686fact resident in windows9x kernel32.dll, so if you use it, you have
     687two IMAGE_IMPORT_DESCRIPTORS for kernel32.dll). Yet other question is
     688whether referencing the same PE structures several times is valid.
     689The answer is why not, prohibiting that (detecting violation) would
     690require more work on behalf of loader than not doing it.
     691
     692@end table
    573693
    574694@node GNU Free Documentation License
Note: See TracChangeset for help on using the changeset viewer.