From af653b5f8e1d81eeb28ecf730d41e4c83fe76241 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Tue, 16 Jul 2019 11:37:55 -0400 Subject: Only pass -pie, -no-pie when linking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, these flags were passed when both compiling and linking code. However, `-pie` and `-no-pie` are link-time-only options. Usually, this does not cause issues, but when using Clang with `-Werror` set results in errors: clang: error: argument unused during compilation: '-nopie' [-Werror,-Wunused-command-line-argument] This is unused by Clang because this flag has no effect at compile time (it’s called `-nopie` internally by Clang but called `-no-pie` in GHC for compatibility with GCC). Just passing these flags at linking time resolves this. Additionally, update #15319 hack to look for `-pgml` instead. Because of the main change, the value of `-pgmc` does not matter when checking for the workaround of #15319. However, `-pgml` *does* still matter as not all `-pgml` values support `-no-pie`. To cover all potential values, we assume that no custom `-pgml` values support `-no-pie`. This means that we run the risk of not using `-no-pie` when it is otherwise necessary for in auto-hardened toolchains! This could be a problem at some point, but this workaround was already introduced in 8d008b71 and we might as well continue supporting it. Likewise, mark `-pgmc-supports-no-pie` as deprecated and create a new `-pgml-supports-no-pie`. --- compiler/GHC/Driver/Session.hs | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'compiler/GHC/Driver/Session.hs') diff --git a/compiler/GHC/Driver/Session.hs b/compiler/GHC/Driver/Session.hs index 5d194d2d58..b4983d9218 100644 --- a/compiler/GHC/Driver/Session.hs +++ b/compiler/GHC/Driver/Session.hs @@ -177,6 +177,9 @@ module GHC.Driver.Session ( -- ** DynFlags C compiler options picCCOpts, picPOpts, + -- ** DynFlags C linker options + pieCCLDOpts, + -- * Compiler configuration suitable for display to the user compilerInfo, @@ -2060,20 +2063,28 @@ dynamic_flags_deps = [ , make_ord_flag defFlag "pgmF" $ hasArg $ \f -> alterToolSettings $ \s -> s { toolSettings_pgm_F = f } , make_ord_flag defFlag "pgmc" - $ hasArg $ \f -> alterToolSettings $ \s -> s - { toolSettings_pgm_c = f - , -- Don't pass -no-pie with -pgmc - -- (see #15319) - toolSettings_ccSupportsNoPie = False - } - , make_ord_flag defFlag "pgmc-supports-no-pie" - $ noArg $ alterToolSettings $ \s -> s { toolSettings_ccSupportsNoPie = True } + $ hasArg $ \f -> alterToolSettings $ \s -> s { toolSettings_pgm_c = f } + , (Deprecated, defFlag "pgmc-supports-no-pie" + $ noArgM $ \d -> do + deprecate $ "use -pgml-supports-no-pie instead" + pure $ alterToolSettings (\s -> s { toolSettings_ccSupportsNoPie = True }) d) , make_ord_flag defFlag "pgms" (HasArg (\_ -> addWarn "Object splitting was removed in GHC 8.8")) , make_ord_flag defFlag "pgma" $ hasArg $ \f -> alterToolSettings $ \s -> s { toolSettings_pgm_a = (f,[]) } , make_ord_flag defFlag "pgml" - $ hasArg $ \f -> alterToolSettings $ \s -> s { toolSettings_pgm_l = (f,[]) } + $ hasArg $ \f -> alterToolSettings $ \s -> s + { toolSettings_pgm_l = (f,[]) + , -- Don't pass -no-pie with custom -pgml (see #15319). Note + -- that this could break when -no-pie is actually needed. + -- But the CC_SUPPORTS_NO_PIE check only happens at + -- buildtime, and -pgml is a runtime option. A better + -- solution would be running this check for each custom + -- -pgml. + toolSettings_ccSupportsNoPie = False + } + , make_ord_flag defFlag "pgml-supports-no-pie" + $ noArg $ alterToolSettings $ \s -> s { toolSettings_ccSupportsNoPie = True } , make_ord_flag defFlag "pgmdll" $ hasArg $ \f -> alterToolSettings $ \s -> s { toolSettings_pgm_dll = (f,[]) } , make_ord_flag defFlag "pgmwindres" @@ -4414,9 +4425,7 @@ setOptHpcDir arg = upd $ \ d -> d {hpcDir = arg} -- platform. picCCOpts :: DynFlags -> [String] -picCCOpts dflags = pieOpts ++ picOpts - where - picOpts = +picCCOpts dflags = case platformOS (targetPlatform dflags) of OSDarwin -- Apple prefers to do things the other way round. @@ -4444,7 +4453,8 @@ picCCOpts dflags = pieOpts ++ picOpts -- explicit here, see #15847 | otherwise -> ["-fno-PIC"] - pieOpts +pieCCLDOpts :: DynFlags -> [String] +pieCCLDOpts dflags | gopt Opt_PICExecutable dflags = ["-pie"] -- See Note [No PIE when linking] | toolSettings_ccSupportsNoPie (toolSettings dflags) = ["-no-pie"] -- cgit v1.2.1