diff options
author | Simon Marlow <smarlow@fb.com> | 2018-02-28 11:03:37 -0800 |
---|---|---|
committer | Simon Marlow <marlowsd@gmail.com> | 2018-03-08 08:36:15 +0000 |
commit | d99a65a80cb671363fa41c826b95b9a89de60878 (patch) | |
tree | f5a659eb0f44e6b2a62b24f39e4b8db36ba321ed /compiler | |
parent | 43fbb905eade2e3e3af67ce944262709763b6578 (diff) | |
download | haskell-d99a65a80cb671363fa41c826b95b9a89de60878.tar.gz |
Add -fexternal-dynamic-refs
Summary:
The `-dynamic` flag does two things:
* In the code generator, it generates code designed to link against
external shared libraries. References outside of the current module
go through platform-specific indirection tables (e.g. the GOT on ELF).
* It enables a "way", which changes which hi files we look
for (`Foo.dyn_hi`) and which libraries we link against.
Some specialised applications want the first of these without the
second. (I could go into detail here but it's probably not all that
important).
This diff splits out the code-generation effects of `-dynamic` from the
"way" parts of its behaviour, via a new flag `-fexternal-dynamic-refs`.
Test Plan: validate
Reviewers: niteria, bgamari, erikd
Subscribers: rwbarton, thomie, carter
Differential Revision: https://phabricator.haskell.org/D4477
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/cmm/CLabel.hs | 15 | ||||
-rw-r--r-- | compiler/main/DynFlags.hs | 4 | ||||
-rw-r--r-- | compiler/nativeGen/PIC.hs | 13 |
3 files changed, 20 insertions, 12 deletions
diff --git a/compiler/cmm/CLabel.hs b/compiler/cmm/CLabel.hs index 9170ee0410..a37ce7e87f 100644 --- a/compiler/cmm/CLabel.hs +++ b/compiler/cmm/CLabel.hs @@ -982,17 +982,19 @@ labelDynamic :: DynFlags -> Module -> CLabel -> Bool labelDynamic dflags this_mod lbl = case lbl of -- is the RTS in a DLL or not? - RtsLabel _ -> (WayDyn `elem` ways dflags) && (this_pkg /= rtsUnitId) + RtsLabel _ -> + (gopt Opt_ExternalDynamicRefs dflags) && (this_pkg /= rtsUnitId) - IdLabel n _ _ -> isDllName dflags this_mod n + IdLabel n _ _ -> + isDllName dflags this_mod n -- When compiling in the "dyn" way, each package is to be linked into -- its own shared library. CmmLabel pkg _ _ | os == OSMinGW32 -> - (WayDyn `elem` ways dflags) && (this_pkg /= pkg) + (gopt Opt_ExternalDynamicRefs dflags) && (this_pkg /= pkg) | otherwise -> - True + gopt Opt_ExternalDynamicRefs dflags LocalBlockLabel _ -> False @@ -1010,14 +1012,15 @@ labelDynamic dflags this_mod lbl = -- When compiling in the "dyn" way, each package is to be -- linked into its own DLL. ForeignLabelInPackage pkgId -> - (WayDyn `elem` ways dflags) && (this_pkg /= pkgId) + (gopt Opt_ExternalDynamicRefs 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 - HpcTicksLabel m -> (WayDyn `elem` ways dflags) && this_mod /= m + HpcTicksLabel m -> + (gopt Opt_ExternalDynamicRefs dflags) && this_mod /= m -- Note that DynamicLinkerLabels do NOT require dynamic linking themselves. _ -> False diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs index 99a798e936..7b9cb13254 100644 --- a/compiler/main/DynFlags.hs +++ b/compiler/main/DynFlags.hs @@ -539,6 +539,7 @@ data GeneralFlag | Opt_PIC -- ^ @-fPIC@ | Opt_PIE -- ^ @-fPIE@ | Opt_PICExecutable -- ^ @-pie@ + | Opt_ExternalDynamicRefs | Opt_SccProfilingOn | Opt_Ticky | Opt_Ticky_Allocd @@ -1564,7 +1565,7 @@ wayGeneralFlags :: Platform -> Way -> [GeneralFlag] wayGeneralFlags _ (WayCustom {}) = [] wayGeneralFlags _ WayThreaded = [] wayGeneralFlags _ WayDebug = [] -wayGeneralFlags _ WayDyn = [Opt_PIC] +wayGeneralFlags _ WayDyn = [Opt_PIC, Opt_ExternalDynamicRefs] -- We could get away without adding -fPIC when compiling the -- modules of a program that is to be linked with -dynamic; the -- program itself does not need to be position-independent, only @@ -3905,6 +3906,7 @@ fFlagsDeps = [ flagSpec "error-spans" Opt_ErrorSpans, flagSpec "excess-precision" Opt_ExcessPrecision, flagSpec "expose-all-unfoldings" Opt_ExposeAllUnfoldings, + flagSpec "external-dynamic-refs" Opt_ExternalDynamicRefs, flagSpec "external-interpreter" Opt_ExternalInterpreter, flagSpec "flat-cache" Opt_FlatCache, flagSpec "float-in" Opt_FloatIn, diff --git a/compiler/nativeGen/PIC.hs b/compiler/nativeGen/PIC.hs index 834aa1b86c..b28e0fc68f 100644 --- a/compiler/nativeGen/PIC.hs +++ b/compiler/nativeGen/PIC.hs @@ -178,7 +178,8 @@ cmmMakePicReference dflags lbl (platformOS $ targetPlatform dflags) lbl ] - | (positionIndependent dflags || WayDyn `elem` ways dflags) && absoluteLabel lbl + | (positionIndependent dflags || gopt Opt_ExternalDynamicRefs dflags) + && absoluteLabel lbl = CmmMachOp (MO_Add (wordWidth dflags)) [ CmmReg (CmmGlobal PicBaseReg) , CmmLit $ picRelative @@ -238,7 +239,7 @@ howToAccessLabel howToAccessLabel dflags _ OSMinGW32 this_mod _ lbl -- Assume all symbols will be in the same PE, so just access them directly. - | WayDyn `notElem` ways dflags + | not (gopt Opt_ExternalDynamicRefs dflags) = AccessDirectly -- If the target symbol is in another PE we need to access it via the @@ -339,7 +340,8 @@ 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 (positionIndependent dflags) && WayDyn `notElem` ways dflags + , not (positionIndependent dflags) && + not (gopt Opt_ExternalDynamicRefs dflags) = AccessDirectly howToAccessLabel dflags arch os this_mod DataReference lbl @@ -470,7 +472,7 @@ needImportedSymbols dflags arch os -- PowerPC Linux: -fPIC or -dynamic | osElfTarget os , arch == ArchPPC - = positionIndependent dflags || WayDyn `elem` ways dflags + = positionIndependent dflags || gopt Opt_ExternalDynamicRefs dflags -- PowerPC 64 Linux: always | osElfTarget os @@ -480,7 +482,8 @@ needImportedSymbols dflags arch os -- i386 (and others?): -dynamic but not -fPIC | osElfTarget os , arch /= ArchPPC_64 ELF_V1 && arch /= ArchPPC_64 ELF_V2 - = WayDyn `elem` ways dflags && not (positionIndependent dflags) + = gopt Opt_ExternalDynamicRefs dflags && + not (positionIndependent dflags) | otherwise = False |