Commit a977c965 authored by Simon Marlow's avatar Simon Marlow

Omit unnecessary linker flags

Summary:
This omits -L and -l flags from the linker command line that shouldn't
be necessary because GHC will already add them via the -package-id
flags we pass.

This also reverts part of 90538d86
that rearranges the linker command line and causes some knock-on
problems (see D2618).

Test Plan: validate (need to validate on Windows too)

Reviewers: Phyx, bgamari, niteria, austin, erikd

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D2639

GHC Trac Issues: #12738
parent f46bfeb8
......@@ -910,26 +910,9 @@ runLink dflags args = do
let (p,args0) = pgm_l dflags
args1 = map Option (getOpts dflags opt_l)
args2 = args0 ++ linkargs ++ args1 ++ args
args3 = argFixup args2 []
mb_env <- getGccEnv args3
runSomethingResponseFile dflags ld_filter "Linker" p args3 mb_env
mb_env <- getGccEnv args2
runSomethingResponseFile dflags ld_filter "Linker" p args2 mb_env
where
testLib lib = "-l" `isPrefixOf` lib || ".a" `isSuffixOf` lib
{- GHC is just blindly appending linker arguments from libraries and
the commandline together. This results in very problematic link orders
which will cause incorrect linking. Since we're changing the link
arguments anyway, let's just make sure libraries are last.
This functions moves libraries on the link all the way back
but keeps the order amongst them the same. -}
argFixup [] r = [] ++ r
-- retain any lib in "-o" position.
argFixup (o@(Option "-o"):o'@(FileOption _ _):xs) r = o:o':argFixup xs r
argFixup (o@(Option opt):xs) r = if testLib opt
then argFixup xs (r ++ [o])
else o:argFixup xs r
argFixup (o@(FileOption _ opt):xs) r = if testLib opt
then argFixup xs (r ++ [o])
else o:argFixup xs r
ld_filter = case (platformOS (targetPlatform dflags)) of
OSSolaris2 -> sunos_ld_filter
_ -> id
......
......@@ -44,16 +44,11 @@ $1_$2_DIST_CC_OPTS = \
$$($1_$2_DEP_CC_OPTS) \
$$(SRC_CC_WARNING_OPTS)
ifneq ($$(strip $$($1_$2_DEP_LIB_DIRS_SINGLE_QUOTED)),)
$1_$2_DIST_LD_LIB_DIRS := $$(subst $$(space)',$$(space)-L',$$(space)$$($1_$2_DEP_LIB_DIRS_SINGLE_QUOTED))
endif
$1_$2_DIST_LD_OPTS = \
$$(SRC_LD_OPTS) \
$$($1_LD_OPTS) \
$$($1_$2_LD_OPTS) \
$$($1_$2_DIST_LD_LIB_DIRS) \
$$(foreach opt,$$($1_$2_DEP_EXTRA_LIBS),-l$$(opt)) \
$$($1_$2_DEP_LD_OPTS)
# c.f. Cabal's Distribution.Simple.PreProcess.ppHsc2hs
......
......@@ -399,7 +399,6 @@ generate directory distdir dll0Modules config_args
mkLibraryRelDir l = "libraries/" ++ l ++ "/dist-install/build"
libraryRelDirs = map mkLibraryRelDir transitiveDepNames
wrappedIncludeDirs <- wrap $ forDeps Installed.includeDirs
wrappedLibraryDirs <- wrap libraryDirs
let variablePrefix = directory ++ '_':distdir
mods = map display modules
......@@ -439,11 +438,9 @@ generate directory distdir dll0Modules config_args
variablePrefix ++ "_LD_OPTS = " ++ unwords (ldOptions bi),
variablePrefix ++ "_DEP_INCLUDE_DIRS_SINGLE_QUOTED = " ++ unwords wrappedIncludeDirs,
variablePrefix ++ "_DEP_CC_OPTS = " ++ unwords (forDeps Installed.ccOptions),
variablePrefix ++ "_DEP_LIB_DIRS_SINGLE_QUOTED = " ++ unwords wrappedLibraryDirs,
variablePrefix ++ "_DEP_LIB_DIRS_SEARCHPATH = " ++ mkSearchPath libraryDirs,
variablePrefix ++ "_DEP_LIB_REL_DIRS = " ++ unwords libraryRelDirs,
variablePrefix ++ "_DEP_LIB_REL_DIRS_SEARCHPATH = " ++ mkSearchPath libraryRelDirs,
variablePrefix ++ "_DEP_EXTRA_LIBS = " ++ unwords (forDeps Installed.extraLibraries),
variablePrefix ++ "_DEP_LD_OPTS = " ++ unwords (forDeps Installed.ldOptions),
variablePrefix ++ "_BUILD_GHCI_LIB = " ++ boolToYesNo (withGHCiLib lbi),
"",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment