[commit: ghc] master: Make Windows linker more robust to unknown sections (620fc6f)

git at git.haskell.org git at git.haskell.org
Sat Oct 3 20:33:48 UTC 2015


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/620fc6f909cd6e51b5613454097ec1c9f323839a/ghc

>---------------------------------------------------------------

commit 620fc6f909cd6e51b5613454097ec1c9f323839a
Author: Tamar Christina <tamar at zhox.com>
Date:   Sat Oct 3 22:28:07 2015 +0200

    Make Windows linker more robust to unknown sections
    
    The Windows Linker has 3 main parts that this patch changes.
    
    1) Identification and classification of sections
    2) Adding of symbols to the symbols tables
    3) Reallocation of sections
    
    1.
    Previously section identification used to be done on a whitelisted
    basis. It was also exclusively being done based on the names of the
    sections. This meant that there was a bit of a cat and mouse game
    between `GCC` and `GHC`. Every time `GCC` added new sections there was a
    good chance `GHC` would break. Luckily this hasn't happened much in the
    past because the `GCC` versions `GHC` used were largely unchanged.
    
    The new code instead treats all new section as `CODE` or `DATA`
    sections, and changes the classifications based on the `Characteristics`
    flag in the PE header. By doing so we no longer have the fragility of
    changing section names. The one exception to this is the `.ctors`
    section, which has no differentiating flag in the PE header, but we know
    we need to treat it as initialization data.
    
    The check to see if the sections are aligned by `4` has been removed.
    The reason is that debug sections often time are `1 aligned` but do have
    relocation symbols. In order to support relocations of `.debug` sections
    this check needs to be gone. Crucially this assumption doesn't seem to
    be in the rest of the code. We only check if there are at least 4 bytes
    to realign further down the road.
    
    2.
    The second loop is iterating of all the symbols in the file and trying
    to add them to the symbols table. Because the classification of the
    sections we did previously are (currently) not available in this phase
    we still have to exclude the sections by hand. If they don't we will
    load in symbols from sections we've explicitly ignored the in # 1. This
    whole part should rewritten to avoid this. But didn't want to do it in
    this commit.
    
    3.
    Finally the sections are relocated. But for some reason the PE files
    contain a Linux relocation constant in them `0x0011` This constant as
    far as I can tell does not come from GHC (or I couldn't find where it's
    being set). I believe this is probably a bug in GAS. But because the
    constant is in the output we have to handle it. I am thus mapping it to
    the constant I think it should be `0x0003`.
    
    Finally, static linking *should* work, but won't. At least not if you
    want to statically link `libgcc` with exceptions support. Doing so would
    require you to link `libgcc` and `libstd++` but also `libmingwex`. The
    problem is that `libmingwex` also defines a lot of symbols that the RTS
    automatically injects into the symbol table. Presumably because they're
    symbols that it needs. like `coshf`. The these symbols are not in a
    section that is declared with weak symbols support. So if we ever want
    to get this working, we should either a) Ask mingw to declare the
    section as such, or b) treat all a imported symbols as being weak.
    Though this doesn't seem like it's a good idea..
    
    Test Plan:
    Running ./validate for both x86 and x86_64
    
    Also running the specific test case for #10672
    
    make TESTS="T10672_x86 T10672_x64"
    
    Reviewed By: ezyang, thomie, austin
    
    Differential Revision: https://phabricator.haskell.org/D1244
    
    GHC Trac Issues: #9907, #10672, #10563


>---------------------------------------------------------------

620fc6f909cd6e51b5613454097ec1c9f323839a
 rts/Linker.c                         | 207 +++++++++++++++--------------------
 testsuite/driver/runtests.py         |   3 +
 testsuite/tests/rts/T10672/Main.hs   |  14 +++
 testsuite/tests/rts/T10672/Makefile  |  11 ++
 testsuite/tests/rts/T10672/Printf.hs |  34 ++++++
 testsuite/tests/rts/T10672/all.T     |  11 ++
 testsuite/tests/rts/T10672/cxxy.cpp  |  23 ++++
 7 files changed, 182 insertions(+), 121 deletions(-)

Diff suppressed because of size. To see it, use:

    git diff-tree --root --patch-with-stat --no-color --find-copies-harder --ignore-space-at-eol --cc 620fc6f909cd6e51b5613454097ec1c9f323839a


More information about the ghc-commits mailing list