More more ld-related settings into the settings file
authorIan Lynagh <ian@well-typed.com>
Sun, 5 Aug 2012 20:28:20 +0000 (21:28 +0100)
committerIan Lynagh <ian@well-typed.com>
Sun, 5 Aug 2012 20:28:20 +0000 (21:28 +0100)
Related to #4862

compiler/ghc.mk
compiler/main/DriverPipeline.hs
compiler/main/DynFlags.hs
compiler/main/SysTools.lhs
configure.ac
distrib/configure.ac.in
settings.in

index 8ddf73a..de191ea 100644 (file)
@@ -99,12 +99,6 @@ endif
        @echo 'cLeadingUnderscore    = "$(LeadingUnderscore)"'              >> $@
        @echo 'cRAWCPP_FLAGS         :: String'                             >> $@
        @echo 'cRAWCPP_FLAGS         = "$(RAWCPP_FLAGS)"'                   >> $@
-       @echo 'cLdHasNoCompactUnwind :: String'                             >> $@
-       @echo 'cLdHasNoCompactUnwind = "$(LdHasNoCompactUnwind)"'           >> $@
-       @echo 'cLdIsGNULd            :: String'                             >> $@
-       @echo 'cLdIsGNULd            = "$(LdIsGNULd)"'                      >> $@
-       @echo 'cLdHasBuildId         :: String'                             >> $@
-       @echo 'cLdHasBuildId         = "$(LdHasBuildId)"'                   >> $@
        @echo 'cGHC_DRIVER_DIR       :: String'                             >> $@
        @echo 'cGHC_DRIVER_DIR       = "$(GHC_DRIVER_DIR)"'                 >> $@
        @echo 'cGHC_UNLIT_PGM        :: String'                             >> $@
index 3d6f681..5dd24c4 100644 (file)
@@ -1655,6 +1655,7 @@ getHCFilePackages filename =
 linkBinary :: DynFlags -> [FilePath] -> [PackageId] -> IO ()
 linkBinary dflags o_files dep_packages = do
     let platform = targetPlatform dflags
+        mySettings = settings dflags
         verbFlags = getVerbFlags dflags
         output_fn = exeFileName dflags
 
@@ -1767,7 +1768,7 @@ linkBinary dflags o_files dep_packages = do
                       -- like
                       --     ld: warning: could not create compact unwind for .LFB3: non-standard register 5 being saved in prolog
                       -- on x86.
-                      ++ (if cLdHasNoCompactUnwind == "YES"    &&
+                      ++ (if sLdSupportsCompactUnwind mySettings &&
                              platformOS   platform == OSDarwin &&
                              platformArch platform `elem` [ArchX86, ArchX86_64]
                           then ["-Wl,-no_compact_unwind"]
@@ -2089,7 +2090,8 @@ hsSourceCppOpts =
 
 joinObjectFiles :: DynFlags -> [FilePath] -> FilePath -> IO ()
 joinObjectFiles dflags o_files output_fn = do
-  let ld_r args = SysTools.runLink dflags ([
+  let mySettings = settings dflags
+      ld_r args = SysTools.runLink dflags ([
                             SysTools.Option "-nostdlib",
                             SysTools.Option "-nodefaultlibs",
                             SysTools.Option "-Wl,-r"
@@ -2100,20 +2102,18 @@ joinObjectFiles dflags o_files output_fn = do
                          ++ (if platformArch (targetPlatform dflags) == ArchSPARC
                                 then [SysTools.Option "-Wl,-no-relax"]
                                 else [])
-                         ++ [
-                            SysTools.Option ld_build_id,
-                            -- SysTools.Option ld_x_flag,
-                            SysTools.Option "-o",
-                            SysTools.FileOption "" output_fn ]
+                         ++ map SysTools.Option ld_build_id
+                         ++ [ SysTools.Option "-o",
+                              SysTools.FileOption "" output_fn ]
                          ++ args)
 
       -- suppress the generation of the .note.gnu.build-id section,
       -- which we don't need and sometimes causes ld to emit a
       -- warning:
-      ld_build_id | cLdHasBuildId == "YES"  = "-Wl,--build-id=none"
-                  | otherwise               = ""
+      ld_build_id | sLdSupportsBuildId mySettings = ["-Wl,--build-id=none"]
+                  | otherwise                     = []
 
-  if cLdIsGNULd == "YES"
+  if sLdIsGnuLd mySettings
      then do
           script <- newTempName dflags "ldscript"
           writeFile script $ "INPUT(" ++ unwords o_files ++ ")"
index 67681fd..c422980 100644 (file)
@@ -672,6 +672,9 @@ data Settings = Settings {
   sRawSettings           :: [(String, String)],
   sExtraGccViaCFlags     :: [String],
   sSystemPackageConfig   :: FilePath,
+  sLdSupportsCompactUnwind :: Bool,
+  sLdSupportsBuildId       :: Bool,
+  sLdIsGnuLd               :: Bool,
   -- commands for particular phases
   sPgm_L                 :: String,
   sPgm_P                 :: (String,[Option]),
index 4bf63fa..0928927 100644 (file)
@@ -192,6 +192,11 @@ initSysTools mbMinusB
                                          _ ->
                                              xs
                             Nothing -> pgmError ("No entry for " ++ show key ++ " in " ++ show settingsFile)
+           getBooleanSetting key = case lookup key mySettings of
+                                   Just "YES" -> return True
+                                   Just "NO" -> return False
+                                   Just xs -> pgmError ("Bad value for " ++ show key ++ ": " ++ show xs)
+                                   Nothing -> pgmError ("No entry for " ++ show key ++ " in " ++ show settingsFile)
            readSetting key = case lookup key mySettings of
                              Just xs ->
                                  case maybeRead xs of
@@ -213,6 +218,9 @@ initSysTools mbMinusB
        gcc_prog <- getSetting "C compiler command"
        gcc_args_str <- getSetting "C compiler flags"
        let gcc_args = map Option (words gcc_args_str)
+       ldSupportsCompactUnwind <- getBooleanSetting "ld supports compact unwind"
+       ldSupportsBuildId       <- getBooleanSetting "ld supports build-id"
+       ldIsGnuLd               <- getBooleanSetting "ld is GNU ld"
        perl_path <- getSetting "perl command"
 
        let pkgconfig_path = installed "package.conf.d"
@@ -280,6 +288,9 @@ initSysTools mbMinusB
                     sRawSettings    = mySettings,
                     sExtraGccViaCFlags = words myExtraGccViaCFlags,
                     sSystemPackageConfig = pkgconfig_path,
+                    sLdSupportsCompactUnwind = ldSupportsCompactUnwind,
+                    sLdSupportsBuildId       = ldSupportsBuildId,
+                    sLdIsGnuLd               = ldIsGnuLd,
                     sPgm_L   = unlit_path,
                     sPgm_P   = (cpp_prog, cpp_args),
                     sPgm_F   = "",
index c8e6ea5..397e8a5 100644 (file)
@@ -546,6 +546,10 @@ FP_CC_LLVM_BACKEND
 
 FP_PROG_LD_HashSize31
 FP_PROG_LD_ReduceMemoryOverheads
+FP_PROG_LD_IS_GNU
+FP_PROG_LD_BUILD_ID
+FP_PROG_LD_NO_COMPACT_UNWIND
+
 
 FPTOOLS_SET_C_LD_FLAGS([target],[CFLAGS],[LDFLAGS],[IGNORE_LINKER_LD_FLAGS],[CPPFLAGS])
 FPTOOLS_SET_C_LD_FLAGS([build],[CONF_CC_OPTS_STAGE0],[CONF_GCC_LINKER_OPTS_STAGE0],[CONF_LD_LINKER_OPTS_STAGE0],[CONF_CPP_OPTS_STAGE0])
@@ -830,11 +834,6 @@ FPTOOLS_FLOAT_WORD_ORDER_BIGENDIAN
 dnl ** check for leading underscores in symbol names
 FP_LEADING_UNDERSCORE
 
-dnl ** check for ld, whether it has an -x option, and if it is GNU ld
-FP_PROG_LD_IS_GNU
-FP_PROG_LD_BUILD_ID
-FP_PROG_LD_NO_COMPACT_UNWIND
-
 FP_VISIBILITY_HIDDEN
 
 dnl ** check for librt
index 8cb57c4..d1ef5d5 100644 (file)
@@ -72,6 +72,9 @@ AC_PROG_CPP
 
 FP_PROG_LD_HashSize31
 FP_PROG_LD_ReduceMemoryOverheads
+FP_PROG_LD_IS_GNU
+FP_PROG_LD_BUILD_ID
+FP_PROG_LD_NO_COMPACT_UNWIND
 
 #
 dnl ** Check gcc version and flags we need to pass it **
index d6245d6..dbf15fd 100644 (file)
@@ -2,6 +2,9 @@
  ("C compiler command", "@SettingsCCompilerCommand@"),
  ("C compiler flags", "@SettingsCCompilerFlags@"),
  ("ld flags", "@SettingsLdFlags@"),
+ ("ld supports compact unwind", "@LdHasNoCompactUnwind@"),
+ ("ld supports build-id", "@LdHasBuildId@"),
+ ("ld is GNU ld", "@LdIsGNULd@"),
  ("ar command", "@SettingsArCommand@"),
  ("ar flags", "@ArArgs@"),
  ("ar supports at file", "@ArSupportsAtFile@"),