[Git][ghc/ghc][wip/T23674] 2 commits: ghc-toolchain: Support otool and install_name_tool

Ben Gamari (@bgamari) gitlab at gitlab.haskell.org
Tue Nov 21 21:52:42 UTC 2023



Ben Gamari pushed to branch wip/T23674 at Glasgow Haskell Compiler / GHC


Commits:
4c60f25e by Ben Gamari at 2023-11-21T16:46:17-05:00
ghc-toolchain: Support otool and install_name_tool

Partially addresses #23674.

- - - - -
a74f7b48 by Ben Gamari at 2023-11-21T16:52:25-05:00
configure: Ensure that otool and install-name-tool exist

Otherwise set them to "false" to unambiguously indicate that
they are unavailable.

- - - - -


10 changed files:

- configure.ac
- distrib/configure.ac.in
- hadrian/cfg/default.host.target.in
- hadrian/cfg/default.target.in
- m4/prep_target_file.m4
- utils/ghc-toolchain/exe/Main.hs
- utils/ghc-toolchain/ghc-toolchain.cabal
- utils/ghc-toolchain/src/GHC/Toolchain/Target.hs
- + utils/ghc-toolchain/src/GHC/Toolchain/Tools/InstallNameTool.hs
- + utils/ghc-toolchain/src/GHC/Toolchain/Tools/Otool.hs


Changes:

=====================================
configure.ac
=====================================
@@ -489,13 +489,13 @@ AC_SUBST([StripCmd])
 
 dnl ** Which otool to use on macOS
 dnl --------------------------------------------------------------
-AC_CHECK_TARGET_TOOL([OTOOL], [otool])
+AC_CHECK_TARGET_TOOL([OTOOL], [otool], [false])
 OtoolCmd="$OTOOL"
 AC_SUBST(OtoolCmd)
 
 dnl ** Which install_name_tool to use on macOS
 dnl --------------------------------------------------------------
-AC_CHECK_TARGET_TOOL([INSTALL_NAME_TOOL], [install_name_tool])
+AC_CHECK_TARGET_TOOL([INSTALL_NAME_TOOL], [install_name_tool], [false])
 InstallNameToolCmd="$INSTALL_NAME_TOOL"
 AC_SUBST(InstallNameToolCmd)
 


=====================================
distrib/configure.ac.in
=====================================
@@ -208,13 +208,13 @@ AC_CONFIG_FILES([mk/system-cxx-std-lib-1.0.conf])
 
 dnl ** Which otool to use on macOS
 dnl --------------------------------------------------------------
-AC_CHECK_TARGET_TOOL([OTOOL], [otool])
+AC_CHECK_TARGET_TOOL([OTOOL], [otool], [])
 OtoolCmd="$OTOOL"
 AC_SUBST(OtoolCmd)
 
 dnl ** Which install_name_tool to use on macOS
 dnl --------------------------------------------------------------
-AC_CHECK_TARGET_TOOL([INSTALL_NAME_TOOL], [install_name_tool])
+AC_CHECK_TARGET_TOOL([INSTALL_NAME_TOOL], [install_name_tool], [])
 InstallNameToolCmd="$INSTALL_NAME_TOOL"
 AC_SUBST(InstallNameToolCmd)
 


=====================================
hadrian/cfg/default.host.target.in
=====================================
@@ -35,6 +35,8 @@ Target
 
 , tgtRanlib = Nothing
 , tgtNm = Nm {nmProgram = Program {prgPath = "", prgFlags = []}}
+, tgtOtool = Nothing
+, tgtInstallNameTool = Nothing
 , tgtMergeObjs = Just (MergeObjs {mergeObjsProgram = Program {prgPath = "@LD_STAGE0@", prgFlags = ["-r"]}, mergeObjsSupportsResponseFiles = False})
 , tgtWindres = Nothing
 }


=====================================
hadrian/cfg/default.target.in
=====================================
@@ -35,6 +35,8 @@ Target
 
 , tgtRanlib = Just (Ranlib {ranlibProgram = Program {prgPath = "@RanlibCmd@", prgFlags = []}})
 , tgtNm = Nm {nmProgram = Program {prgPath = "@NmCmd@", prgFlags = []}}
+, tgtOtool = @OtoolCmdMaybe@
+, tgtInstallNameTool = @InstallNameToolCmdMaybe@
 , tgtMergeObjs = @MergeObjsCmdMaybe@
 , tgtWindres = @WindresCmdMaybeProg@
 }


=====================================
m4/prep_target_file.m4
=====================================
@@ -161,6 +161,19 @@ AC_DEFUN([PREP_TARGET_FILE],[
     PREP_LIST([CONF_CXX_OPTS_STAGE0])
     PREP_LIST([CONF_GCC_LINKER_OPTS_STAGE0])
 
+    if test "$OtoolCmd" = "false"; then
+      OtoolCmdMaybe=Nothing
+    else
+      OtoolCmdMaybe="Just (Otool {otoolProgram = Program{prgPath = \"$OtoolCmd\", prgFlags = @<:@@:>@)"
+    fi
+    AC_SUBST([OtoolCmdMaybe])
+
+    if test "$InstallNameToolCmd" = "false"; then
+      InstallNameToolCmdMaybe=Nothing
+    else
+      InstallNameToolCmdMaybe="Just (InstallNameTool {installNameToolProgram = Program{prgPath = \"$InstallNameToolCmd\", prgFlags = @<:@@:>@)"
+    fi
+    AC_SUBST([InstallNameToolCmdMaybe])
 
     if test -z "$MergeObjsCmd"; then
       MergeObjsCmdMaybe=Nothing


=====================================
utils/ghc-toolchain/exe/Main.hs
=====================================
@@ -29,6 +29,8 @@ import GHC.Toolchain.Tools.Link
 import GHC.Toolchain.Tools.Ar
 import GHC.Toolchain.Tools.Ranlib
 import GHC.Toolchain.Tools.Nm
+import GHC.Toolchain.Tools.Otool
+import GHC.Toolchain.Tools.InstallNameTool
 import GHC.Toolchain.Tools.MergeObjs
 import GHC.Toolchain.Tools.Readelf
 import GHC.Toolchain.NormaliseTriple (normaliseTriple)
@@ -47,6 +49,8 @@ data Opts = Opts
     , optAr        :: ProgOpt
     , optRanlib    :: ProgOpt
     , optNm        :: ProgOpt
+    , optOtool     :: ProgOpt
+    , optInstallNameTool :: ProgOpt
     , optReadelf   :: ProgOpt
     , optMergeObjs :: ProgOpt
     , optWindres   :: ProgOpt
@@ -92,6 +96,8 @@ emptyOpts = Opts
     , optAr        = po0
     , optRanlib    = po0
     , optNm        = po0
+    , optOtool     = po0
+    , optInstallNameTool = po0
     , optReadelf   = po0
     , optMergeObjs = po0
     , optWindres   = po0
@@ -117,6 +123,8 @@ _optCcLink  = Lens optCcLink  (\x o -> o {optCcLink=x})
 _optAr      = Lens optAr      (\x o -> o {optAr=x})
 _optRanlib  = Lens optRanlib  (\x o -> o {optRanlib=x})
 _optNm      = Lens optNm      (\x o -> o {optNm=x})
+_optOtool   = Lens optOtool  (\x o -> o {optOtool=x})
+_optInstallNameTool = Lens optInstallNameTool  (\x o -> o {optInstallNameTool=x})
 _optReadelf = Lens optReadelf (\x o -> o {optReadelf=x})
 _optMergeObjs = Lens optMergeObjs (\x o -> o {optMergeObjs=x})
 _optWindres = Lens optWindres (\x o -> o {optWindres=x})
@@ -172,6 +180,8 @@ options =
     , progOpts "ar" "ar archiver" _optAr
     , progOpts "ranlib" "ranlib utility" _optRanlib
     , progOpts "nm" "nm archiver" _optNm
+    , progOpts "otool" "otool utility" _optOtool
+    , progOpts "install-name-tool" "install_name_tool utility" _optInstallNameTool
     , progOpts "readelf" "readelf utility" _optReadelf
     , progOpts "merge-objs" "linker for merging objects" _optMergeObjs
     , progOpts "windres" "windres utility" _optWindres
@@ -407,6 +417,15 @@ mkTarget opts = do
     when (isNothing mergeObjs && not (arSupportsDashL ar)) $
       throwE "Neither a object-merging tool (e.g. ld -r) nor an ar that supports -L is available"
 
+    -- Darwin-specific utilities
+    (otool, installNameTool) <-
+        case archOS_OS archOs of
+          OSDarwin -> do
+            otool <- findOtool (optOtool opts)
+            installNameTool <- findInstallNameTool (optInstallNameTool opts)
+            return (Just otool, Just installNameTool)
+          _ -> return (Nothing, Nothing)
+
     -- Windows-specific utilities
     windres <-
         case archOS_OS archOs of
@@ -448,6 +467,8 @@ mkTarget opts = do
                    , tgtCCompilerLink = ccLink
                    , tgtRanlib = ranlib
                    , tgtNm = nm
+                   , tgtOtool = otool
+                   , tgtInstallNameTool = installNameTool
                    , tgtMergeObjs = mergeObjs
                    , tgtWindres = windres
                    , tgtWordSize


=====================================
utils/ghc-toolchain/ghc-toolchain.cabal
=====================================
@@ -25,6 +25,8 @@ library
                       GHC.Toolchain.Tools.Cxx,
                       GHC.Toolchain.Tools.Cpp,
                       GHC.Toolchain.Tools.Link,
+                      GHC.Toolchain.Tools.Otool,
+                      GHC.Toolchain.Tools.InstallNameTool,
                       GHC.Toolchain.Tools.Nm,
                       GHC.Toolchain.Tools.Ranlib,
                       GHC.Toolchain.Tools.Readelf,


=====================================
utils/ghc-toolchain/src/GHC/Toolchain/Target.hs
=====================================
@@ -14,6 +14,8 @@ import GHC.Toolchain.Tools.Ar
 import GHC.Toolchain.Tools.Ranlib
 import GHC.Toolchain.Tools.Link
 import GHC.Toolchain.Tools.Nm
+import GHC.Toolchain.Tools.Otool
+import GHC.Toolchain.Tools.InstallNameTool
 import GHC.Toolchain.Tools.MergeObjs
 
 data WordSize = WS4 | WS8
@@ -25,8 +27,6 @@ data Endianness = LittleEndian | BigEndian
 -- TODO(#23674): Move the remaining relevant `settings-xxx` to Target:
 -- * llc command
 -- * opt command
--- * install_name_tool
--- * otool command
 --
 -- Those are all things that are put into GHC's settings, and that might be
 -- different across targets
@@ -66,6 +66,8 @@ data Target = Target
     , tgtRanlib :: Maybe Ranlib
     -- ^ N.B. Most @ar@ implementations will add an index by default without @ranlib@ so this is often optional
     , tgtNm :: Nm
+    , tgtOtool :: Maybe Otool
+    , tgtInstallNameTool :: Maybe InstallNameTool
     , tgtMergeObjs :: Maybe MergeObjs
     -- ^ We don't need a merge objects tool if we @Ar@ supports @-L@
 
@@ -115,6 +117,8 @@ instance Show Target where
     , ", tgtAr = " ++ show tgtAr
     , ", tgtRanlib = " ++ show tgtRanlib
     , ", tgtNm = " ++ show tgtNm
+    , ", tgtOtool = " ++ show tgtOtool
+    , ", tgtInstallNameTool = " ++ show tgtInstallNameTool
     , ", tgtMergeObjs = " ++ show tgtMergeObjs
     , ", tgtWindres = " ++ show tgtWindres
     , "}"


=====================================
utils/ghc-toolchain/src/GHC/Toolchain/Tools/InstallNameTool.hs
=====================================
@@ -0,0 +1,18 @@
+{-# LANGUAGE NamedFieldPuns #-}
+{-# LANGUAGE RecordWildCards #-}
+
+module GHC.Toolchain.Tools.InstallNameTool where
+
+import Control.Monad
+
+import GHC.Toolchain.Prelude
+import GHC.Toolchain.Program
+
+newtype InstallNameTool = InstallNameTool { installNameToolProgram :: Program
+                                          }
+    deriving (Show, Read, Eq, Ord)
+
+findInstallNameTool :: ProgOpt -> M InstallNameTool
+findInstallNameTool progOpt = checking "for install_name_tool" $ do
+    installNameToolProgram <- findProgram "install_name_tool utility" progOpt ["install_name_tool"]
+    return InstallNameTool {..}


=====================================
utils/ghc-toolchain/src/GHC/Toolchain/Tools/Otool.hs
=====================================
@@ -0,0 +1,18 @@
+{-# LANGUAGE NamedFieldPuns #-}
+{-# LANGUAGE RecordWildCards #-}
+
+module GHC.Toolchain.Tools.Otool where
+
+import Control.Monad
+
+import GHC.Toolchain.Prelude
+import GHC.Toolchain.Program
+
+newtype Otool = Otool { otoolProgram :: Program
+                      }
+    deriving (Show, Read, Eq, Ord)
+
+findOtool :: ProgOpt -> M Otool
+findOtool progOpt = checking "for otool" $ do
+    otoolProgram <- findProgram "otool utility" progOpt ["otool"]
+    return Otool {..}



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/325a0c5f1a7f34c4b24d7257fd5c95e4d65c4d51...a74f7b48df8e3210a61413133e61f46e1713f21c

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/325a0c5f1a7f34c4b24d7257fd5c95e4d65c4d51...a74f7b48df8e3210a61413133e61f46e1713f21c
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/20231121/15f9df29/attachment-0001.html>


More information about the ghc-commits mailing list