[Git][ghc/ghc][wip/T26521] 2 commits: ghc-toolchain: detect PowerPC 64 bit ABI
Peter Trommler pushed to branch wip/T26521 at Glasgow Haskell Compiler / GHC Commits: 858a19f2 by Peter Trommler at 2025-10-27T10:21:20+01:00 ghc-toolchain: detect PowerPC 64 bit ABI Check preprocessor macro defined for ABI v2 and assume v1 otherwise. Fixes #26521 - - - - - 79f5d7e2 by Peter Trommler at 2025-10-27T10:23:10+01:00 ghc-toolchain: refactor, move lastLine to Utils - - - - - 5 changed files: - utils/ghc-toolchain/ghc-toolchain.cabal - utils/ghc-toolchain/src/GHC/Toolchain/CheckArm.hs - + utils/ghc-toolchain/src/GHC/Toolchain/CheckPower.hs - utils/ghc-toolchain/src/GHC/Toolchain/ParseTriple.hs - utils/ghc-toolchain/src/GHC/Toolchain/Utils.hs Changes: ===================================== utils/ghc-toolchain/ghc-toolchain.cabal ===================================== @@ -21,6 +21,7 @@ library GHC.Toolchain.NormaliseTriple, GHC.Toolchain.CheckArm, GHC.Toolchain.Target, + GHC.Toolchain.CheckPower GHC.Toolchain.Tools.Ar, GHC.Toolchain.Tools.Cc, GHC.Toolchain.Tools.Cxx, ===================================== utils/ghc-toolchain/src/GHC/Toolchain/CheckArm.hs ===================================== @@ -8,6 +8,7 @@ import System.Process import GHC.Platform.ArchOS import GHC.Toolchain.Prelude +import GHC.Toolchain.Utils (lastLine) import GHC.Toolchain.Tools.Cc -- | Awkwardly, ARM triples sometimes contain insufficient information about @@ -75,10 +76,6 @@ findArmIsa cc = do "False" -> return False _ -> throwE $ "unexpected output from test program: " ++ out -lastLine :: String -> String -lastLine "" = "" -lastLine s = last $ lines s - -- | Raspbian unfortunately makes some extremely questionable packaging -- decisions, configuring gcc to compile for ARMv6 despite the fact that the -- Raspberry Pi 4 is ARMv8. As ARMv8 doesn't support all instructions supported ===================================== utils/ghc-toolchain/src/GHC/Toolchain/CheckPower.hs ===================================== @@ -0,0 +1,29 @@ +module GHC.Toolchain.CheckPower ( checkPowerAbi ) where + +import GHC.Platform.ArchOS + +import GHC.Toolchain.Prelude +import GHC.Toolchain.Utils (lastLine) +import GHC.Toolchain.Tools.Cc + +-- 64-Bit ELF V2 ABI Specification, Power Architecture, Revision 1.5 says: +-- A C preprocessor that conforms to this ABI shall predefine the macro +-- _CALL_ELF to have a value of 2 (Section 5.1.4 Predifined Macros). +-- The 64-bit PowerPC ELF Application Binary Interface Supplement 1.9 +-- does not define any macro to identify the ABI. +-- So we check for ABI version 2 and default to ABI version 1. + +checkPowerAbi :: Cc -> M Arch +checkPowerAbi cc = do + checking "POWER ELF ABI" $ do + out <- fmap lastLine $ preprocess cc $ unlines + [ "#if defined(_CALL_ELF) && _CALL_ELF == 2" + , "ELFv2" + , "#else" + , "ELFv1" + , "#endif" + ] + case out of + "ELFv1" -> pure $ ArchPPC_64 ELF_V1 + "ELFv2" -> pure $ ArchPPC_64 ELF_V2 + _ -> throwE $ "unexpected output from test program: " ++ out ===================================== utils/ghc-toolchain/src/GHC/Toolchain/ParseTriple.hs ===================================== @@ -6,6 +6,7 @@ import GHC.Platform.ArchOS import GHC.Toolchain.Prelude import GHC.Toolchain.CheckArm +import GHC.Toolchain.CheckPower import GHC.Toolchain.Tools.Cc -- | Parse a triple `arch-vendor-os` into an 'ArchOS' and a vendor name 'String' @@ -40,7 +41,7 @@ parseArch cc arch = "x86_64" -> pure ArchX86_64 "amd64" -> pure ArchX86_64 "powerpc" -> pure ArchPPC - "powerpc64" -> pure (ArchPPC_64 ELF_V1) + "powerpc64" -> checkPowerAbi cc "powerpc64le" -> pure (ArchPPC_64 ELF_V2) "s390x" -> pure ArchS390X "arm" -> findArmIsa cc ===================================== utils/ghc-toolchain/src/GHC/Toolchain/Utils.hs ===================================== @@ -8,6 +8,7 @@ module GHC.Toolchain.Utils , oneOf , oneOf' , isSuccess + , lastLine ) where import Control.Exception @@ -65,3 +66,6 @@ isSuccess = \case ExitSuccess -> True ExitFailure _ -> False +lastLine :: String -> String +lastLine "" = "" +lastLine s = last $ lines s View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/cf9d958f5ed1bebd6f5ff757a6078c9... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/cf9d958f5ed1bebd6f5ff757a6078c9... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Peter Trommler (@trommler)