summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorBen Gamari <bgamari.foss@gmail.com>2016-11-10 13:18:09 -0500
committerBen Gamari <ben@smart-cactus.org>2016-11-10 13:21:09 -0500
commitbae4a55b1fb403f610b4b55a1b6fb3f03e9c2026 (patch)
tree114191a265045a30ea86dcaa81e8e9c107fca41a /compiler
parent9030d8e4dc321dbcd32baae33f150b4e7c8ed141 (diff)
downloadhaskell-bae4a55b1fb403f610b4b55a1b6fb3f03e9c2026.tar.gz
Pass -no-pie to GCC
Certain distributions (e.g. Debian and Ubuntu) have enabled PIE be default in their GCC packaging. This breaks our abuse of GCC as a linker which requires that we pass -Wl,-r, which is incompatible with PIE (since the former implies that we are generating a relocatable object file and the latter an executable). Test Plan: Validate Reviewers: hvr, austin Subscribers: rwbarton, thomie, erikd Differential Revision: https://phabricator.haskell.org/D2691 GHC Trac Issues: #12759
Diffstat (limited to 'compiler')
-rw-r--r--compiler/main/DriverPipeline.hs9
-rw-r--r--compiler/main/SysTools.hs13
2 files changed, 22 insertions, 0 deletions
diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs
index b578612ac4..23badbd885 100644
--- a/compiler/main/DriverPipeline.hs
+++ b/compiler/main/DriverPipeline.hs
@@ -1859,6 +1859,11 @@ linkBinary' staticLink dflags o_files dep_packages = do
++ map SysTools.Option (
[]
+#if GCC_SUPPORTS_NO_PIE
+ -- See Note [No PIE eating when linking]
+ ++ ["-no-pie"]
+#endif
+
-- Permit the linker to auto link _symbol to _imp_symbol.
-- This lets us link against DLLs without needing an "import library".
++ (if platformOS platform == OSMinGW32
@@ -2157,6 +2162,10 @@ joinObjectFiles dflags o_files output_fn = do
SysTools.Option "-nostdlib",
SysTools.Option "-Wl,-r"
]
+#if GCC_SUPPORTS_NO_PIE
+ -- See Note [No PIE eating while linking] in SysTools
+ ++ [SysTools.Option "-no-pie"]
+#endif
++ (if any (cc ==) [Clang, AppleClang, AppleClang51]
then []
else [SysTools.Option "-nodefaultlibs"])
diff --git a/compiler/main/SysTools.hs b/compiler/main/SysTools.hs
index 5fb92c8583..82a6383dd5 100644
--- a/compiler/main/SysTools.hs
+++ b/compiler/main/SysTools.hs
@@ -1546,6 +1546,15 @@ linesPlatform xs =
#endif
+{-
+Note [No PIE eating while linking]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+As of 2016 some Linux distributions (e.g. Debian) have started enabling -pie by
+default in their gcc builds. This is incompatible with -r as it implies that we
+are producing an executable. Consequently, we must manually pass -no-pie to gcc
+when joining object files or linking dynamic libraries. See #12759.
+-}
+
linkDynLib :: DynFlags -> [String] -> [InstalledUnitId] -> IO ()
linkDynLib dflags0 o_files dep_packages
= do
@@ -1711,6 +1720,10 @@ linkDynLib dflags0 o_files dep_packages
++ [ Option "-o"
, FileOption "" output_fn
]
+#if GCC_SUPPORTS_NO_PIE
+ -- See Note [No PIE eating when linking]
+ ++ [ Option "-no-pie" ]
+#endif
++ map Option o_files
++ [ Option "-shared" ]
++ map Option bsymbolicFlag