summaryrefslogtreecommitdiff
path: root/compiler/main
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/main')
-rw-r--r--compiler/main/DriverPipeline.hs10
-rw-r--r--compiler/main/DynFlags.hs1
-rw-r--r--compiler/main/SysTools.hs15
3 files changed, 26 insertions, 0 deletions
diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs
index b578612ac4..167f78e7f9 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 (
[]
+ -- See Note [No PIE eating when linking]
+ ++ (if sGccSupportsNoPie mySettings
+ then ["-no-pie"]
+ else [])
+
-- 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,11 @@ joinObjectFiles dflags o_files output_fn = do
SysTools.Option "-nostdlib",
SysTools.Option "-Wl,-r"
]
+ -- See Note [No PIE eating while linking] in SysTools
+ ++ (if sGccSupportsNoPie mySettings
+ then [SysTools.Option "-no-pie"]
+ else [])
+
++ (if any (cc ==) [Clang, AppleClang, AppleClang51]
then []
else [SysTools.Option "-nodefaultlibs"])
diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs
index fba188bcea..479b50d0ea 100644
--- a/compiler/main/DynFlags.hs
+++ b/compiler/main/DynFlags.hs
@@ -955,6 +955,7 @@ data Settings = Settings {
sLdSupportsBuildId :: Bool,
sLdSupportsFilelist :: Bool,
sLdIsGnuLd :: Bool,
+ sGccSupportsNoPie :: Bool,
-- commands for particular phases
sPgm_L :: String,
sPgm_P :: (String,[Option]),
diff --git a/compiler/main/SysTools.hs b/compiler/main/SysTools.hs
index 5fb92c8583..38d866e169 100644
--- a/compiler/main/SysTools.hs
+++ b/compiler/main/SysTools.hs
@@ -251,6 +251,7 @@ initSysTools mbMinusB
-- to make that possible, so for now you can't.
gcc_prog <- getSetting "C compiler command"
gcc_args_str <- getSetting "C compiler flags"
+ gccSupportsNoPie <- getBooleanSetting "C compiler supports -no-pie"
cpp_prog <- getSetting "Haskell CPP command"
cpp_args_str <- getSetting "Haskell CPP flags"
let unreg_gcc_args = if targetUnregisterised
@@ -343,6 +344,7 @@ initSysTools mbMinusB
sLdSupportsBuildId = ldSupportsBuildId,
sLdSupportsFilelist = ldSupportsFilelist,
sLdIsGnuLd = ldIsGnuLd,
+ sGccSupportsNoPie = gccSupportsNoPie,
sProgramName = "ghc",
sProjectVersion = cProjectVersion,
sPgm_L = unlit_path,
@@ -1546,6 +1548,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 +1722,10 @@ linkDynLib dflags0 o_files dep_packages
++ [ Option "-o"
, FileOption "" output_fn
]
+ -- See Note [No PIE eating when linking]
+ ++ (if sGccSupportsNoPie (settings dflags)
+ then [Option "-no-pie"]
+ else [])
++ map Option o_files
++ [ Option "-shared" ]
++ map Option bsymbolicFlag