Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions compiler/GHC/Driver/Config/Linker.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ initFrameworkOpts dflags = FrameworkOpts
}

-- | Initialize linker configuration from DynFlags
initLinkerConfig :: DynFlags -> LinkerConfig
initLinkerConfig dflags =
initLinkerConfig :: DynFlags -> Bool -> LinkerConfig
initLinkerConfig dflags require_cxx =
let
-- see Note [Solaris linker]
ld_filter = case platformOS (targetPlatform dflags) of
Expand All @@ -46,8 +46,13 @@ initLinkerConfig dflags =
(p,pre_args) = pgm_l dflags
post_args = map Option (getOpts dflags opt_l)

-- sneakily switch to C++ compiler when we need C++ standard lib
-- FIXME: ld flags may be totally inappropriate for the C++ compiler?
ld_prog = if require_cxx then pgm_cxx dflags else p


in LinkerConfig
{ linkerProgram = p
{ linkerProgram = ld_prog
, linkerOptionsPre = pre_args
, linkerOptionsPost = post_args
, linkerTempDir = tmpDir dflags
Expand Down
2 changes: 1 addition & 1 deletion compiler/GHC/Driver/Config/StgToJS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ initStgToJSConfig dflags = StgToJSConfig
, csRuntimeAssert = False
-- settings
, csContext = initSDocContext dflags defaultDumpStyle
, csLinkerConfig = initLinkerConfig dflags
, csLinkerConfig = initLinkerConfig dflags False -- no C++ linking
}

-- | Default linker configuration
Expand Down
4 changes: 3 additions & 1 deletion compiler/GHC/Linker/Dynamic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import GHC.Linker.Unit
import GHC.Linker.External
import GHC.Utils.Logger
import GHC.Utils.TmpFs
import GHC.Data.FastString

import Control.Monad (when)
import System.FilePath
Expand Down Expand Up @@ -105,7 +106,8 @@ linkDynLib logger tmpfs dflags0 unit_env o_files dep_packages
pkg_framework_opts <- getUnitFrameworkOpts unit_env (map unitId pkgs)
let framework_opts = getFrameworkOpts (initFrameworkOpts dflags) platform

let linker_config = initLinkerConfig dflags
let require_cxx = any ((==) (PackageName (fsLit "system-cxx-std-lib")) . unitPackageName) pkgs
let linker_config = initLinkerConfig dflags require_cxx

case os of
OSMinGW32 -> do
Expand Down
6 changes: 5 additions & 1 deletion compiler/GHC/Linker/Static.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import GHC.Linker.Static.Utils
import GHC.Driver.Config.Linker
import GHC.Driver.Session

import GHC.Data.FastString

import System.FilePath
import System.Directory
import Control.Monad
Expand Down Expand Up @@ -192,7 +194,9 @@ linkBinary' staticLink logger tmpfs dflags unit_env o_files dep_units = do
OSMinGW32 | gopt Opt_GenManifest dflags -> maybeCreateManifest logger tmpfs dflags output_fn
_ -> return []

let linker_config = initLinkerConfig dflags
let require_cxx = any ((==) (PackageName (fsLit "system-cxx-std-lib")) . unitPackageName) pkgs

let linker_config = initLinkerConfig dflags require_cxx
let link dflags args = do
runLink logger tmpfs linker_config args
-- Make sure to honour -fno-use-rpaths if set on darwin as well; see #20004
Expand Down
21 changes: 21 additions & 0 deletions libraries/system-cxx-std-lib/system-cxx-std-lib.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cabal-version: 2.0
name: system-cxx-std-lib
version: 1.0
license: BSD-3-Clause
synopsis: A placeholder for the system's C++ standard library implementation.
description: Building against C++ libraries requires that the C++ standard
library be included when linking. Typically when compiling a C++
project this is done automatically by the C++ compiler. However,
as GHC uses the C compiler for linking, users needing the C++
standard library must declare this dependency explicitly.
.
This "virtual" package can be used to depend upon the host system's
C++ standard library implementation in a platform agnostic manner.
category: System
build-type: Simple

library
-- empty library: this is just a placeholder for GHC to use to inject C++
-- standard libraries when linking with the C toolchain, or to directly use
-- the C++ toolchain to link.