diff options
Diffstat (limited to 'compiler/main/DynFlags.hs')
-rw-r--r-- | compiler/main/DynFlags.hs | 70 |
1 files changed, 56 insertions, 14 deletions
diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs index 48d3402586..690b77ea4a 100644 --- a/compiler/main/DynFlags.hs +++ b/compiler/main/DynFlags.hs @@ -317,6 +317,7 @@ data DynFlag | Opt_DeferTypeErrors | Opt_Parallel | Opt_GranMacros + | Opt_PIC -- output style opts | Opt_PprCaseAsLet @@ -972,7 +973,7 @@ defaultDynFlags mySettings = dirsToClean = panic "defaultDynFlags: No dirsToClean", generatedDumps = panic "defaultDynFlags: No generatedDumps", haddockOptions = Nothing, - flags = IntSet.fromList (map fromEnum defaultFlags), + flags = IntSet.fromList (map fromEnum (defaultFlags (sTargetPlatform mySettings))), warningFlags = IntSet.fromList (map fromEnum standardWarnings), ghciScripts = [], language = Nothing, @@ -1840,6 +1841,8 @@ dynamic_flags = [ ------ Safe Haskell flags ------------------------------------------- , Flag "fpackage-trust" (NoArg setPackageTrust) , Flag "fno-safe-infer" (NoArg (setSafeHaskell Sf_None)) + , Flag "fPIC" (NoArg setFPIC) + , Flag "fno-PIC" (NoArg unSetFPIC) ] ++ map (mkFlag turnOn "" setDynFlag ) negatableFlags ++ map (mkFlag turnOff "no-" unSetDynFlag) negatableFlags @@ -2195,8 +2198,8 @@ xFlags = [ ( "PackageImports", Opt_PackageImports, nop ) ] -defaultFlags :: [DynFlag] -defaultFlags +defaultFlags :: Platform -> [DynFlag] +defaultFlags platform = [ Opt_AutoLinkPackages, Opt_SharedImplib, @@ -2217,6 +2220,14 @@ defaultFlags ++ [f | (ns,f) <- optLevelFlags, 0 `elem` ns] -- The default -O0 options + ++ (case platformOS platform of + OSDarwin -> + case platformArch platform of + ArchX86_64 -> [Opt_PIC] + _ | not opt_Static -> [Opt_PIC] + _ -> [] + _ -> []) + impliedFlags :: [(ExtensionFlag, TurnOnFlag, ExtensionFlag)] impliedFlags = [ (Opt_RankNTypes, turnOn, Opt_ExplicitForAll) @@ -2612,7 +2623,7 @@ setObjTarget l = updM set return dflags HscLlvm | not ((arch == ArchX86_64) && (os == OSLinux || os == OSDarwin)) && - (not opt_Static || opt_PIC) + (not opt_Static || dopt Opt_PIC dflags) -> do addWarn ("Ignoring " ++ flag ++ " as it is incompatible with -fPIC and -dynamic on this platform") return dflags @@ -2623,6 +2634,37 @@ setObjTarget l = updM set os = platformOS platform flag = showHscTargetFlag l +setFPIC :: DynP () +setFPIC = updM set + where + set dflags + | cGhcWithNativeCodeGen == "YES" || cGhcUnregisterised == "YES" + = let platform = targetPlatform dflags + in case hscTarget dflags of + HscLlvm + | (platformArch platform == ArchX86_64) && + (platformOS platform `elem` [OSLinux, OSDarwin]) -> + do addWarn "Ignoring -fPIC as it is incompatible with LLVM on this platform" + return dflags + _ -> return $ dopt_set dflags Opt_PIC + | otherwise + = ghcError $ CmdLineError "-fPIC is not supported on this platform" + +unSetFPIC :: DynP () +unSetFPIC = updM set + where + set dflags + = let platform = targetPlatform dflags + in case platformOS platform of + OSDarwin + | platformArch platform == ArchX86_64 -> + do addWarn "Ignoring -fno-PIC on this platform" + return dflags + _ | not opt_Static -> + do addWarn "Ignoring -fno-PIC as -fstatic is off" + return dflags + _ -> return $ dopt_unset dflags Opt_PIC + setOptLevel :: Int -> DynFlags -> DynP DynFlags setOptLevel n dflags | hscTarget dflags == HscInterpreted && n > 0 @@ -2782,24 +2824,24 @@ picCCOpts dflags -- Don't generate "common" symbols - these are unwanted -- in dynamic libraries. - | opt_PIC -> ["-fno-common", "-U __PIC__", "-D__PIC__"] - | otherwise -> ["-mdynamic-no-pic"] + | dopt Opt_PIC dflags -> ["-fno-common", "-U __PIC__", "-D__PIC__"] + | otherwise -> ["-mdynamic-no-pic"] OSMinGW32 -- no -fPIC for Windows - | opt_PIC -> ["-U __PIC__", "-D__PIC__"] - | otherwise -> [] + | dopt Opt_PIC dflags -> ["-U __PIC__", "-D__PIC__"] + | otherwise -> [] _ -- we need -fPIC for C files when we are compiling with -dynamic, -- otherwise things like stub.c files don't get compiled -- correctly. They need to reference data in the Haskell -- objects, but can't without -fPIC. See -- http://hackage.haskell.org/trac/ghc/wiki/Commentary/PositionIndependentCode - | opt_PIC || not opt_Static -> ["-fPIC", "-U __PIC__", "-D__PIC__"] - | otherwise -> [] + | dopt Opt_PIC dflags || not opt_Static -> ["-fPIC", "-U __PIC__", "-D__PIC__"] + | otherwise -> [] -picPOpts :: [String] -picPOpts - | opt_PIC = ["-U __PIC__", "-D__PIC__"] - | otherwise = [] +picPOpts :: DynFlags -> [String] +picPOpts dflags + | dopt Opt_PIC dflags = ["-U __PIC__", "-D__PIC__"] + | otherwise = [] -- ----------------------------------------------------------------------------- -- Splitting |