Changes between Version 3 and Version 4 of DynamicLinking


Ignore:
Timestamp:
May 14, 2009 11:37:14 AM (6 years ago)
Author:
duncan
Comment:

redirect to new location

Legend:

Unmodified
Added
Removed
Modified
  • DynamicLinking

    v3 v4  
    1 GHC currently has some support for dynamic linking. 
    2  
    3 GHC can generate position independent code (when given the `-fPIC` flag) on Mac OS X (Darwin/PPC) and PowerPC (32-bit) Linux. Some ''minor'' work is required to make it generate position independent code for x86 ELF platforms (Linux and others). Position independent code is not needed for Windows and PowerPC64 Linux. 
    4  
    5 The `-dynamic` flag does two things: 
    6  
    7   * It causes GHC to assume that everything that is in a different package is in a different shared/dynamic library or binary. 
    8   * It causes GHC to link to dynamic libraries instead of static ones. 
    9  
    10 = Build System = 
    11  
    12 There is now some support in the build system for building dynamic libraries. 
    13  
    14 You need to add a flag when you configure 
    15  
    16 {{{ 
    17 ./configure --enable-shared 
    18 }}} 
    19  
    20 There has been some churn in how dynamic libraries are built since the introduction of the new build system in ghc HEAD (6.11). The only platforms that have been tested with the new system are currently Linux/x86 and Linux/x86-64. The current target is to have GHC itself built statically but to build dynamic libraries such that GHC is capable of linking libraries and programs that use dynamic libraries. 
    21  
    22 If anyone would like to help, report to the cvs-ghc mailing list or directly to [email protected] or [email protected] 
    23  
    24 = Platform-Specific TODO = 
    25  
    26 Profiled code isn't yet really position-independent even when `-fPIC` is specified. Building profiled dynamic libraries therefore fails on Mac OS X (Linux silently accepts relocations - it's just slightly bad for performance). 
    27  
    28 == All ELF systems == 
    29  
    30  * Get the "soname" set, probably based on -o file name. (see [http://www.haskell.org/pipermail/cvs-ghc/2009-May/048567.html this message]) 
    31  * Make sure all shared libs properly record their dependencies, including on the rts (to enable soname chasing) 
    32  * Work out a scheme to enable switching the variant of the rts at link time. 
    33  * Switch default dynamic linking mode to "system dependent" 
    34  * Use an external Main.o rather than having main in the rts (see [http://www.haskell.org/pipermail/cvs-ghc/2009-May/048573.html this message]). 
    35  * In a final link, use the minimum set of libraries, only direct dependencies (assume soname chasing). Avoid -u flags (which are only required for linking base and rts as static libs). 
    36  
    37  * Get GHCi working by loading shared libs 
    38  * Check ld.so loading performance, check quality of hashing. 
    39  * Test that for every rts way, the combination of rts.so + base.so has no unresolved symbols. They should stand alone. Eg check bfd and liberty in debug rts way and check pthread in threaded way. 
    40  
    41 == x86 and powerpc32 ELF/Linux TODO == 
    42  
    43 Summary: -fPIC -fasm works, -fPIC -fvia-C does not work and is unlikely to ever work. 
    44  
    45 Support for `-fPIC` in the mangler is buggy on PowerPC and nonexistent on x86. Due to the strange way that dynamic linking is implemented, it will be very hard to generate position-dependent code that correctly links to (Haskell code in) dynamic libraries without the NCG. 
    46  
    47 == Windows TODO == 
    48  
    49 There used to be a Windows-specific hack involving static closures because Windows doesn't support references to dynamically imported symbols in static data. This hack has bitrotted and needs to be resurrected. The Windows-specific code for supporting `-dynamic` in the NCG has never been tested, to my knowledge. 
    50  
    51 When building a DLL, you have to specify which libraries it depends on; the build system will need to support this. There is a lot of code for building DLLs in the Makefiles, but it probably no longer works and needs to be merged with the new shared library building support. 
    52  
    53 Also, since the last time that DLLs worked with GHC on Windows, the GNU linker has gained a new feature. It can now "auto-import" data from shared libraries, making all the windows-specific hacks unnecessary. However, auto-imported data will prevent all sharing of code between processes, every page of code with a reference to data will get written to at load time. 
    54  
    55 == Darwin TODO == 
    56  
    57 Done. 
    58  
    59 == PowerPC 64-bit Linux TODO == 
    60  
    61 This platform has a great ABI which didn't require anything to be done for dynamic linking to work. Both `-fPIC` and `-dynamic` will just be ignored. 
    62  
    63 = AIX TODO = 
    64  
    65 We don't need any special dynamic linking support here, either, so all that needs to be done is the build system. 
    66  
    67 = Platform-Specific NOTES = 
    68  
    69 The following tables show which combinations of the `-dynamic` and `-fPIC` flags work in which situations on which platforms. The row indicates how a Haskell module is built, and the column indicates what it is being used for. A YES means it should work, a NO means it will fail to link or even crash. 
    70  
    71 == Darwin == 
    72  
    73 ||              ||dynamic libraries||static code||dynamically linked executables||statically linked plugins||dynamically linked plugins|| 
    74 ||(no flags)    ||NO               ||YES        ||NO                            ||NO            ||NO|| 
    75 ||-dynamic      ||NO               ||YES        ||YES                           ||NO            ||NO|| 
    76 ||-fPIC         ||NO               ||YES        ||NO                            ||YES           ||NO|| 
    77 ||-dynamic -fPIC||YES              ||YES        ||YES                           ||YES           ||YES|| 
    78  
    79 == PowerPC 32-Bit and x86 Linux == 
    80  
    81 ||              ||dynamic libraries||static code||dynamically linked executables||statically linked plugins||dynamically linked plugins|| 
    82 ||(no flags)    ||NO               ||YES        ||NO                            ||YES**         ||NO|| 
    83 ||-dynamic      ||NO               ||YES        ||YES*                          ||YES**         ||NO|| 
    84 ||-fPIC         ||NO               ||YES        ||NO                            ||YES           ||NO|| 
    85 ||-dynamic -fPIC||YES              ||YES        ||NO                            ||YES           ||YES|| 
    86  
    87 (*) Dynamically linked executables have to be built via the native code genetator (when using `-O`, specify `-fasm`). 
    88  
    89 (**) Position-dependent code theoretically leads to increased load times and prevents sharing between multiple instances of the code. 
    90  
    91 Via-C compilation with `-fPIC` or `-dynamic` currently doesn't work (not implemented on x86, buggy on PPC). 
    92  
    93 == PowerPC 64-Bit Linux == 
    94  
    95 ||              ||dynamic libraries||static code||dynamically linked executables||statically linked plugins||dynamically linked plugins|| 
    96 ||(no flags)    ||YES              ||YES        ||YES                           ||YES           ||YES|| 
    97 ||-dynamic      ||YES              ||YES        ||YES                           ||YES           ||YES|| 
    98 ||-fPIC         ||YES              ||YES        ||YES                           ||YES           ||YES|| 
    99 ||-dynamic -fPIC||YES              ||YES        ||YES                           ||YES           ||YES|| 
    100  
    101 Now that's a boring table... `-fPIC` is ignored, and `-dynamic` doesn't affect code generation. Everything just works. 
    102  
    103 = x86 Windows = 
    104  
    105 Windows support isn't there yet. In theory, though, this is how it will look like: 
    106  
    107 ||              ||dynamic libraries||static code||dynamically linked executables||statically linked plugins||dynamically linked plugins|| 
    108 ||(no flags)    ||NO               ||YES        ||NO                            ||YES           ||NO|| 
    109 ||-dynamic      ||YES              ||NO         ||YES                           ||NO            ||YES|| 
    110 ||-fPIC         ||NO               ||YES        ||NO                            ||YES           ||NO|| 
    111 ||-dynamic -fPIC||YES              ||NO         ||YES                           ||NO            ||YES|| 
    112  
    113 `-fPIC` is ignored. 
     1[[redirect(wiki:SharedLibraries/PlatformSupport)]]