Skip to content
  • Tamar Christina's avatar
    Big-obj support for the Windows runtime linker · 81377e9e
    Tamar Christina authored
    Summary:
    The normal object file on Windows has a limit of `2^16`
    sections that can be in an object-file.
    
    The `big-obj` format raises this to `2^32` sections.
    
    The implementation is made difficult because we now need to support
    two header formats and two section formats that differ only by a single
    element size within each. The element that's different is in the middle
    of the structs and since the structs are used to map regions of memory
    directly, it means we need to know which struct it is when we do the
    mapping or pointer arithmetics.
    
    This is the final Object-Code format which Windows compilers can generate
    which we do not support yet in GHCI. All other major compilers on the platforms
    can produce it and all linkers consume it (bfd and lld).
    
    See http://tinyurl.com/bigobj
    
    This patch abstracts away retrieving the fields to functions which all take
    an struct which describes which object format is currently being parsed.
    These functions are always in-lined as they're small but would looks messy
    being copy-pasted everywhere.
    
    Test Plan:
    ./validate and new test `big-obj`
    
    ```
    Tamar@Rage MINGW64 /r
    $ gcc -c -Wa,-mbig-obj foo.c -o foo.o
    
    Tamar@Rage MINGW64 /r
    $ objdump -h foo.o
    
    foo.o:     file format pe-bigobj-x86-64
    
    Sections:
    Idx Name          Size      VMA               LMA               File off  Algn
      0 .text         00000010  0000000000000000  0000000000000000  00000128  2**4
                      CONTENTS, ALLOC, LOAD, READONLY, CODE
      1 .data         00000000  0000000000000000  0000000000000000  00000000  2**4
                      ALLOC, LOAD, DATA
      2 .bss          00000000  0000000000000000  0000000000000000  00000000  2**4
                      ALLOC
      3 .xdata        00000008  0000000000000000  0000000000000000  00000138  2**2
                      CONTENTS, ALLOC, LOAD, READONLY, DATA
      4 .pdata        0000000c  0000000000000000  0000000000000000  00000140  2**2
                      CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA
      5 .rdata$zzz    00000030  0000000000000000  0000000000000000  0000014c  2**4
                      CONTENTS, ALLOC, LOAD, READONLY, DATA
    
    Tamar@Rage MINGW64 /r
    $ echo main | ~/ghc/inplace/bin/ghc-stage2.exe --interactive bar.hs foo.o
    GHCi, version 8.3.20170430: http://www.haskell.org/ghc/  :? for help
    [1 of 1] Compiling Main             ( bar.hs, interpreted )
    Ok, modules loaded: Main.
    *Main> 17
    *Main> Leaving GHCi.
    ```
    
    Reviewers: austin, bgamari, erikd, simonmar
    
    Subscribers: awson, rwbarton, thomie, #ghc_windows_task_force
    
    GHC Trac Issues: #13815
    
    Differential Revision: https://phabricator.haskell.org/D3523
    81377e9e