[Git][ghc/ghc][wip/toolchain-selection] 3 commits: Remove configure checks of GNUnoexecStack and ident directive
Rodrigo Mesquita (@alt-romes)
gitlab at gitlab.haskell.org
Fri May 12 15:23:22 UTC 2023
Rodrigo Mesquita pushed to branch wip/toolchain-selection at Glasgow Haskell Compiler / GHC
Commits:
35b2ead0 by Rodrigo Mesquita at 2023-05-12T15:22:50+01:00
Remove configure checks of GNUnoexecStack and ident directive
And fix bug in ghc-toolchain respective code
- - - - -
64d59e52 by Rodrigo Mesquita at 2023-05-12T15:44:50+01:00
Rip out more from hadrians system.config.in
- - - - -
e26b6d28 by Rodrigo Mesquita at 2023-05-12T16:23:15+01:00
Configure CLink supports response files
- - - - -
8 changed files:
- distrib/configure.ac.in
- hadrian/cfg/system.config.in
- hadrian/src/Rules/Generate.hs
- − m4/fp_ld_supports_response_files.m4
- m4/fptools_set_haskell_platform_vars.m4
- utils/ghc-toolchain/Main.hs
- utils/ghc-toolchain/src/GHC/Toolchain/PlatformDetails.hs
- utils/ghc-toolchain/src/GHC/Toolchain/Tools/Link.hs
Changes:
=====================================
distrib/configure.ac.in
=====================================
@@ -181,23 +181,6 @@ dnl May need to use gcc to find platform details.
dnl --------------------------------------------------------------
FPTOOLS_SET_HASKELL_PLATFORM_VARS([Build])
-FPTOOLS_SET_HASKELL_PLATFORM_VARS([Host])
-AC_SUBST(HaskellHostArch)
-AC_SUBST(HaskellHostOs)
-
-FPTOOLS_SET_HASKELL_PLATFORM_VARS([Target])
-AC_SUBST(HaskellTargetArch)
-AC_SUBST(HaskellTargetOs)
-
-GHC_SUBSECTIONS_VIA_SYMBOLS
-AC_SUBST(TargetHasSubsectionsViaSymbols)
-
-GHC_IDENT_DIRECTIVE
-AC_SUBST(TargetHasIdentDirective)
-
-GHC_GNU_NONEXEC_STACK
-AC_SUBST(TargetHasGnuNonexecStack)
-
dnl ** See whether cc supports --target=<triple> and set
dnl CONF_CC_OPTS_STAGE[12] accordingly.
FP_CC_SUPPORTS_TARGET([$CC], [CONF_CC_OPTS_STAGE1], [CONF_CXX_OPTS_STAGE1], [CONF_GCC_LINK_OPTS_STAGE1])
=====================================
hadrian/cfg/system.config.in
=====================================
@@ -6,18 +6,13 @@
#===================
alex = @AlexCmd@
-ar = @ArCmd@
autoreconf = @AutoreconfCmd@
cc = @CC@
happy = @HappyCmd@
hs-cpp = @HaskellCPPCmd@
-ld = @LdCmd@
make = @MakeCmd@
-nm = @NmCmd@
-merge-objects = @MergeObjsCmd@
system-merge-objects = @LD_STAGE0@
objdump = @ObjdumpCmd@
-ranlib = @REAL_RANLIB_CMD@
sphinx-build = @SPHINXBUILD@
system-ar = @AR_STAGE0@
system-cc = @CC_STAGE0@
@@ -39,9 +34,7 @@ python = @PythonCmd@
# Information about builders:
#============================
-ar-supports-at-file = @ArSupportsAtFile@
system-ar-supports-at-file = @ArSupportsAtFile_STAGE0@
-ar-supports-dash-l = @ArSupportsDashL@
system-ar-supports-dash-l = @ArSupportsDashL_STAGE0@
cc-llvm-backend = @CcLlvmBackend@
hs-cpp-args = @HaskellCPPArgs@
@@ -49,8 +42,6 @@ hs-cpp-args = @HaskellCPPArgs@
# Build options:
#===============
-ghc-unregisterised = @Unregisterised@
-tables-next-to-code = @TablesNextToCode@
use-libffi-for-adjustors = @UseLibffiForAdjustors@
ghc-source-path = @hardtop@
leading-underscore = @LeadingUnderscore@
@@ -67,16 +58,12 @@ host-platform = @HostPlatform@
host-arch = @HostArch_CPP@
host-os = @HostOS_CPP@
host-vendor = @HostVendor_CPP@
-host-os-haskell = @HaskellHostOs@
-host-arch-haskell = @HaskellHostArch@
target-platform = @TargetPlatform@
target-platform-full = @TargetPlatformFull@
target-arch = @TargetArch_CPP@
target-os = @TargetOS_CPP@
target-vendor = @TargetVendor_CPP@
-target-os-haskell = @HaskellTargetOs@
-target-arch-haskell = @HaskellTargetArch@
llvm-target = @LLVMTarget_CPP@
cross-compiling = @CrossCompiling@
@@ -137,11 +124,7 @@ conf-merge-objects-args-stage3 = @MergeObjsArgs@
# See Note [tooldir: How GHC finds mingw on Windows]
gcc-extra-via-c-opts = @GccExtraViaCOpts@
-ld-has-no-compact-unwind = @LdHasNoCompactUnwind@
-ld-has-filelist = @LdHasFilelist@
-ld-supports-response-files = @LdSupportsResponseFiles@
ld-is-gnu-ld = @LdIsGNULd@
-ar-args = @ArArgs@
settings-c-compiler-command = @SettingsCCompilerCommand@
settings-cxx-compiler-command = @SettingsCxxCompilerCommand@
@@ -169,11 +152,7 @@ settings-use-distro-mingw = @SettingsUseDistroMINGW@
target-word-size = @TargetWordSize@
target-word-big-endian = @TargetWordBigEndian@
-target-has-gnu-nonexec-stack = @TargetHasGnuNonexecStack@
-target-has-ident-directive = @TargetHasIdentDirective@
-target-has-subsections-via-symbols = @TargetHasSubsectionsViaSymbols@
target-has-libm = @TargetHasLibm@
-target-arm-version = @ARM_ISA@
# Include and library directories:
#=================================
=====================================
hadrian/src/Rules/Generate.hs
=====================================
@@ -9,7 +9,7 @@ import qualified Data.Set as Set
import Base
import qualified Context
import Expression
-import Hadrian.Oracles.TextFile (lookupSystemConfig, queryHostTargetConfig)
+import Hadrian.Oracles.TextFile (lookupSystemConfig, queryTargetTargetConfig)
import Oracles.Flag
import Oracles.ModuleFiles
import Oracles.Setting
@@ -425,14 +425,14 @@ generateSettings = do
, ("Haskell CPP flags", expr $ settingsFileSetting ToolchainSetting_HaskellCPPFlags)
, ("ld command", expr $ settingsFileSetting ToolchainSetting_LdCommand)
, ("ld flags", expr $ settingsFileSetting ToolchainSetting_LdFlags)
- , ("ld supports compact unwind", expr $ lookupSystemConfig "ld-has-no-compact-unwind")
- , ("ld supports filelist", expr $ lookupSystemConfig "ld-has-filelist")
+ , ("ld supports compact unwind", expr $ queryTargetTargetConfig linkSupportsCompactUnwind)
+ , ("ld supports filelist", expr $ queryTargetTargetConfig ldSupportsFilelist)
, ("ld supports response files", expr $ lookupSystemConfig "ld-supports-response-files")
, ("ld is GNU ld", expr $ lookupSystemConfig "ld-is-gnu-ld")
, ("Merge objects command", expr $ settingsFileSetting ToolchainSetting_MergeObjectsCommand)
, ("Merge objects flags", expr $ settingsFileSetting ToolchainSetting_MergeObjectsFlags)
, ("ar command", expr $ settingsFileSetting ToolchainSetting_ArCommand)
- , ("ar flags", expr $ queryHostTargetConfig (unwords . prgFlags . Toolchain.arMkArchive . Toolchain.tgtAr))
+ , ("ar flags", expr $ queryTargetTargetConfig arFlags)
, ("ar supports at file", expr $ yesNo <$> flag ArSupportsAtFile)
, ("ar supports -L", expr $ yesNo <$> flag ArSupportsDashL)
, ("ranlib command", expr $ settingsFileSetting ToolchainSetting_RanlibCommand)
@@ -474,6 +474,11 @@ generateSettings = do
("[" ++ showTuple s)
: ((\s' -> "," ++ showTuple s') <$> ss)
++ ["]"]
+ where
+ ldSupportsFilelist = yesNo . Toolchain.ccLinkSupportsFilelist . Toolchain.tgtCCompilerLink
+ linkSupportsCompactUnwind = yesNo . Toolchain.ccLinkSupportsCompactUnwind . Toolchain.tgtCCompilerLink
+ arFlags = unwords . prgFlags . Toolchain.arMkArchive . Toolchain.tgtAr
+
-- | Generate @Config.hs@ files.
=====================================
m4/fp_ld_supports_response_files.m4 deleted
=====================================
@@ -1,19 +0,0 @@
-# FP_LD_SUPPORTS_RESPONSE_FILES
-# --------------------
-# See if whether we are using a version of ld which supports response files.
-AC_DEFUN([FP_LD_SUPPORTS_RESPONSE_FILES], [
- AC_MSG_CHECKING([whether $LD supports response files])
- echo 'int main(void) {return 0;}' > conftest.c
- "$CC" -c -o conftest.o conftest.c > /dev/null 2>&1
- printf '%q\n' -o conftest conftest.o > args.txt
- if "$LD" -shared @args.txt > /dev/null 2>&1 || "$LD" -dylib @args.txt > /dev/null 2>&1
- then
- LdSupportsResponseFiles=YES
- AC_MSG_RESULT([yes])
- else
- LdSupportsResponseFiles=NO
- AC_MSG_RESULT([no])
- fi
- rm -f conftest.c conftest args.txt
- AC_SUBST(LdSupportsResponseFiles)
-])
=====================================
m4/fptools_set_haskell_platform_vars.m4
=====================================
@@ -40,56 +40,4 @@ AC_DEFUN([GHC_SUBSECTIONS_VIA_SYMBOLS],
AC_MSG_RESULT(no)])
])
-# GHC_IDENT_DIRECTIVE
-# ----------------------------------
-# check for .ident assembler directive
-AC_DEFUN([GHC_IDENT_DIRECTIVE],
-[
- AC_MSG_CHECKING(whether your assembler supports .ident directive)
- dnl See Note [autoconf assembler checks and -flto]
- AC_LINK_IFELSE(
- [AC_LANG_PROGRAM([__asm__ (".ident \"GHC x.y.z\"");], [])],
- [AC_MSG_RESULT(yes)
- TargetHasIdentDirective=YES],
- [AC_MSG_RESULT(no)
- TargetHasIdentDirective=NO])
-])
-
-# GHC_GNU_NONEXEC_STACK
-# ----------------------------------
-# *** check for GNU non-executable stack note support (ELF only)
-# (.section .note.GNU-stack,"", at progbits)
-#
-# This test doesn't work with "gcc -g" in gcc 4.4 (GHC trac #3889:
-# Error: can't resolve `.note.GNU-stack' {.note.GNU-stack section} - `.Ltext0' {.text section}
-# so we empty CFLAGS while running this test
-AC_DEFUN([GHC_GNU_NONEXEC_STACK],
-[
- CFLAGS2="$CFLAGS"
- CFLAGS=
- case $TargetArch in
- arm)
- dnl See #13937.
- progbits="%progbits"
- ;;
- *)
- progbits="@progbits"
- ;;
- esac
- AC_MSG_CHECKING(for GNU non-executable stack support)
- dnl See Note [autoconf assembler checks and -flto]
- AC_LINK_IFELSE(
- dnl the `main` function is placed after the .note.GNU-stack directive
- dnl so we need to ensure that the active segment is correctly set,
- dnl otherwise `main` will be placed in the wrong segment.
- [AC_LANG_PROGRAM([
- __asm__ (".section .note.GNU-stack,\"\",$progbits");
- __asm__ (".section .text");
- ], [0])],
- [AC_MSG_RESULT(yes)
- TargetHasGnuNonexecStack=YES],
- [AC_MSG_RESULT(no)
- TargetHasGnuNonexecStack=NO])
- CFLAGS="$CFLAGS2"
-])
-
+# ROMES:TODO: We can't still remove this because of the DEFINE HAVE_SUBSECTIONS_VIA_SYMBOLS 1, which is used in the rts
=====================================
utils/ghc-toolchain/Main.hs
=====================================
@@ -265,7 +265,6 @@ determineUseLibFFIForAdjustors archOs mb = checking "whether to use libffi for a
Just True ->
-- The user explicitly requested it
pure True
-
_ ->
-- If don't have a native adjustor implementation we use libffi
pure (not . archHasNativeAdjustors $ archOS_arch archOs) -- If we
=====================================
utils/ghc-toolchain/src/GHC/Toolchain/PlatformDetails.hs
=====================================
@@ -124,7 +124,7 @@ checkGnuNonexecStack archOs =
ArchARM{} -> "%progbits" -- See #13937
_ -> "@progbits"
- prog = unlines [ asmStmt ".section .note.GNU-stack,\"\","++progbits
+ prog = unlines [ asmStmt (".section .note.GNU-stack,\"\","++progbits)
, asmStmt ".section .text"
]
=====================================
utils/ghc-toolchain/src/GHC/Toolchain/Tools/Link.hs
=====================================
@@ -21,6 +21,7 @@ data CcLink = CcLink { ccLinkProgram :: Program
, ccLinkSupportsNoPie :: Bool -- Does have to be a separate settings. Sometimes we do want to use PIE
, ccLinkSupportsCompactUnwind :: Bool -- Argument to be made about this being part of the cclink flags
, ccLinkSupportsFilelist :: Bool -- This too
+ , ccLinkSupportsResponseFiles :: Bool
}
deriving (Show, Read, Eq, Ord)
@@ -37,9 +38,10 @@ findCcLink progOpt ldOverride archOs cc readelf = checking "for C compiler for l
ccLinkSupportsNoPie <- checkSupportsNoPie ccLinkProgram
ccLinkSupportsCompactUnwind <- checkSupportsCompactUnwind cc ccLinkProgram
ccLinkSupportsFilelist <- checkSupportsFilelist cc ccLinkProgram
+ ccLinkSupportsResponseFiles <- checkSupportsResponseFiles cc ccLinkProgram
checkBfdCopyBug archOs cc readelf ccLinkProgram
ccLinkProgram <- addPlatformDepLinkFlags archOs cc ccLinkProgram
- return $ CcLink {ccLinkProgram, ccLinkSupportsNoPie, ccLinkSupportsCompactUnwind, ccLinkSupportsFilelist}
+ return $ CcLink {ccLinkProgram, ccLinkSupportsNoPie, ccLinkSupportsCompactUnwind, ccLinkSupportsFilelist, ccLinkSupportsResponseFiles}
-- | Try to convince @cc@ to use a more efficient linker than @bfd.ld@
findLinkFlags :: Maybe Bool -> Cc -> Program -> M Program
@@ -81,7 +83,7 @@ doLinkerSearch = False
#endif
checkSupportsNoPie :: Program -> M Bool
-checkSupportsNoPie ccLink = checking "whether CC supports -no-pie" $
+checkSupportsNoPie ccLink = checking "whether the cc linker supports -no-pie" $
withTempDir $ \dir -> do
let test_c = dir </> "test.c"
writeFile test_c "int main() { return 0; }"
@@ -95,32 +97,26 @@ checkSupportsNoPie ccLink = checking "whether CC supports -no-pie" $
else return True
checkSupportsCompactUnwind :: Cc -> Program -> M Bool
-checkSupportsCompactUnwind cc ccLink = checking "whether ld understands -no_compact_unwind" $
+checkSupportsCompactUnwind cc ccLink = checking "whether the cc linker understands -no_compact_unwind" $
withTempDir $ \dir -> do
- let test_c = dir </> "test.c"
- test_o = dir </> "test.o"
+ let test_o = dir </> "o"
test2_o = dir </> "test2.o"
- writeFile test_c "int foo() { return 0; }"
- callProgram (ccProgram cc) ["-c", test_c]
+
+ compileC cc test_o "int foo() { return 0; }"
+
exitCode <- runProgram ccLink ["-r", "-no_compact_unwind", "-o", test2_o, test_o]
pure $ isSuccess exitCode
-
checkSupportsFilelist :: Cc -> Program -> M Bool
-checkSupportsFilelist cc ccLink = checking "whether ld understands -filelist" $
+checkSupportsFilelist cc ccLink = checking "whether the cc linker understands -filelist" $
withTempDir $ \dir -> do
let test_o = dir </> "test.o"
- test1_c = dir </> "test1.c"
- test2_c = dir </> "test2.c"
test1_o = dir </> "test1.o"
test2_o = dir </> "test2.o"
test_ofiles = dir </> "test.o-files"
- writeFile test1_c "int foo() { return 0; }"
- writeFile test2_c "int bar() { return 0; }"
-
- callProgram (ccProgram cc) ["-c", test1_c]
- callProgram (ccProgram cc) ["-c", test2_c]
+ compileC cc test1_o "int foo() { return 0; }"
+ compileC cc test2_o "int bar() { return 0; }"
writeFile test_ofiles test1_o -- write the filename test1_o to the test_ofiles file
appendFile test_ofiles test2_o -- append the filename test2_o to the test_ofiles file
@@ -129,6 +125,21 @@ checkSupportsFilelist cc ccLink = checking "whether ld understands -filelist" $
pure $ isSuccess exitCode
+checkSupportsResponseFiles :: Cc -> Program -> M Bool
+checkSupportsResponseFiles cc ccLink = checking "whether the cc linker supports response files" $
+ withTempDir $ \dir -> do
+ let test_o = dir </> "test.o"
+ compileC cc test_o "int main(void) {return 0;}"
+
+ let args_txt = dir </> "args.txt"
+ out = dir </> "test"
+ writeFile args_txt (unlines ["-o", out, test_o])
+
+ -- TODO: It'd be good to shortcircuit this logical `or`
+ exitCode1 <- runProgram ccLink ["-shared", "@"++args_txt]
+ exitCode2 <- runProgram ccLink ["-dylib", "@"++args_txt]
+ pure (isSuccess exitCode1 || isSuccess exitCode2)
+
-- | Check whether linking works.
checkLinkWorks :: Cc -> Program -> M ()
checkLinkWorks cc ccLink = withTempDir $ \dir -> do
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/96257cb0cc5d51fe31859d15d9318bac913a86bd...e26b6d285f0709528519c952a668bb82d7c40aff
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/96257cb0cc5d51fe31859d15d9318bac913a86bd...e26b6d285f0709528519c952a668bb82d7c40aff
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230512/3ed0a608/attachment-0001.html>
More information about the ghc-commits
mailing list