diff options
-rw-r--r-- | compiler/cmm/CLabel.hs | 15 | ||||
-rw-r--r-- | compiler/main/DynFlags.hs | 4 | ||||
-rw-r--r-- | compiler/nativeGen/PIC.hs | 13 | ||||
-rw-r--r-- | docs/users_guide/8.6.1-notes.rst | 5 | ||||
-rw-r--r-- | docs/users_guide/phases.rst | 20 | ||||
-rw-r--r-- | testsuite/tests/ghci/scripts/T9293.stdout | 4 | ||||
-rw-r--r-- | testsuite/tests/ghci/scripts/ghci024.stdout | 1 | ||||
-rw-r--r-- | testsuite/tests/ghci/scripts/ghci057.stdout | 4 |
8 files changed, 48 insertions, 18 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 diff --git a/docs/users_guide/8.6.1-notes.rst b/docs/users_guide/8.6.1-notes.rst index 17617ac61a..1e3f509843 100644 --- a/docs/users_guide/8.6.1-notes.rst +++ b/docs/users_guide/8.6.1-notes.rst @@ -56,6 +56,11 @@ Compiler - GHC now supports British spelling of :extension:`GeneralizedNewtypeDeriving`. +- The code-generation effects of :ghc-flag:`-dynamic` can now be + enabled independently by the flag + :ghc-flag:`-fexternal-dynamic-refs`. If you don't know why you might + need this, you don't need it. + Runtime system ~~~~~~~~~~~~~~ diff --git a/docs/users_guide/phases.rst b/docs/users_guide/phases.rst index ad9daf1279..a2c25c79eb 100644 --- a/docs/users_guide/phases.rst +++ b/docs/users_guide/phases.rst @@ -580,6 +580,15 @@ Options affecting code generation Windows, position-independent code is never used so the flag is a no-op on that platform. +.. ghc-flag:: -fexternal-dynamic-refs + :shortdesc: Generate code for linking against dynamic libraries + :type: dynamic + :category: codegen + + When generating code, assume that entities imported from a + different module might be dynamically linked. This flag is enabled + automatically by :ghc-flag:`-dynamic`. + .. ghc-flag:: -fPIE :shortdesc: Generate code for a position-independent executable (where available) :type: dynamic @@ -596,12 +605,11 @@ Options affecting code generation :category: codegen :noindex: - When generating code, assume that entities imported from a different - package will be dynamically linked. This can reduce code size - tremendously, but may slow-down cross-package calls of non-inlined - functions. There can be some complications combining :ghc-flag:`-shared` - with this flag relating to linking in the RTS under Linux. See - :ghc-ticket:`10352`. + Build code for dynamic linking. This can reduce code size + tremendously, but may slow-down cross-module calls of non-inlined + functions. There can be some complications combining + :ghc-flag:`-shared` with this flag relating to linking in the RTS + under Linux. See :ghc-ticket:`10352`. Note that using this option when linking causes GHC to link against shared libraries. diff --git a/testsuite/tests/ghci/scripts/T9293.stdout b/testsuite/tests/ghci/scripts/T9293.stdout index c5be11aa58..2e5adc404c 100644 --- a/testsuite/tests/ghci/scripts/T9293.stdout +++ b/testsuite/tests/ghci/scripts/T9293.stdout @@ -6,6 +6,7 @@ with the following modifiers: GHCi-specific dynamic flag settings: other dynamic, non-language, flag settings: -fno-diagnostics-show-caret + -fexternal-dynamic-refs -fignore-optim-changes -fignore-hpc-changes -fno-ghci-history @@ -24,6 +25,7 @@ with the following modifiers: GHCi-specific dynamic flag settings: other dynamic, non-language, flag settings: -fno-diagnostics-show-caret + -fexternal-dynamic-refs -fignore-optim-changes -fignore-hpc-changes -fno-ghci-history @@ -41,6 +43,7 @@ with the following modifiers: GHCi-specific dynamic flag settings: other dynamic, non-language, flag settings: -fno-diagnostics-show-caret + -fexternal-dynamic-refs -fignore-optim-changes -fignore-hpc-changes -fno-ghci-history @@ -60,6 +63,7 @@ with the following modifiers: GHCi-specific dynamic flag settings: other dynamic, non-language, flag settings: -fno-diagnostics-show-caret + -fexternal-dynamic-refs -fignore-optim-changes -fignore-hpc-changes -fno-ghci-history diff --git a/testsuite/tests/ghci/scripts/ghci024.stdout b/testsuite/tests/ghci/scripts/ghci024.stdout index 1247616719..f38393bad4 100644 --- a/testsuite/tests/ghci/scripts/ghci024.stdout +++ b/testsuite/tests/ghci/scripts/ghci024.stdout @@ -7,6 +7,7 @@ with the following modifiers: GHCi-specific dynamic flag settings: other dynamic, non-language, flag settings: -fno-diagnostics-show-caret + -fexternal-dynamic-refs -fignore-optim-changes -fignore-hpc-changes -fno-ghci-history diff --git a/testsuite/tests/ghci/scripts/ghci057.stdout b/testsuite/tests/ghci/scripts/ghci057.stdout index c5be11aa58..2e5adc404c 100644 --- a/testsuite/tests/ghci/scripts/ghci057.stdout +++ b/testsuite/tests/ghci/scripts/ghci057.stdout @@ -6,6 +6,7 @@ with the following modifiers: GHCi-specific dynamic flag settings: other dynamic, non-language, flag settings: -fno-diagnostics-show-caret + -fexternal-dynamic-refs -fignore-optim-changes -fignore-hpc-changes -fno-ghci-history @@ -24,6 +25,7 @@ with the following modifiers: GHCi-specific dynamic flag settings: other dynamic, non-language, flag settings: -fno-diagnostics-show-caret + -fexternal-dynamic-refs -fignore-optim-changes -fignore-hpc-changes -fno-ghci-history @@ -41,6 +43,7 @@ with the following modifiers: GHCi-specific dynamic flag settings: other dynamic, non-language, flag settings: -fno-diagnostics-show-caret + -fexternal-dynamic-refs -fignore-optim-changes -fignore-hpc-changes -fno-ghci-history @@ -60,6 +63,7 @@ with the following modifiers: GHCi-specific dynamic flag settings: other dynamic, non-language, flag settings: -fno-diagnostics-show-caret + -fexternal-dynamic-refs -fignore-optim-changes -fignore-hpc-changes -fno-ghci-history |