summaryrefslogtreecommitdiff
path: root/testsuite/tests
diff options
context:
space:
mode:
authorTamar Christina <tamar@zhox.com>2015-10-03 22:28:07 +0200
committerThomas Miedema <thomasmiedema@gmail.com>2015-10-03 22:33:37 +0200
commit620fc6f909cd6e51b5613454097ec1c9f323839a (patch)
treee66ea11cfd2404daf472e5e3c4f96919cd1b42a0 /testsuite/tests
parentd2fb53281da4cf9131cb0937fc66933ede8b6b85 (diff)
downloadhaskell-620fc6f909cd6e51b5613454097ec1c9f323839a.tar.gz
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
Diffstat (limited to 'testsuite/tests')
-rw-r--r--testsuite/tests/rts/T10672/Main.hs14
-rw-r--r--testsuite/tests/rts/T10672/Makefile11
-rw-r--r--testsuite/tests/rts/T10672/Printf.hs34
-rw-r--r--testsuite/tests/rts/T10672/all.T11
-rw-r--r--testsuite/tests/rts/T10672/cxxy.cpp23
5 files changed, 93 insertions, 0 deletions
diff --git a/testsuite/tests/rts/T10672/Main.hs b/testsuite/tests/rts/T10672/Main.hs
new file mode 100644
index 0000000000..eb07b8cfea
--- /dev/null
+++ b/testsuite/tests/rts/T10672/Main.hs
@@ -0,0 +1,14 @@
+-- Copyright (C) 2015, Luke Iannini
+
+{-# LANGUAGE TemplateHaskell #-}
+{-# LANGUAGE ForeignFunctionInterface #-}
+
+module Main where
+import Printf ( pr )
+
+foreign import ccall "talkToCxx" talkToCxx :: IO ()
+
+main :: IO ()
+main = do
+ putStrLn ( $(pr "Hello From Template Haskell!") )
+ talkToCxx
diff --git a/testsuite/tests/rts/T10672/Makefile b/testsuite/tests/rts/T10672/Makefile
new file mode 100644
index 0000000000..5fc458857e
--- /dev/null
+++ b/testsuite/tests/rts/T10672/Makefile
@@ -0,0 +1,11 @@
+TOP=../../..
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
+
+T10672_x64:
+ '$(TEST_HC)' $(TEST_HC_OPTS) -v0 -rtsopts=none -fforce-recomp -lgcc_s_seh-1 -lstdc++-6 \
+ Main.hs Printf.hs cxxy.cpp
+
+T10672_x86:
+ '$(TEST_HC)' $(TEST_HC_OPTS) -v0 -rtsopts=none -fforce-recomp -lgcc_s_dw2-1 -lstdc++-6 \
+ Main.hs Printf.hs cxxy.cpp
diff --git a/testsuite/tests/rts/T10672/Printf.hs b/testsuite/tests/rts/T10672/Printf.hs
new file mode 100644
index 0000000000..046f9a07eb
--- /dev/null
+++ b/testsuite/tests/rts/T10672/Printf.hs
@@ -0,0 +1,34 @@
+-- Copyright (C) 2015, Luke Iannini
+
+{-# LANGUAGE TemplateHaskell #-}
+module Printf where
+
+-- Skeletal printf from the paper:
+-- http://research.microsoft.com/pubs/67015/meta-haskell.pdf
+-- It needs to be in a separate module to the one where
+-- you intend to use it.
+
+-- Import some Template Haskell syntax
+import Language.Haskell.TH
+
+-- Describe a format string
+data Format = D | S | L String
+
+-- Parse a format string. This is left largely to you
+-- as we are here interested in building our first ever
+-- Template Haskell program and not in building printf.
+parse :: String -> [Format]
+parse s = [ L s ]
+
+-- Generate Haskell source code from a parsed representation
+-- of the format string. This code will be spliced into
+-- the module which calls "pr", at compile time.
+gen :: [Format] -> Q Exp
+gen [D] = [| \n -> show n |]
+gen [S] = [| \s -> s |]
+gen [L s] = stringE s
+
+-- Here we generate the Haskell code for the splice
+-- from an input format string.
+pr :: String -> Q Exp
+pr s = gen (parse s)
diff --git a/testsuite/tests/rts/T10672/all.T b/testsuite/tests/rts/T10672/all.T
new file mode 100644
index 0000000000..4367b0a497
--- /dev/null
+++ b/testsuite/tests/rts/T10672/all.T
@@ -0,0 +1,11 @@
+test('T10672_x64', [extra_clean(['cxxy.o',
+ 'Main.exe', 'Main.hi', 'Main.o',
+ 'Printf.o', 'Printf.hi']),
+ [unless(opsys('mingw32'),skip) , unless(arch('x86_64'), skip)]],
+ run_command, ['$MAKE -s --no-print-directory T10672_x64'])
+
+test('T10672_x86', [extra_clean(['cxxy.o',
+ 'Main.exe', 'Main.hi', 'Main.o',
+ 'Printf.o', 'Printf.hi']),
+ [unless(opsys('mingw32'),skip) , unless(arch('i386'), skip)]],
+ run_command, ['$MAKE -s --no-print-directory T10672_x86'])
diff --git a/testsuite/tests/rts/T10672/cxxy.cpp b/testsuite/tests/rts/T10672/cxxy.cpp
new file mode 100644
index 0000000000..815d15399e
--- /dev/null
+++ b/testsuite/tests/rts/T10672/cxxy.cpp
@@ -0,0 +1,23 @@
+// Copyright (C) 2015, Luke Iannini
+
+#include <iostream>
+#include <exception>
+#include <string.h>
+
+// Make sure can call unmangled names from Haskell's FFI
+extern "C" {
+
+int talkToCxx() {
+
+ try {
+ throw 20;
+ }
+ catch (int e) {
+ std::cout << "An exception occurred. Exception Nr. " << e << '\n';
+ }
+
+ std::cout << "Hello From C++!";
+}
+
+
+}