summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Miedema <thomasmiedema@gmail.com>2015-12-15 01:07:24 +0100
committerBen Gamari <ben@smart-cactus.org>2015-12-15 01:38:10 +0100
commit6d9c18cb43c1fda95932ef0f640dcf41906a2773 (patch)
tree3c43af6f62a7de90e86e8c29a56bda6fd7ee2bb4
parent05a5ebed916dc00bc5761224047440fefe10485e (diff)
downloadhaskell-6d9c18cb43c1fda95932ef0f640dcf41906a2773.tar.gz
DynFlags: remove Opt_Static
There are currently 2 different ways to test for a static or dynamic build: * Test if WayDyn is in ways * Test if Opt_Static is set The problem is that these can easily go out of sync, especially when using the GHC API. This commit replaces all queries of Opt_Static with an equivalent query of WayDyn. This would have prevented bug #8294 and fixes #11154. Reviewers: hvr, austin, bgamari Reviewed By: austin, bgamari Differential Revision: https://phabricator.haskell.org/D1607 GHC Trac Issues: #10636
-rw-r--r--compiler/cmm/CLabel.hs10
-rw-r--r--compiler/ghci/Linker.hs11
-rw-r--r--compiler/main/DriverPipeline.hs8
-rw-r--r--compiler/main/DynFlags.hs13
-rw-r--r--compiler/main/Packages.hs6
-rw-r--r--compiler/main/SysTools.hs2
-rw-r--r--compiler/nativeGen/PIC.hs14
7 files changed, 30 insertions, 34 deletions
diff --git a/compiler/cmm/CLabel.hs b/compiler/cmm/CLabel.hs
index 2682421e74..a7eb797eeb 100644
--- a/compiler/cmm/CLabel.hs
+++ b/compiler/cmm/CLabel.hs
@@ -868,7 +868,7 @@ labelDynamic :: DynFlags -> UnitId -> Module -> CLabel -> Bool
labelDynamic dflags this_pkg this_mod lbl =
case lbl of
-- is the RTS in a DLL or not?
- RtsLabel _ -> not (gopt Opt_Static dflags) && (this_pkg /= rtsUnitId)
+ RtsLabel _ -> (WayDyn `elem` ways dflags) && (this_pkg /= rtsUnitId)
IdLabel n _ _ -> isDllName dflags this_pkg this_mod n
@@ -876,7 +876,7 @@ labelDynamic dflags this_pkg this_mod lbl =
-- its own shared library.
CmmLabel pkg _ _
| os == OSMinGW32 ->
- not (gopt Opt_Static dflags) && (this_pkg /= pkg)
+ (WayDyn `elem` ways dflags) && (this_pkg /= pkg)
| otherwise ->
True
@@ -894,16 +894,16 @@ labelDynamic dflags this_pkg this_mod lbl =
-- When compiling in the "dyn" way, each package is to be
-- linked into its own DLL.
ForeignLabelInPackage pkgId ->
- (not (gopt Opt_Static dflags)) && (this_pkg /= pkgId)
+ (WayDyn `elem` ways dflags) && (this_pkg /= pkgId)
else -- On Mac OS X and on ELF platforms, false positives are OK,
-- so we claim that all foreign imports come from dynamic
-- libraries
True
- PlainModuleInitLabel m -> not (gopt Opt_Static dflags) && this_pkg /= (moduleUnitId m)
+ PlainModuleInitLabel m -> (WayDyn `elem` ways dflags) && this_pkg /= (moduleUnitId m)
- HpcTicksLabel m -> not (gopt Opt_Static dflags) && this_mod /= m
+ HpcTicksLabel m -> (WayDyn `elem` ways dflags) && this_mod /= m
-- Note that DynamicLinkerLabels do NOT require dynamic linking themselves.
_ -> False
diff --git a/compiler/ghci/Linker.hs b/compiler/ghci/Linker.hs
index d1f226aa9e..7c10fae331 100644
--- a/compiler/ghci/Linker.hs
+++ b/compiler/ghci/Linker.hs
@@ -827,11 +827,8 @@ dynLoadObjs _ pls [] = return pls
dynLoadObjs dflags pls objs = do
let platform = targetPlatform dflags
(soFile, libPath , libName) <- newTempLibName dflags (soExt platform)
- let -- When running TH for a non-dynamic way, we still need to make
- -- -l flags to link against the dynamic libraries, so we turn
- -- Opt_Static off
- dflags1 = gopt_unset dflags Opt_Static
- dflags2 = dflags1 {
+ let
+ dflags2 = dflags {
-- We don't want the original ldInputs in
-- (they're already linked in), but we do want
-- to link against previous dynLoadObjs
@@ -847,6 +844,10 @@ dynLoadObjs dflags pls objs = do
, Option ("-l" ++ l)
])
(temp_sos pls),
+ -- When running TH for a non-dynamic way, we still
+ -- need to make -l flags to link against the dynamic
+ -- libraries, so we need to add WayDyn to ways.
+ --
-- Even if we're e.g. profiling, we still want
-- the vanilla dynamic libraries, so we set the
-- ways / build tag to be just WayDyn.
diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs
index 2e6bac81b8..f3c9eb077a 100644
--- a/compiler/main/DriverPipeline.hs
+++ b/compiler/main/DriverPipeline.hs
@@ -483,7 +483,7 @@ ghcLinkInfoNoteName = "GHC link info"
findHSLib :: DynFlags -> [String] -> String -> IO (Maybe FilePath)
findHSLib dflags dirs lib = do
- let batch_lib_file = if gopt Opt_Static dflags
+ let batch_lib_file = if WayDyn `notElem` ways dflags
then "lib" ++ lib <.> "a"
else mkSOName (targetPlatform dflags) lib
found <- filterM doesFileExist (map (</> batch_lib_file) dirs)
@@ -1417,7 +1417,7 @@ runPhase (RealPhase LlvmLlc) input_fn dflags
-- DATA segment or dyld traps at runtime writing into TEXT: see #7722
rmodel | platformOS (targetPlatform dflags) == OSiOS = "dynamic-no-pic"
| gopt Opt_PIC dflags = "pic"
- | not (gopt Opt_Static dflags) = "dynamic-no-pic"
+ | WayDyn `elem` ways dflags = "dynamic-no-pic"
| otherwise = "static"
tbaa | gopt Opt_LlvmTBAA dflags = "--enable-tbaa=true"
| otherwise = "--enable-tbaa=false"
@@ -1733,7 +1733,7 @@ linkBinary' staticLink dflags o_files dep_packages = do
get_pkg_lib_path_opts l
| osElfTarget (platformOS platform) &&
dynLibLoader dflags == SystemDependent &&
- not (gopt Opt_Static dflags)
+ WayDyn `elem` ways dflags
= let libpath = if gopt Opt_RelativeDynlibPaths dflags
then "$ORIGIN" </>
(l `makeRelativeTo` full_output_fn)
@@ -1753,7 +1753,7 @@ linkBinary' staticLink dflags o_files dep_packages = do
in ["-L" ++ l] ++ rpathlink ++ rpath
| osMachOTarget (platformOS platform) &&
dynLibLoader dflags == SystemDependent &&
- not (gopt Opt_Static dflags) &&
+ WayDyn `elem` ways dflags &&
gopt Opt_RPath dflags
= let libpath = if gopt Opt_RelativeDynlibPaths dflags
then "@loader_path" </>
diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs
index b306253538..7003a6ca88 100644
--- a/compiler/main/DynFlags.hs
+++ b/compiler/main/DynFlags.hs
@@ -423,7 +423,6 @@ data GeneralFlag
| Opt_Ticky_Allocd
| Opt_Ticky_LNE
| Opt_Ticky_Dyn_Thunk
- | Opt_Static
| Opt_RPath
| Opt_RelativeDynlibPaths
| Opt_Hpc
@@ -2162,10 +2161,7 @@ parseDynamicFlagsFull activeFlags cmdline dflags0 args = do
updateWays :: DynFlags -> DynFlags
updateWays dflags
= let theWays = sort $ nub $ ways dflags
- f = if WayDyn `elem` theWays then unSetGeneralFlag'
- else setGeneralFlag'
- in f Opt_Static
- $ dflags {
+ in dflags {
ways = theWays,
buildTag = mkBuildTag (filter (not . wayRTSOnly) theWays),
rtsBuildTag = mkBuildTag theWays
@@ -3303,8 +3299,7 @@ defaultFlags settings
++ (if pc_DYNAMIC_BY_DEFAULT (sPlatformConstants settings)
then wayGeneralFlags platform WayDyn
- else [Opt_Static])
- -- Opt_Static needs to be set if and only if WayDyn is not used (#7478)
+ else [])
where platform = sTargetPlatform settings
@@ -4170,7 +4165,7 @@ picCCOpts dflags
-- correctly. They need to reference data in the Haskell
-- objects, but can't without -fPIC. See
-- http://ghc.haskell.org/trac/ghc/wiki/Commentary/PositionIndependentCode
- | gopt Opt_PIC dflags || not (gopt Opt_Static dflags) ->
+ | gopt Opt_PIC dflags || WayDyn `elem` ways dflags ->
["-fPIC", "-U__PIC__", "-D__PIC__"]
| otherwise -> []
@@ -4302,7 +4297,7 @@ makeDynFlagsConsistent dflags
| hscTarget dflags == HscLlvm &&
not ((arch == ArchX86_64) && (os == OSLinux || os == OSDarwin || os == OSFreeBSD)) &&
not ((isARM arch) && (os == OSLinux)) &&
- (not (gopt Opt_Static dflags) || gopt Opt_PIC dflags)
+ (gopt Opt_PIC dflags || WayDyn `elem` ways dflags)
= if cGhcWithNativeCodeGen == "YES"
then let dflags' = dflags { hscTarget = HscAsm }
warn = "Using native code generator rather than LLVM, as LLVM is incompatible with -fPIC and -dynamic on this platform"
diff --git a/compiler/main/Packages.hs b/compiler/main/Packages.hs
index ac4fae2449..8d0f2a67aa 100644
--- a/compiler/main/Packages.hs
+++ b/compiler/main/Packages.hs
@@ -1157,7 +1157,7 @@ packageHsLibs dflags p = map (mkDynName . addSuffix) (hsLibraries p)
rts_tag = mkBuildTag ways2
mkDynName x
- | gopt Opt_Static dflags = x
+ | WayDyn `notElem` ways dflags = x
| "HS" `isPrefixOf` x =
x ++ '-':programName dflags ++ projectVersion dflags
-- For non-Haskell libraries, we use the name "Cfoo". The .a
@@ -1362,10 +1362,10 @@ unitIdPackageIdString dflags pkg_key
-- | Will the 'Name' come from a dynamically linked library?
isDllName :: DynFlags -> UnitId -> Module -> Name -> Bool
-- Despite the "dll", I think this function just means that
--- the synbol comes from another dynamically-linked package,
+-- the symbol comes from another dynamically-linked package,
-- and applies on all platforms, not just Windows
isDllName dflags _this_pkg this_mod name
- | gopt Opt_Static dflags = False
+ | WayDyn `notElem` ways dflags = False
| Just mod <- nameModule_maybe name
-- Issue #8696 - when GHC is dynamically linked, it will attempt
-- to load the dynamic dependencies of object files at compile
diff --git a/compiler/main/SysTools.hs b/compiler/main/SysTools.hs
index 0e3acb6943..ad717a8a88 100644
--- a/compiler/main/SysTools.hs
+++ b/compiler/main/SysTools.hs
@@ -1545,7 +1545,7 @@ linkDynLib dflags0 o_files dep_packages
| ( osElfTarget (platformOS (targetPlatform dflags)) ||
osMachOTarget (platformOS (targetPlatform dflags)) ) &&
dynLibLoader dflags == SystemDependent &&
- not (gopt Opt_Static dflags)
+ WayDyn `elem` ways dflags
= ["-L" ++ l, "-Wl,-rpath", "-Wl," ++ l]
| otherwise = ["-L" ++ l]
diff --git a/compiler/nativeGen/PIC.hs b/compiler/nativeGen/PIC.hs
index ca556759ed..fa726dddd1 100644
--- a/compiler/nativeGen/PIC.hs
+++ b/compiler/nativeGen/PIC.hs
@@ -167,7 +167,7 @@ cmmMakePicReference dflags lbl
(platformOS $ targetPlatform dflags)
lbl ]
- | (gopt Opt_PIC dflags || not (gopt Opt_Static dflags)) && absoluteLabel lbl
+ | (gopt Opt_PIC dflags || WayDyn `elem` ways dflags) && absoluteLabel lbl
= CmmMachOp (MO_Add (wordWidth dflags))
[ CmmReg (CmmGlobal PicBaseReg)
, CmmLit $ picRelative
@@ -220,14 +220,14 @@ howToAccessLabel
-- To access the function at SYMBOL from our local module, we just need to
-- dereference the local __imp_SYMBOL.
--
--- If Opt_Static is set then we assume that all our code will be linked
+-- If not compiling with -dynamic we assume that all our code will be linked
-- into the same .exe file. In this case we always access symbols directly,
-- and never use __imp_SYMBOL.
--
howToAccessLabel dflags _ OSMinGW32 this_mod _ lbl
-- Assume all symbols will be in the same PE, so just access them directly.
- | gopt Opt_Static dflags
+ | WayDyn `notElem` ways dflags
= AccessDirectly
-- If the target symbol is in another PE we need to access it via the
@@ -317,7 +317,7 @@ howToAccessLabel dflags _ os _ _ _
-- if we don't dynamically link to Haskell code,
-- it actually manages to do so without messing things up.
| osElfTarget os
- , not (gopt Opt_PIC dflags) && gopt Opt_Static dflags
+ , not (gopt Opt_PIC dflags) && WayDyn `notElem` ways dflags
= AccessDirectly
howToAccessLabel dflags arch os this_mod DataReference lbl
@@ -439,7 +439,7 @@ needImportedSymbols dflags arch os
-- PowerPC Linux: -fPIC or -dynamic
| osElfTarget os
, arch == ArchPPC
- = gopt Opt_PIC dflags || not (gopt Opt_Static dflags)
+ = gopt Opt_PIC dflags || WayDyn `elem` ways dflags
-- PowerPC 64 Linux: always
| osElfTarget os
@@ -449,7 +449,7 @@ needImportedSymbols dflags arch os
-- i386 (and others?): -dynamic but not -fPIC
| osElfTarget os
, arch /= ArchPPC_64 ELF_V1 && arch /= ArchPPC_64 ELF_V2
- = not (gopt Opt_Static dflags) && not (gopt Opt_PIC dflags)
+ = WayDyn `elem` ways dflags && not (gopt Opt_PIC dflags)
| otherwise
= False
@@ -650,7 +650,7 @@ pprImportedSymbol _ (Platform { platformOS = OSDarwin }) _
-- section.
-- The "official" GOT mechanism (label@got) isn't intended to be used
-- in position dependent code, so we have to create our own "fake GOT"
--- when not Opt_PIC && not (gopt Opt_Static dflags).
+-- when not Opt_PIC && WayDyn `elem` ways dflags.
--
-- 2) PowerPC Linux is just plain broken.
-- While it's theoretically possible to use GOT offsets larger