Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC

Commits:

17 changed files:

Changes:

  • distrib/configure.ac.in
    ... ... @@ -216,7 +216,7 @@ AC_SUBST([LlvmAsCmd])
    216 216
     
    
    217 217
     dnl We know that `clang` supports `--target` and it is necessary to pass it
    
    218 218
     dnl lest we see #25793.
    
    219
    -if test -z "$LlvmAsFlags" ; then
    
    219
    +if test -z "$LlvmAsFlags" && ! test -z "$LlvmTarget"; then
    
    220 220
         LlvmAsFlags="--target=$LlvmTarget"
    
    221 221
     fi
    
    222 222
     AC_SUBST([LlvmAsFlags])
    

  • hadrian/cfg/default.host.target.in
    ... ... @@ -38,5 +38,10 @@ Target
    38 38
     , tgtRanlib = Nothing
    
    39 39
     , tgtNm = Nm {nmProgram = Program {prgPath = "", prgFlags = []}}
    
    40 40
     , tgtMergeObjs = Just (MergeObjs {mergeObjsProgram = Program {prgPath = "@LD_STAGE0@", prgFlags = ["-r"]}, mergeObjsSupportsResponseFiles = False})
    
    41
    +, tgtLlc = Nothing
    
    42
    +, tgtOpt = Nothing
    
    43
    +, tgtLlvmAs = Nothing
    
    41 44
     , tgtWindres = Nothing
    
    45
    +, tgtOtool = Nothing
    
    46
    +, tgtInstallNameTool = Nothing
    
    42 47
     }

  • hadrian/cfg/default.target.in
    ... ... @@ -38,5 +38,10 @@ Target
    38 38
     , tgtRanlib = Just (Ranlib {ranlibProgram = Program {prgPath = "@RanlibCmd@", prgFlags = []}})
    
    39 39
     , tgtNm = Nm {nmProgram = Program {prgPath = "@NmCmd@", prgFlags = []}}
    
    40 40
     , tgtMergeObjs = @MergeObjsCmdMaybe@
    
    41
    +, tgtLlc = @LlcCmdMaybeProg@
    
    42
    +, tgtOpt = @OptCmdMaybeProg@
    
    43
    +, tgtLlvmAs = @LlvmAsCmdMaybeProg@
    
    41 44
     , tgtWindres = @WindresCmdMaybeProg@
    
    45
    +, tgtOtool = @OtoolCmdMaybeProg@
    
    46
    +, tgtInstallNameTool = @InstallNameToolCmdMaybeProg@
    
    42 47
     }

  • hadrian/cfg/system.config.in
    ... ... @@ -79,13 +79,6 @@ project-git-commit-id = @ProjectGitCommitId@
    79 79
     # generated by configure, to generated being by the build system. Many of these
    
    80 80
     # might become redundant.
    
    81 81
     # See Note [tooldir: How GHC finds mingw on Windows]
    
    82
    -
    
    83
    -settings-otool-command = @SettingsOtoolCommand@
    
    84
    -settings-install_name_tool-command = @SettingsInstallNameToolCommand@
    
    85
    -settings-llc-command = @SettingsLlcCommand@
    
    86
    -settings-opt-command = @SettingsOptCommand@
    
    87
    -settings-llvm-as-command = @SettingsLlvmAsCommand@
    
    88
    -settings-llvm-as-flags = @SettingsLlvmAsFlags@
    
    89 82
     settings-use-distro-mingw = @SettingsUseDistroMINGW@
    
    90 83
     
    
    91 84
     target-has-libm = @TargetHasLibm@
    

  • hadrian/src/Builder.hs
    ... ... @@ -34,7 +34,6 @@ import Base
    34 34
     import Context
    
    35 35
     import Oracles.Flag
    
    36 36
     import Oracles.Setting (setting, Setting(..))
    
    37
    -import Oracles.Setting (settingsFileSetting, ToolchainSetting(..))
    
    38 37
     import Packages
    
    39 38
     
    
    40 39
     import GHC.IO.Encoding (getFileSystemEncoding)
    
    ... ... @@ -240,7 +239,7 @@ instance H.Builder Builder where
    240 239
             Ghc _ st -> do
    
    241 240
                 root <- buildRoot
    
    242 241
                 unlitPath  <- builderPath Unlit
    
    243
    -            distro_mingw <- settingsFileSetting ToolchainSetting_DistroMinGW
    
    242
    +            distro_mingw <- lookupSystemConfig "settings-use-distro-mingw"
    
    244 243
                 libffi_adjustors <- useLibffiForAdjustors
    
    245 244
                 use_system_ffi <- flag UseSystemFfi
    
    246 245
     
    

  • hadrian/src/Oracles/Setting.hs
    ... ... @@ -2,7 +2,6 @@ module Oracles.Setting (
    2 2
         configFile,
    
    3 3
         -- * Settings
    
    4 4
         Setting (..), setting, getSetting,
    
    5
    -    ToolchainSetting (..), settingsFileSetting,
    
    6 5
     
    
    7 6
         -- * Helpers
    
    8 7
         ghcCanonVersion, cmdLineLengthLimit, targetSupportsRPaths, topDirectory,
    
    ... ... @@ -75,25 +74,6 @@ data Setting = CursesIncludeDir
    75 74
                  | BourneShell
    
    76 75
                  | EmsdkVersion
    
    77 76
     
    
    78
    --- TODO compute solely in Hadrian, removing these variables' definitions
    
    79
    --- from aclocal.m4 whenever they can be calculated from other variables
    
    80
    --- already fed into Hadrian.
    
    81
    -
    
    82
    --- | All 'ToolchainSetting's are computed by the ghc-toolchain utility for configuring toolchains.
    
    83
    --- This used to be defined by 'FP_SETTINGS' in aclocal.m4.
    
    84
    ---
    
    85
    --- TODO: We should be able to drop this completely, after moving all the toolchain settings to ghc-toolchain
    
    86
    --- Move to ghc-toolchain and to the Target files generated by configure and ghc-toolchain
    
    87
    --- * First we will get rid of DistroMinGW when we fix the windows build
    
    88
    -data ToolchainSetting
    
    89
    -    = ToolchainSetting_OtoolCommand
    
    90
    -    | ToolchainSetting_InstallNameToolCommand
    
    91
    -    | ToolchainSetting_LlcCommand
    
    92
    -    | ToolchainSetting_OptCommand
    
    93
    -    | ToolchainSetting_LlvmAsCommand
    
    94
    -    | ToolchainSetting_LlvmAsFlags
    
    95
    -    | ToolchainSetting_DistroMinGW
    
    96
    -
    
    97 77
     -- | Look up the value of a 'Setting' in @cfg/system.config@, tracking the
    
    98 78
     -- result.
    
    99 79
     setting :: Setting -> Action String
    
    ... ... @@ -134,20 +114,6 @@ setting key = lookupSystemConfig $ case key of
    134 114
         BourneShell        -> "bourne-shell"
    
    135 115
         EmsdkVersion       -> "emsdk-version"
    
    136 116
     
    
    137
    --- | Look up the value of a 'SettingList' in @cfg/system.config@, tracking the
    
    138
    --- result.
    
    139
    --- See Note [tooldir: How GHC finds mingw on Windows]
    
    140
    --- ROMES:TODO: This should be queryTargetTargetConfig
    
    141
    -settingsFileSetting :: ToolchainSetting -> Action String
    
    142
    -settingsFileSetting key = lookupSystemConfig $ case key of
    
    143
    -    ToolchainSetting_OtoolCommand           -> "settings-otool-command"
    
    144
    -    ToolchainSetting_InstallNameToolCommand -> "settings-install_name_tool-command"
    
    145
    -    ToolchainSetting_LlcCommand             -> "settings-llc-command"
    
    146
    -    ToolchainSetting_OptCommand             -> "settings-opt-command"
    
    147
    -    ToolchainSetting_LlvmAsCommand          -> "settings-llvm-as-command"
    
    148
    -    ToolchainSetting_LlvmAsFlags            -> "settings-llvm-as-flags"
    
    149
    -    ToolchainSetting_DistroMinGW            -> "settings-use-distro-mingw" -- ROMES:TODO: This option doesn't seem to be in ghc-toolchain yet. It corresponds to EnableDistroToolchain
    
    150
    -
    
    151 117
     -- | An expression that looks up the value of a 'Setting' in @cfg/system.config@,
    
    152 118
     -- tracking the result.
    
    153 119
     getSetting :: Setting -> Expr c b String
    

  • hadrian/src/Rules/Generate.hs
    ... ... @@ -424,7 +424,7 @@ bindistRules = do
    424 424
         , interpolateSetting "LlvmMinVersion" LlvmMinVersion
    
    425 425
         , interpolateVar "LlvmTarget" $ getTarget tgtLlvmTarget
    
    426 426
         , interpolateSetting "ProjectVersion" ProjectVersion
    
    427
    -    , interpolateVar "SettingsUseDistroMINGW" $ settingsFileSetting ToolchainSetting_DistroMinGW
    
    427
    +    , interpolateVar "SettingsUseDistroMINGW" $ lookupSystemConfig "settings-use-distro-mingw"
    
    428 428
         , interpolateVar "TablesNextToCode" $ yesNo <$> getTarget tgtTablesNextToCode
    
    429 429
         , interpolateVar "TargetHasLibm" $ lookupSystemConfig "target-has-libm"
    
    430 430
         , interpolateVar "TargetPlatform" $ getTarget targetPlatformTriple
    
    ... ... @@ -508,9 +508,9 @@ generateSettings settingsFile = do
    508 508
             , ("ar flags",            queryTarget arFlags)
    
    509 509
             , ("ar supports at file", queryTarget arSupportsAtFile')
    
    510 510
             , ("ar supports -L",      queryTarget arSupportsDashL')
    
    511
    -        , ("ranlib command", queryTarget ranlibPath)
    
    512
    -        , ("otool command", expr $ settingsFileSetting ToolchainSetting_OtoolCommand)
    
    513
    -        , ("install_name_tool command", expr $ settingsFileSetting ToolchainSetting_InstallNameToolCommand)
    
    511
    +        , ("ranlib command",      queryTarget ranlibPath)
    
    512
    +        , ("otool command",       queryTarget otoolPath)
    
    513
    +        , ("install_name_tool command", queryTarget installNameToolPath)
    
    514 514
             , ("windres command", queryTarget (maybe "/bin/false" prgPath . tgtWindres)) -- TODO: /bin/false is not available on many distributions by default, but we keep it as it were before the ghc-toolchain patch. Fix-me.
    
    515 515
             , ("unlit command", ("$topdir/../bin/" <>) <$> expr (programName (ctx { Context.package = unlit })))
    
    516 516
             , ("cross compiling", expr $ yesNo <$> flag CrossCompiling)
    
    ... ... @@ -525,11 +525,11 @@ generateSettings settingsFile = do
    525 525
             , ("target has libm", expr $  lookupSystemConfig "target-has-libm")
    
    526 526
             , ("Unregisterised", queryTarget (yesNo . tgtUnregisterised))
    
    527 527
             , ("LLVM target", queryTarget tgtLlvmTarget)
    
    528
    -        , ("LLVM llc command", expr $ settingsFileSetting ToolchainSetting_LlcCommand)
    
    529
    -        , ("LLVM opt command", expr $ settingsFileSetting ToolchainSetting_OptCommand)
    
    530
    -        , ("LLVM llvm-as command", expr $ settingsFileSetting ToolchainSetting_LlvmAsCommand)
    
    531
    -        , ("LLVM llvm-as flags", expr $ settingsFileSetting ToolchainSetting_LlvmAsFlags)
    
    532
    -        , ("Use inplace MinGW toolchain", expr $ settingsFileSetting ToolchainSetting_DistroMinGW)
    
    528
    +        , ("LLVM llc command", queryTarget llcPath)
    
    529
    +        , ("LLVM opt command", queryTarget optPath)
    
    530
    +        , ("LLVM llvm-as command", queryTarget llvmAsPath)
    
    531
    +        , ("LLVM llvm-as flags", queryTarget llvmAsFlags)
    
    532
    +        , ("Use inplace MinGW toolchain", expr $ lookupSystemConfig "settings-use-distro-mingw")
    
    533 533
     
    
    534 534
             , ("target RTS linker only supports shared libraries", expr $ yesNo <$> targetRTSLinkerOnlySupportsSharedLibs)
    
    535 535
             , ("Use interpreter", expr $ yesNo <$> ghcWithInterpreter (predStage stage))
    
    ... ... @@ -571,10 +571,16 @@ generateSettings settingsFile = do
    571 571
         linkSupportsFilelist        = yesNo . ccLinkSupportsFilelist . tgtCCompilerLink
    
    572 572
         linkSupportsCompactUnwind   = yesNo . ccLinkSupportsCompactUnwind . tgtCCompilerLink
    
    573 573
         linkIsGnu                   = yesNo . ccLinkIsGnu . tgtCCompilerLink
    
    574
    +    llcPath = maybe "" prgPath . tgtLlc
    
    575
    +    optPath = maybe "" prgPath . tgtOpt
    
    576
    +    llvmAsPath = maybe "" prgPath . tgtLlvmAs
    
    577
    +    llvmAsFlags = escapeArgs . maybe [] prgFlags . tgtLlvmAs
    
    574 578
         arPath  = prgPath . arMkArchive . tgtAr
    
    575 579
         arFlags = escapeArgs . prgFlags . arMkArchive . tgtAr
    
    576 580
         arSupportsAtFile' = yesNo . arSupportsAtFile . tgtAr
    
    577 581
         arSupportsDashL' = yesNo . arSupportsDashL . tgtAr
    
    582
    +    otoolPath = maybe "" prgPath . tgtOtool
    
    583
    +    installNameToolPath = maybe "" prgPath . tgtInstallNameTool
    
    578 584
         ranlibPath  = maybe "" (prgPath . ranlibProgram) . tgtRanlib
    
    579 585
         mergeObjsSupportsResponseFiles' = maybe "NO" (yesNo . mergeObjsSupportsResponseFiles) . tgtMergeObjs
    
    580 586
     
    

  • hadrian/src/Settings/Builders/RunTest.hs
    ... ... @@ -127,9 +127,9 @@ inTreeCompilerArgs stg = do
    127 127
         platform    <- queryTargetTarget targetPlatformTriple
    
    128 128
         wordsize    <- show @Int . (*8) <$> queryTargetTarget (wordSize2Bytes . tgtWordSize)
    
    129 129
     
    
    130
    -    llc_cmd   <- settingsFileSetting ToolchainSetting_LlcCommand
    
    131
    -    llvm_as_cmd <- settingsFileSetting ToolchainSetting_LlvmAsCommand
    
    132
    -    have_llvm <- liftIO (all isJust <$> mapM findExecutable [llc_cmd, llvm_as_cmd])
    
    130
    +    llc_cmd   <- queryTargetTarget tgtLlc
    
    131
    +    llvm_as_cmd <- queryTargetTarget tgtLlvmAs
    
    132
    +    let have_llvm = all isJust [llc_cmd, llvm_as_cmd]
    
    133 133
     
    
    134 134
         top         <- topDirectory
    
    135 135
     
    

  • hadrian/stack.yaml
    1
    -# GHC's configure script reports that GHC versions 9.2 and greater are required
    
    1
    +# GHC's configure script reports that GHC versions 9.6 and greater are required
    
    2 2
     # to build GHC from source.
    
    3
    -resolver: lts-20.26 # GHC 9.2.8
    
    3
    +resolver: lts-22.44 # GHC 9.6.7
    
    4 4
     
    
    5 5
     packages:
    
    6 6
     - '.'
    

  • hadrian/stack.yaml.lock
    ... ... @@ -5,22 +5,57 @@
    5 5
     
    
    6 6
     packages:
    
    7 7
     - completed:
    
    8
    -    hackage: Cabal-3.10.1.0@sha256:6d11adf7847d9734e7b02785ff831b5a0d11536bfbcefd6634b2b08411c63c94,12316
    
    8
    +    hackage: Cabal-3.14.0.0@sha256:604ea78fd41acf5382d3578aad5e90d66065a823fca4207ed144ef209daf3c7f,13720
    
    9 9
         pantry-tree:
    
    10
    -      sha256: 3d175ab2e29f17494599bf5844d0037d01fd04287ac5d50c5c788b0633a8ee6f
    
    11
    -      size: 9223
    
    10
    +      sha256: 9bd496dbb7d0a1bc1e9147cedbede83003c86ceec66c06594fe292710618bc43
    
    11
    +      size: 12219
    
    12 12
       original:
    
    13
    -    hackage: Cabal-3.10.1.0
    
    13
    +    hackage: Cabal-3.14.0.0
    
    14 14
     - completed:
    
    15
    -    hackage: Cabal-syntax-3.10.1.0@sha256:bb835ebab577fd0f9c11dab96210dbb8d68ffc62652576f4b092563c345930e7,7434
    
    15
    +    hackage: Cabal-syntax-3.14.0.0@sha256:6cd7666c675c29981392d031a9ad402f578234b6195a304c886b84510b0c21cd,7380
    
    16 16
         pantry-tree:
    
    17
    -      sha256: bb1e418f0eb0976bbf4f50491ef4f2b737121bb866e22d07cff1de91f199db7e
    
    18
    -      size: 11052
    
    17
    +      sha256: 2aed3c4195554d93ed1e25c4bacdf8eb7f3e006622bbd17a2e27d4bd0de0cd32
    
    18
    +      size: 10977
    
    19 19
       original:
    
    20
    -    hackage: Cabal-syntax-3.10.1.0
    
    20
    +    hackage: Cabal-syntax-3.14.0.0
    
    21
    +- completed:
    
    22
    +    hackage: directory-1.3.9.0@sha256:2490137bb7738bd79392959458ef5f276219ea5ba8a9a56d3e0b06315c1bb917,3307
    
    23
    +    pantry-tree:
    
    24
    +      sha256: cf35b0c2755674f913078c588c88fc169d928ce09f292c648af9f1dbc3167131
    
    25
    +      size: 3386
    
    26
    +  original:
    
    27
    +    hackage: directory-1.3.9.0
    
    28
    +- completed:
    
    29
    +    hackage: file-io-0.1.4@sha256:e3e1866eab82cb28f6a5f28507643da3987008b737e66a3c7398f39f16d824dc,3251
    
    30
    +    pantry-tree:
    
    31
    +      sha256: f5401e2f822eafa465b8c661303275ebcbfd6c0a34a9943379b8f580da64af03
    
    32
    +      size: 858
    
    33
    +  original:
    
    34
    +    hackage: file-io-0.1.4
    
    35
    +- completed:
    
    36
    +    hackage: filepath-1.4.300.2@sha256:24f794247fcb8d26388aaec87b8e3577649f462a744bb09f01e85a60a435d5ab,6128
    
    37
    +    pantry-tree:
    
    38
    +      sha256: 086c1298421eaf07ca46666938bcb750ccbdcf386410e7d597f76d313d3ce98c
    
    39
    +      size: 3998
    
    40
    +  original:
    
    41
    +    hackage: filepath-1.4.300.2
    
    42
    +- completed:
    
    43
    +    hackage: process-1.6.25.0@sha256:092ab61596e914d21983aa2e9206a74c4faa38a5a636446b5c954305821cb496,2749
    
    44
    +    pantry-tree:
    
    45
    +      sha256: bdab416d3c454ad716d4fab1ced490cc75330658c1c7c66a0b6f4b3e5125017b
    
    46
    +      size: 1790
    
    47
    +  original:
    
    48
    +    hackage: process-1.6.25.0
    
    49
    +- completed:
    
    50
    +    hackage: unix-2.8.5.1@sha256:3f702a252a313a7bcb56e3908a14e7f9f1b40e41b7bdc8ae8a9605a1a8686f06,9808
    
    51
    +    pantry-tree:
    
    52
    +      sha256: b961320db69795a16c4ef4eebb0a3e7ddbbbe506fa1e22dde95ee8d8501bfbe5
    
    53
    +      size: 5821
    
    54
    +  original:
    
    55
    +    hackage: unix-2.8.5.1
    
    21 56
     snapshots:
    
    22 57
     - completed:
    
    23
    -    size: 650475
    
    24
    -    url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/20/26.yaml
    
    25
    -    sha256: 5a59b2a405b3aba3c00188453be172b85893cab8ebc352b1ef58b0eae5d248a2
    
    26
    -  original: lts-20.26
    58
    +    sha256: 238fa745b64f91184f9aa518fe04bdde6552533d169b0da5256670df83a0f1a9
    
    59
    +    size: 721141
    
    60
    +    url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/44.yaml
    
    61
    +  original: lts-22.44

  • libraries/template-haskell/changelog.md
    ... ... @@ -12,9 +12,9 @@
    12 12
         `pragSpecInlED`.
    
    13 13
       
    
    14 14
       * Remove the `Language.Haskell.TH.Lib.Internal` module. This module has long been deprecated, and exposes compiler internals.
    
    15
    -    Users should use `Language.Haskell.TH.Lib` instead, which exposes a stable version of this API.
    
    15
    +    Users should use `Language.Haskell.TH.Lib` instead, which exposes a more stable version of this API.
    
    16 16
         
    
    17
    -  * Remove `addrToByteArrayName` and `addrToByteArray` from `Language.Haskell.TH.Syntax`. These were part of the implementation of the `Lift ByteArray` instance and were errornously exported because this module lacked an explicit export list. They have no usages on Hackage.
    
    17
    +  * Remove `addrToByteArrayName` and `addrToByteArray` from `Language.Haskell.TH.Syntax`. These were part of the implementation of the `Lift ByteArray` instance and were accidentally exported because this module lacked an explicit export list. They have no usages on Hackage.
    
    18 18
     
    
    19 19
     ## 2.23.0.0
    
    20 20
     
    

  • m4/fp_settings.m4
    ... ... @@ -136,14 +136,7 @@ AC_DEFUN([FP_SETTINGS],
    136 136
         fi
    
    137 137
     
    
    138 138
         # Mac-only tools
    
    139
    -    if test -z "$OtoolCmd"; then
    
    140
    -        OtoolCmd="otool"
    
    141
    -    fi
    
    142 139
         SettingsOtoolCommand="$OtoolCmd"
    
    143
    -
    
    144
    -    if test -z "$InstallNameToolCmd"; then
    
    145
    -        InstallNameToolCmd="install_name_tool"
    
    146
    -    fi
    
    147 140
         SettingsInstallNameToolCommand="$InstallNameToolCmd"
    
    148 141
     
    
    149 142
         SettingsCCompilerSupportsNoPie="$CONF_GCC_SUPPORTS_NO_PIE"
    

  • m4/ghc_toolchain.m4
    ... ... @@ -107,6 +107,9 @@ AC_DEFUN([FIND_GHC_TOOLCHAIN],
    107 107
         echo "--merge-objs=$MergeObjsCmd" >> acargs
    
    108 108
         echo "--readelf=$READELF" >> acargs
    
    109 109
         echo "--windres=$WindresCmd" >> acargs
    
    110
    +    echo "--llc=$LlcCmd" >> acargs
    
    111
    +    echo "--opt=$OptCmd" >> acargs
    
    112
    +    echo "--llvm-as=$LlvmAsCmd" >> acargs
    
    110 113
     
    
    111 114
         if test -n "$USER_LD"; then
    
    112 115
           echo "--ld=$USER_LD" >> acargs
    

  • m4/prep_target_file.m4
    ... ... @@ -10,6 +10,38 @@
    10 10
     # This toolchain will additionally be used to validate the one generated by
    
    11 11
     # ghc-toolchain. See Note [ghc-toolchain consistency checking].
    
    12 12
     
    
    13
    +# PREP_LIST
    
    14
    +# ============
    
    15
    +#
    
    16
    +# Issue a substitution with ["list","of","args"] of [$1List] when $1 is a
    
    17
    +# space-separated list of args
    
    18
    +# i.e.
    
    19
    +# "arg1 arg2 arg3"
    
    20
    +# ==>
    
    21
    +# ["arg1","arg2","arg3"]
    
    22
    +#
    
    23
    +# $1 = list variable to substitute
    
    24
    +dnl In autoconf, '@<:@' stands for '[', and '@:>@' for ']'.
    
    25
    +AC_DEFUN([PREP_LIST],[
    
    26
    +    # shell array
    
    27
    +    set -- $$1
    
    28
    +    $1List="@<:@"
    
    29
    +    if test "[$]#" -eq 0; then
    
    30
    +        # no arguments
    
    31
    +        true
    
    32
    +    else
    
    33
    +        $1List="${$1List}\"[$]1\""
    
    34
    +        shift # drop first elem
    
    35
    +        for arg in "[$]@"
    
    36
    +        do
    
    37
    +            $1List="${$1List},\"$arg\""
    
    38
    +        done
    
    39
    +    fi
    
    40
    +    $1List="${$1List}@:>@"
    
    41
    +
    
    42
    +    AC_SUBST([$1List])
    
    43
    +])
    
    44
    +
    
    13 45
     # PREP_MAYBE_SIMPLE_PROGRAM
    
    14 46
     # =========================
    
    15 47
     #
    
    ... ... @@ -27,6 +59,25 @@ AC_DEFUN([PREP_MAYBE_SIMPLE_PROGRAM],[
    27 59
         AC_SUBST([$1MaybeProg])
    
    28 60
     ])
    
    29 61
     
    
    62
    +# PREP_MAYBE_PROGRAM
    
    63
    +# =========================
    
    64
    +#
    
    65
    +# Introduce a substitution [$1MaybeProg] with
    
    66
    +# * Nothing, if $$1 is empty
    
    67
    +# * Just (Program {prgPath = "$$1", prgFlags = [elements of $$2]}), otherwise
    
    68
    +#
    
    69
    +# $1 = optional program path
    
    70
    +# $2 = program arguments
    
    71
    +AC_DEFUN([PREP_MAYBE_PROGRAM],[
    
    72
    +    if test -z "$$1"; then
    
    73
    +        $1MaybeProg=Nothing
    
    74
    +    else
    
    75
    +        PREP_LIST([$2])
    
    76
    +        $1MaybeProg="Just (Program {prgPath = \"$$1\", prgFlags = $$2List})"
    
    77
    +    fi
    
    78
    +    AC_SUBST([$1MaybeProg])
    
    79
    +])
    
    80
    +
    
    30 81
     # PREP_MAYBE_STRING
    
    31 82
     # =========================
    
    32 83
     #
    
    ... ... @@ -86,38 +137,6 @@ AC_DEFUN([PREP_NOT_BOOLEAN],[
    86 137
         AC_SUBST([Not$1Bool])
    
    87 138
     ])
    
    88 139
     
    
    89
    -# PREP_LIST
    
    90
    -# ============
    
    91
    -#
    
    92
    -# Issue a substitution with ["list","of","args"] of [$1List] when $1 is a
    
    93
    -# space-separated list of args
    
    94
    -# i.e.
    
    95
    -# "arg1 arg2 arg3"
    
    96
    -# ==>
    
    97
    -# ["arg1","arg2","arg3"]
    
    98
    -#
    
    99
    -# $1 = list variable to substitute
    
    100
    -dnl In autoconf, '@<:@' stands for '[', and '@:>@' for ']'.
    
    101
    -AC_DEFUN([PREP_LIST],[
    
    102
    -    # shell array
    
    103
    -    set -- $$1
    
    104
    -    $1List="@<:@"
    
    105
    -    if test "[$]#" -eq 0; then
    
    106
    -        # no arguments
    
    107
    -        true
    
    108
    -    else
    
    109
    -        $1List="${$1List}\"[$]1\""
    
    110
    -        shift # drop first elem
    
    111
    -        for arg in "[$]@"
    
    112
    -        do
    
    113
    -            $1List="${$1List},\"$arg\""
    
    114
    -        done
    
    115
    -    fi
    
    116
    -    $1List="${$1List}@:>@"
    
    117
    -
    
    118
    -    AC_SUBST([$1List])
    
    119
    -])
    
    120
    -
    
    121 140
     # Eventually: PREP_BUILD_TARGET_FILE, PREP_HOST_TARGET_FILE, PREP_TARGET_TARGET_FILE
    
    122 141
     # Prepares required substitutions to generate the target file
    
    123 142
     AC_DEFUN([PREP_TARGET_FILE],[
    
    ... ... @@ -148,7 +167,12 @@ AC_DEFUN([PREP_TARGET_FILE],[
    148 167
         PREP_LIST([JavaScriptCPPArgs])
    
    149 168
         PREP_LIST([CmmCPPArgs])
    
    150 169
         PREP_LIST([CmmCPPArgs_STAGE0])
    
    170
    +    PREP_MAYBE_SIMPLE_PROGRAM([LlcCmd])
    
    171
    +    PREP_MAYBE_SIMPLE_PROGRAM([OptCmd])
    
    172
    +    PREP_MAYBE_PROGRAM([LlvmAsCmd], [LlvmAsFlags])
    
    151 173
         PREP_MAYBE_SIMPLE_PROGRAM([WindresCmd])
    
    174
    +    PREP_MAYBE_SIMPLE_PROGRAM([OtoolCmd])
    
    175
    +    PREP_MAYBE_SIMPLE_PROGRAM([InstallNameToolCmd])
    
    152 176
         PREP_MAYBE_STRING([TargetVendor_CPP])
    
    153 177
         PREP_MAYBE_STRING([HostVendor_CPP])
    
    154 178
         PREP_LIST([CONF_CPP_OPTS_STAGE2])
    

  • rts/linker/LoadArchive.c
    ... ... @@ -33,6 +33,7 @@
    33 33
     
    
    34 34
     #define DEBUG_LOG(...) IF_DEBUG(linker, debugBelch("loadArchive: " __VA_ARGS__))
    
    35 35
     
    
    36
    +
    
    36 37
     #if defined(darwin_HOST_OS) || defined(ios_HOST_OS)
    
    37 38
     /* Read 4 bytes and convert to host byte order */
    
    38 39
     static uint32_t read4Bytes(const char buf[static 4])
    
    ... ... @@ -40,7 +41,7 @@ static uint32_t read4Bytes(const char buf[static 4])
    40 41
         return ntohl(*(uint32_t*)buf);
    
    41 42
     }
    
    42 43
     
    
    43
    -static StgBool loadFatArchive(char tmp[static 20], FILE* f, pathchar* path)
    
    44
    +static bool loadFatArchive(char input[static 20], FILE* f, pathchar* path)
    
    44 45
     {
    
    45 46
         uint32_t nfat_arch, nfat_offset, cputype, cpusubtype;
    
    46 47
     #if defined(i386_HOST_ARCH)
    
    ... ... @@ -58,8 +59,9 @@ static StgBool loadFatArchive(char tmp[static 20], FILE* f, pathchar* path)
    58 59
     #error Unknown Darwin architecture
    
    59 60
     #endif
    
    60 61
     
    
    61
    -    nfat_arch = read4Bytes(tmp + 4);
    
    62
    +    nfat_arch = read4Bytes(input + 4);
    
    62 63
         DEBUG_LOG("found a fat archive containing %d architectures\n", nfat_arch);
    
    64
    +    char tmp[20];
    
    63 65
         nfat_offset = 0;
    
    64 66
         for (uint32_t i = 0; i < nfat_arch; i++) {
    
    65 67
             /* search for the right arch */
    
    ... ... @@ -90,6 +92,7 @@ static StgBool loadFatArchive(char tmp[static 20], FILE* f, pathchar* path)
    90 92
             }
    
    91 93
     
    
    92 94
             /* Read the header */
    
    95
    +        char tmp[20];
    
    93 96
             n = fread(tmp, 1, 8, f);
    
    94 97
             if (n != 8) {
    
    95 98
                 errorBelch("Failed reading header from `%" PATH_FMT "'", path);
    
    ... ... @@ -107,10 +110,51 @@ static StgBool loadFatArchive(char tmp[static 20], FILE* f, pathchar* path)
    107 110
     }
    
    108 111
     #endif
    
    109 112
     
    
    110
    -static StgBool readThinArchiveMember(int n, int memberSize, pathchar* path,
    
    113
    +enum ObjectFileFormat {
    
    114
    +    NotObject,
    
    115
    +    COFFAmd64,
    
    116
    +    COFFI386,
    
    117
    +    COFFAArch64,
    
    118
    +    ELF,
    
    119
    +    MachO32,
    
    120
    +    MachO64,
    
    121
    +};
    
    122
    +
    
    123
    +static enum ObjectFileFormat identifyObjectFile_(char* buf, size_t sz)
    
    124
    +{
    
    125
    +    if (sz > 2 && ((uint16_t*)buf)[0] == 0x8664) {
    
    126
    +        return COFFAmd64;
    
    127
    +    }
    
    128
    +    if (sz > 2 && ((uint16_t*)buf)[0] == 0x014c) {
    
    129
    +        return COFFI386;
    
    130
    +    }
    
    131
    +    if (sz > 2 && ((uint16_t*)buf)[0] == 0xaa64) {
    
    132
    +        return COFFAArch64;
    
    133
    +    }
    
    134
    +    if (sz > 4 && memcmp(buf, "\x7f" "ELF", 4) == 0) {
    
    135
    +        return ELF;
    
    136
    +    }
    
    137
    +    if (sz > 4 && ((uint32_t*)buf)[0] == 0xfeedface) {
    
    138
    +        return MachO32;
    
    139
    +    }
    
    140
    +    if (sz > 4 && ((uint32_t*)buf)[0] == 0xfeedfacf) {
    
    141
    +        return MachO64;
    
    142
    +    }
    
    143
    +    return NotObject;
    
    144
    +}
    
    145
    +
    
    146
    +static enum ObjectFileFormat identifyObjectFile(FILE *f)
    
    147
    +{
    
    148
    +    char buf[32];
    
    149
    +    ssize_t sz = fread(buf, 1, 32, f);
    
    150
    +    CHECK(fseek(f, -sz, SEEK_CUR) == 0);
    
    151
    +    return identifyObjectFile_(buf, sz);
    
    152
    +}
    
    153
    +
    
    154
    +static bool readThinArchiveMember(int n, int memberSize, pathchar* path,
    
    111 155
             char* fileName, char* image)
    
    112 156
     {
    
    113
    -    StgBool has_succeeded = false;
    
    157
    +    bool has_succeeded = false;
    
    114 158
         FILE* member = NULL;
    
    115 159
         pathchar *pathCopy, *dirName, *memberPath, *objFileName;
    
    116 160
         memberPath = NULL;
    
    ... ... @@ -148,10 +192,9 @@ inner_fail:
    148 192
         return has_succeeded;
    
    149 193
     }
    
    150 194
     
    
    151
    -static StgBool checkFatArchive(char magic[static 20], FILE* f, pathchar* path)
    
    195
    +static bool checkFatArchive(char magic[static 4], FILE* f, pathchar* path)
    
    152 196
     {
    
    153
    -    StgBool success;
    
    154
    -    success = false;
    
    197
    +    bool success = false;
    
    155 198
     #if defined(darwin_HOST_OS) || defined(ios_HOST_OS)
    
    156 199
         /* Not a standard archive, look for a fat archive magic number: */
    
    157 200
         if (read4Bytes(magic) == FAT_MAGIC)
    
    ... ... @@ -175,7 +218,7 @@ static StgBool checkFatArchive(char magic[static 20], FILE* f, pathchar* path)
    175 218
      * be reallocated on return; the old value is now _invalid_.
    
    176 219
      * @param gnuFileIndexSize The size of the index.
    
    177 220
      */
    
    178
    -static StgBool
    
    221
    +static bool
    
    179 222
     lookupGNUArchiveIndex(int gnuFileIndexSize, char **fileName_,
    
    180 223
         char* gnuFileIndex, pathchar* path, size_t* thisFileNameSize,
    
    181 224
         size_t* fileNameSize)
    
    ... ... @@ -241,47 +284,21 @@ lookupGNUArchiveIndex(int gnuFileIndexSize, char **fileName_,
    241 284
         return true;
    
    242 285
     }
    
    243 286
     
    
    244
    -HsInt loadArchive_ (pathchar *path)
    
    245
    -{
    
    246
    -    char *image = NULL;
    
    247
    -    HsInt retcode = 0;
    
    248
    -    int memberSize;
    
    249
    -    int memberIdx = 0;
    
    250
    -    FILE *f = NULL;
    
    251
    -    int n;
    
    252
    -    size_t thisFileNameSize = (size_t)-1; /* shut up bogus GCC warning */
    
    253
    -    char *fileName;
    
    254
    -    size_t fileNameSize;
    
    255
    -    int isObject, isGnuIndex, isThin, isImportLib;
    
    256
    -    char tmp[20];
    
    257
    -    char *gnuFileIndex;
    
    258
    -    int gnuFileIndexSize;
    
    259
    -    int misalignment = 0;
    
    260
    -
    
    261
    -    DEBUG_LOG("start\n");
    
    262
    -    DEBUG_LOG("Loading archive `%" PATH_FMT "'\n", path);
    
    287
    +enum ArchiveFormat {
    
    288
    +    StandardArchive,
    
    289
    +    ThinArchive,
    
    290
    +    FatArchive,
    
    291
    +};
    
    263 292
     
    
    264
    -    /* Check that we haven't already loaded this archive.
    
    265
    -       Ignore requests to load multiple times */
    
    266
    -    if (isAlreadyLoaded(path)) {
    
    267
    -        IF_DEBUG(linker,
    
    268
    -                 debugBelch("ignoring repeated load of %" PATH_FMT "\n", path));
    
    269
    -        return 1; /* success */
    
    293
    +static bool identifyArchiveFormat(FILE *f, pathchar *path, enum ArchiveFormat *out)
    
    294
    +{
    
    295
    +    char tmp[8];
    
    296
    +    size_t n = fread(tmp, 1, 8, f);
    
    297
    +    if (n != 8) {
    
    298
    +        errorBelch("loadArchive: Failed reading header from `%" PATH_FMT "'", path); \
    
    299
    +        return false;
    
    270 300
         }
    
    271 301
     
    
    272
    -    gnuFileIndex = NULL;
    
    273
    -    gnuFileIndexSize = 0;
    
    274
    -
    
    275
    -    fileNameSize = 32;
    
    276
    -    fileName = stgMallocBytes(fileNameSize, "loadArchive(fileName)");
    
    277
    -
    
    278
    -    isThin = 0;
    
    279
    -    isImportLib = 0;
    
    280
    -
    
    281
    -    f = pathopen(path, WSTR("rb"));
    
    282
    -    if (!f)
    
    283
    -        FAIL("loadObj: can't read `%" PATH_FMT "'", path);
    
    284
    -
    
    285 302
         /* Check if this is an archive by looking for the magic "!<arch>\n"
    
    286 303
          * string.  Usually, if this fails, we belch an error and return.  On
    
    287 304
          * Darwin however, we may have a fat archive, which contains archives for
    
    ... ... @@ -300,12 +317,10 @@ HsInt loadArchive_ (pathchar *path)
    300 317
          * its magic "!<arch>\n" string and continue processing just as if
    
    301 318
          * we had a single architecture archive.
    
    302 319
          */
    
    303
    -
    
    304
    -    n = fread ( tmp, 1, 8, f );
    
    305
    -    if (n != 8) {
    
    306
    -        FAIL("Failed reading header from `%" PATH_FMT "'", path);
    
    320
    +    if (strncmp(tmp, "!<arch>\n", 8) == 0) {
    
    321
    +        *out = StandardArchive;
    
    322
    +        return true;
    
    307 323
         }
    
    308
    -    if (strncmp(tmp, "!<arch>\n", 8) == 0) {}
    
    309 324
         /* Check if this is a thin archive by looking for the magic string "!<thin>\n"
    
    310 325
          *
    
    311 326
          * ar thin libraries have the exact same format as normal archives except they
    
    ... ... @@ -322,16 +337,59 @@ HsInt loadArchive_ (pathchar *path)
    322 337
          *
    
    323 338
          */
    
    324 339
         else if (strncmp(tmp, "!<thin>\n", 8) == 0) {
    
    325
    -        isThin = 1;
    
    340
    +        *out = ThinArchive;
    
    341
    +        return true;
    
    326 342
         }
    
    327 343
         else {
    
    328
    -        StgBool success = checkFatArchive(tmp, f, path);
    
    329
    -        if (!success)
    
    330
    -            goto fail;
    
    344
    +        bool success = checkFatArchive(tmp, f, path);
    
    345
    +        if (!success) {
    
    346
    +            return false;
    
    347
    +        }
    
    348
    +        *out = FatArchive;
    
    349
    +        return true;
    
    331 350
         }
    
    351
    +}
    
    352
    +
    
    353
    +HsInt loadArchive_ (pathchar *path)
    
    354
    +{
    
    355
    +    char *image = NULL;
    
    356
    +    HsInt retcode = 0;
    
    357
    +    int memberIdx = 0;
    
    358
    +    FILE *f = NULL;
    
    359
    +    size_t thisFileNameSize = (size_t) -1; /* shut up bogus GCC warning */
    
    360
    +    int misalignment = 0;
    
    361
    +
    
    362
    +    DEBUG_LOG("start\n");
    
    363
    +    DEBUG_LOG("Loading archive `%" PATH_FMT "'\n", path);
    
    364
    +
    
    365
    +    /* Check that we haven't already loaded this archive.
    
    366
    +       Ignore requests to load multiple times */
    
    367
    +    if (isAlreadyLoaded(path)) {
    
    368
    +        IF_DEBUG(linker,
    
    369
    +                 debugBelch("ignoring repeated load of %" PATH_FMT "\n", path));
    
    370
    +        return 1; /* success */
    
    371
    +    }
    
    372
    +
    
    373
    +    char *gnuFileIndex = NULL;
    
    374
    +    int gnuFileIndexSize = 0;
    
    375
    +
    
    376
    +    size_t fileNameSize = 32;
    
    377
    +    char *fileName = stgMallocBytes(fileNameSize, "loadArchive(fileName)");
    
    378
    +
    
    379
    +    f = pathopen(path, WSTR("rb"));
    
    380
    +    if (!f)
    
    381
    +        FAIL("loadObj: can't read `%" PATH_FMT "'", path);
    
    382
    +
    
    383
    +    enum ArchiveFormat archive_fmt;
    
    384
    +    if (!identifyArchiveFormat(f, path, &archive_fmt)) {
    
    385
    +        FAIL("failed to identify archive format of %" PATH_FMT ".", path);
    
    386
    +    }
    
    387
    +    bool isThin = archive_fmt == ThinArchive;
    
    388
    +
    
    332 389
         DEBUG_LOG("loading archive contents\n");
    
    333 390
     
    
    334 391
         while (1) {
    
    392
    +        size_t n;
    
    335 393
             DEBUG_LOG("reading at %ld\n", ftell(f));
    
    336 394
             n = fread ( fileName, 1, 16, f );
    
    337 395
             if (n != 16) {
    
    ... ... @@ -351,6 +409,7 @@ HsInt loadArchive_ (pathchar *path)
    351 409
             }
    
    352 410
     #endif
    
    353 411
     
    
    412
    +        char tmp[32];
    
    354 413
             n = fread ( tmp, 1, 12, f );
    
    355 414
             if (n != 12)
    
    356 415
                 FAIL("Failed reading mod time from `%" PATH_FMT "'", path);
    
    ... ... @@ -369,9 +428,16 @@ HsInt loadArchive_ (pathchar *path)
    369 428
             tmp[10] = '\0';
    
    370 429
             for (n = 0; isdigit(tmp[n]); n++);
    
    371 430
             tmp[n] = '\0';
    
    372
    -        memberSize = atoi(tmp);
    
    431
    +        size_t memberSize;
    
    432
    +        {
    
    433
    +            char *end;
    
    434
    +            memberSize = strtol(tmp, &end, 10);
    
    435
    +            if (tmp == end) {
    
    436
    +                FAIL("Failed to decode member size");
    
    437
    +            }
    
    438
    +        }
    
    373 439
     
    
    374
    -        DEBUG_LOG("size of this archive member is %d\n", memberSize);
    
    440
    +        DEBUG_LOG("size of this archive member is %zd\n", memberSize);
    
    375 441
             n = fread ( tmp, 1, 2, f );
    
    376 442
             if (n != 2)
    
    377 443
                 FAIL("Failed reading magic from `%" PATH_FMT "'", path);
    
    ... ... @@ -379,7 +445,7 @@ HsInt loadArchive_ (pathchar *path)
    379 445
                 FAIL("Failed reading magic from `%" PATH_FMT "' at %ld. Got %c%c",
    
    380 446
                      path, ftell(f), tmp[0], tmp[1]);
    
    381 447
     
    
    382
    -        isGnuIndex = 0;
    
    448
    +        bool isGnuIndex = false;
    
    383 449
             /* Check for BSD-variant large filenames */
    
    384 450
             if (0 == strncmp(fileName, "#1/", 3)) {
    
    385 451
                 size_t n = 0;
    
    ... ... @@ -419,7 +485,7 @@ HsInt loadArchive_ (pathchar *path)
    419 485
             else if (0 == strncmp(fileName, "//", 2)) {
    
    420 486
                 fileName[0] = '\0';
    
    421 487
                 thisFileNameSize = 0;
    
    422
    -            isGnuIndex = 1;
    
    488
    +            isGnuIndex = true;
    
    423 489
             }
    
    424 490
             /* Check for a file in the GNU file index */
    
    425 491
             else if (fileName[0] == '/') {
    
    ... ... @@ -460,12 +526,8 @@ HsInt loadArchive_ (pathchar *path)
    460 526
     
    
    461 527
             DEBUG_LOG("Found member file `%s'\n", fileName);
    
    462 528
     
    
    463
    -        /* TODO: Stop relying on file extensions to determine input formats.
    
    464
    -                 Instead try to match file headers. See #13103.  */
    
    465
    -        isObject = (thisFileNameSize >= 2 && strncmp(fileName + thisFileNameSize - 2, ".o"  , 2) == 0)
    
    466
    -                || (thisFileNameSize >= 3 && strncmp(fileName + thisFileNameSize - 3, ".lo" , 3) == 0)
    
    467
    -                || (thisFileNameSize >= 4 && strncmp(fileName + thisFileNameSize - 4, ".p_o", 4) == 0)
    
    468
    -                || (thisFileNameSize >= 4 && strncmp(fileName + thisFileNameSize - 4, ".obj", 4) == 0);
    
    529
    +        bool is_symbol_table = strcmp("", fileName) == 0;
    
    530
    +        enum ObjectFileFormat object_fmt = is_symbol_table ? NotObject : identifyObjectFile(f);
    
    469 531
     
    
    470 532
     #if defined(OBJFORMAT_PEi386)
    
    471 533
             /*
    
    ... ... @@ -479,15 +541,15 @@ HsInt loadArchive_ (pathchar *path)
    479 541
             *
    
    480 542
             * Linker members (e.g. filename / are skipped since they are not needed)
    
    481 543
             */
    
    482
    -        isImportLib = thisFileNameSize >= 4 && strncmp(fileName + thisFileNameSize - 4, ".dll", 4) == 0;
    
    544
    +        bool isImportLib = thisFileNameSize >= 4 && strncmp(fileName + thisFileNameSize - 4, ".dll", 4) == 0;
    
    545
    +#else
    
    546
    +        bool isImportLib = false;
    
    483 547
     #endif // windows
    
    484 548
     
    
    485 549
             DEBUG_LOG("\tthisFileNameSize = %d\n", (int)thisFileNameSize);
    
    486
    -        DEBUG_LOG("\tisObject = %d\n", isObject);
    
    487
    -
    
    488
    -        if (isObject) {
    
    489
    -            pathchar *archiveMemberName;
    
    550
    +        DEBUG_LOG("\tisObject = %d\n", object_fmt);
    
    490 551
     
    
    552
    +        if ((!is_symbol_table && isThin) || object_fmt != NotObject) {
    
    491 553
                 DEBUG_LOG("Member is an object file...loading...\n");
    
    492 554
     
    
    493 555
     #if defined(darwin_HOST_OS) || defined(ios_HOST_OS)
    
    ... ... @@ -505,14 +567,13 @@ HsInt loadArchive_ (pathchar *path)
    505 567
                 image = stgMallocBytes(memberSize, "loadArchive(image)");
    
    506 568
     #endif
    
    507 569
                 if (isThin) {
    
    508
    -                if (!readThinArchiveMember(n, memberSize, path,
    
    509
    -                        fileName, image)) {
    
    570
    +                if (!readThinArchiveMember(n, memberSize, path, fileName, image)) {
    
    510 571
                         goto fail;
    
    511 572
                     }
    
    512 573
                 }
    
    513 574
                 else
    
    514 575
                 {
    
    515
    -                n = fread ( image, 1, memberSize, f );
    
    576
    +                size_t n = fread ( image, 1, memberSize, f );
    
    516 577
                     if (n != memberSize) {
    
    517 578
                         FAIL("error whilst reading `%" PATH_FMT "'", path);
    
    518 579
                     }
    
    ... ... @@ -523,16 +584,18 @@ HsInt loadArchive_ (pathchar *path)
    523 584
                 // I don't understand why this extra +1 is needed here; pathprintf
    
    524 585
                 // should have given us the correct length but in practice it seems
    
    525 586
                 // to be one byte short on Win32.
    
    526
    -            archiveMemberName = stgMallocBytes((size+1+1) * sizeof(pathchar), "loadArchive(file)");
    
    587
    +            pathchar *archiveMemberName = stgMallocBytes((size+1+1) * sizeof(pathchar), "loadArchive(file)");
    
    527 588
                 pathprintf(archiveMemberName, size+1, WSTR("%" PATH_FMT "(#%d:%.*s)"),
    
    528 589
                            path, memberIdx, (int)thisFileNameSize, fileName);
    
    529 590
     
    
    530 591
                 ObjectCode *oc = mkOc(STATIC_OBJECT, path, image, memberSize, false, archiveMemberName,
    
    531 592
                                       misalignment);
    
    532 593
     #if defined(OBJFORMAT_MACHO)
    
    594
    +            ASSERT(object_fmt == MachO32 || object_fmt == MachO64);
    
    533 595
                 ocInit_MachO( oc );
    
    534 596
     #endif
    
    535 597
     #if defined(OBJFORMAT_ELF)
    
    598
    +            ASSERT(object_fmt == ELF);
    
    536 599
                 ocInit_ELF( oc );
    
    537 600
     #endif
    
    538 601
     
    
    ... ... @@ -577,7 +640,7 @@ while reading filename from `%" PATH_FMT "'", path);
    577 640
                               "Skipping...\n");
    
    578 641
                     n = fseek(f, memberSize, SEEK_CUR);
    
    579 642
                     if (n != 0)
    
    580
    -                    FAIL("error whilst seeking by %d in `%" PATH_FMT "'",
    
    643
    +                    FAIL("error whilst seeking by %zd in `%" PATH_FMT "'",
    
    581 644
                         memberSize, path);
    
    582 645
                 }
    
    583 646
     #endif
    
    ... ... @@ -588,7 +651,7 @@ while reading filename from `%" PATH_FMT "'", path);
    588 651
                 if (!isThin || thisFileNameSize == 0) {
    
    589 652
                     n = fseek(f, memberSize, SEEK_CUR);
    
    590 653
                     if (n != 0)
    
    591
    -                    FAIL("error whilst seeking by %d in `%" PATH_FMT "'",
    
    654
    +                    FAIL("error whilst seeking by %zd in `%" PATH_FMT "'",
    
    592 655
                              memberSize, path);
    
    593 656
                 }
    
    594 657
             }
    

  • utils/ghc-toolchain/exe/Main.hs
    ... ... @@ -52,7 +52,12 @@ data Opts = Opts
    52 52
         , optNm        :: ProgOpt
    
    53 53
         , optReadelf   :: ProgOpt
    
    54 54
         , optMergeObjs :: ProgOpt
    
    55
    +    , optLlc       :: ProgOpt
    
    56
    +    , optOpt       :: ProgOpt
    
    57
    +    , optLlvmAs    :: ProgOpt
    
    55 58
         , optWindres   :: ProgOpt
    
    59
    +    , optOtool     :: ProgOpt
    
    60
    +    , optInstallNameTool :: ProgOpt
    
    56 61
         -- Note we don't actually configure LD into anything but
    
    57 62
         -- see #23857 and #22550 for the very unfortunate story.
    
    58 63
         , optLd        :: ProgOpt
    
    ... ... @@ -99,8 +104,13 @@ emptyOpts = Opts
    99 104
         , optNm        = po0
    
    100 105
         , optReadelf   = po0
    
    101 106
         , optMergeObjs = po0
    
    107
    +    , optLlc       = po0
    
    108
    +    , optOpt       = po0
    
    109
    +    , optLlvmAs    = po0
    
    102 110
         , optWindres   = po0
    
    103 111
         , optLd        = po0
    
    112
    +    , optOtool     = po0
    
    113
    +    , optInstallNameTool = po0
    
    104 114
         , optUnregisterised = Nothing
    
    105 115
         , optTablesNextToCode = Nothing
    
    106 116
         , optUseLibFFIForAdjustors = Nothing
    
    ... ... @@ -112,7 +122,8 @@ emptyOpts = Opts
    112 122
         po0 = emptyProgOpt
    
    113 123
     
    
    114 124
     _optCc, _optCxx, _optCpp, _optHsCpp, _optJsCpp, _optCmmCpp, _optCcLink, _optAr,
    
    115
    -    _optRanlib, _optNm, _optReadelf, _optMergeObjs, _optWindres, _optLd
    
    125
    +    _optRanlib, _optNm, _optReadelf, _optMergeObjs, _optLlc, _optOpt, _optLlvmAs,
    
    126
    +    _optWindres, _optLd, _optOtool, _optInstallNameTool
    
    116 127
         :: Lens Opts ProgOpt
    
    117 128
     _optCc      = Lens optCc      (\x o -> o {optCc=x})
    
    118 129
     _optCxx     = Lens optCxx     (\x o -> o {optCxx=x})
    
    ... ... @@ -126,8 +137,13 @@ _optRanlib = Lens optRanlib (\x o -> o {optRanlib=x})
    126 137
     _optNm      = Lens optNm      (\x o -> o {optNm=x})
    
    127 138
     _optReadelf = Lens optReadelf (\x o -> o {optReadelf=x})
    
    128 139
     _optMergeObjs = Lens optMergeObjs (\x o -> o {optMergeObjs=x})
    
    140
    +_optLlc     = Lens optLlc     (\x o -> o {optLlc=x})
    
    141
    +_optOpt     = Lens optOpt     (\x o -> o {optOpt=x})
    
    142
    +_optLlvmAs  = Lens optLlvmAs  (\x o -> o {optLlvmAs=x})
    
    129 143
     _optWindres = Lens optWindres (\x o -> o {optWindres=x})
    
    130
    -_optLd = Lens optLd (\x o -> o {optLd= x})
    
    144
    +_optLd      = Lens optLd (\x o -> o {optLd=x})
    
    145
    +_optOtool   = Lens optOtool (\x o -> o {optOtool=x})
    
    146
    +_optInstallNameTool = Lens optInstallNameTool (\x o -> o {optInstallNameTool=x})
    
    131 147
     
    
    132 148
     _optTriple :: Lens Opts (Maybe String)
    
    133 149
     _optTriple = Lens optTriple (\x o -> o {optTriple=x})
    
    ... ... @@ -183,8 +199,13 @@ options =
    183 199
         , progOpts "nm" "nm archiver" _optNm
    
    184 200
         , progOpts "readelf" "readelf utility" _optReadelf
    
    185 201
         , progOpts "merge-objs" "linker for merging objects" _optMergeObjs
    
    202
    +    , progOpts "llc" "LLVM llc utility" _optLlc
    
    203
    +    , progOpts "opt" "LLVM opt utility" _optOpt
    
    204
    +    , progOpts "llvm-as" "Assembler used for LLVM backend (typically clang)" _optLlvmAs
    
    186 205
         , progOpts "windres" "windres utility" _optWindres
    
    187 206
         , progOpts "ld" "linker" _optLd
    
    207
    +    , progOpts "otool" "otool utility" _optOtool
    
    208
    +    , progOpts "install-name-tool" "install-name-tool utility" _optInstallNameTool
    
    188 209
         ]
    
    189 210
       where
    
    190 211
         progOpts :: String -> String -> Lens Opts ProgOpt -> [OptDescr (Opts -> Opts)]
    
    ... ... @@ -436,6 +457,11 @@ mkTarget opts = do
    436 457
         when (isNothing mergeObjs && not (arSupportsDashL ar)) $
    
    437 458
           throwE "Neither a object-merging tool (e.g. ld -r) nor an ar that supports -L is available"
    
    438 459
     
    
    460
    +    -- LLVM toolchain
    
    461
    +    llc <- optional $ findProgram "llc" (optLlc opts) ["llc"]
    
    462
    +    opt <- optional $ findProgram "opt" (optOpt opts) ["opt"]
    
    463
    +    llvmAs <- optional $ findProgram "llvm assembler" (optLlvmAs opts) ["clang"]
    
    464
    +
    
    439 465
         -- Windows-specific utilities
    
    440 466
         windres <-
    
    441 467
             case archOS_OS archOs of
    
    ... ... @@ -444,6 +470,15 @@ mkTarget opts = do
    444 470
                 return (Just windres)
    
    445 471
               _ -> return Nothing
    
    446 472
     
    
    473
    +    -- Darwin-specific utilities
    
    474
    +    (otool, installNameTool) <-
    
    475
    +        case archOS_OS archOs of
    
    476
    +          OSDarwin -> do
    
    477
    +            otool <- findProgram "otool" (optOtool opts) ["otool"]
    
    478
    +            installNameTool <- findProgram "install_name_tool" (optInstallNameTool opts) ["install_name_tool"]
    
    479
    +            return (Just otool, Just installNameTool)
    
    480
    +          _ -> return (Nothing, Nothing)
    
    481
    +
    
    447 482
         -- various other properties of the platform
    
    448 483
         tgtWordSize <- checkWordSize cc
    
    449 484
         tgtEndianness <- checkEndianness cc
    
    ... ... @@ -480,7 +515,12 @@ mkTarget opts = do
    480 515
                        , tgtRanlib = ranlib
    
    481 516
                        , tgtNm = nm
    
    482 517
                        , tgtMergeObjs = mergeObjs
    
    518
    +                   , tgtLlc = llc
    
    519
    +                   , tgtOpt = opt
    
    520
    +                   , tgtLlvmAs = llvmAs
    
    483 521
                        , tgtWindres = windres
    
    522
    +                   , tgtOtool = otool
    
    523
    +                   , tgtInstallNameTool = installNameTool
    
    484 524
                        , tgtWordSize
    
    485 525
                        , tgtEndianness
    
    486 526
                        , tgtUnregisterised
    

  • utils/ghc-toolchain/src/GHC/Toolchain/Target.hs
    ... ... @@ -22,15 +22,6 @@ data WordSize = WS4 | WS8
    22 22
     data Endianness = LittleEndian | BigEndian
    
    23 23
         deriving (Show, Read, Eq, Ord)
    
    24 24
     
    
    25
    --- TODO(#23674): Move the remaining relevant `settings-xxx` to Target:
    
    26
    --- * llc command
    
    27
    --- * opt command
    
    28
    --- * install_name_tool
    
    29
    --- * otool command
    
    30
    ---
    
    31
    --- Those are all things that are put into GHC's settings, and that might be
    
    32
    --- different across targets
    
    33
    -
    
    34 25
     -- | A 'Target' consists of:
    
    35 26
     --
    
    36 27
     -- * a target architecture and operating system
    
    ... ... @@ -72,8 +63,18 @@ data Target = Target
    72 63
         , tgtMergeObjs :: Maybe MergeObjs
    
    73 64
         -- ^ We don't need a merge objects tool if we @Ar@ supports @-L@
    
    74 65
     
    
    66
    +      -- LLVM backend toolchain
    
    67
    +    , tgtLlc :: Maybe Program
    
    68
    +    , tgtOpt :: Maybe Program
    
    69
    +    , tgtLlvmAs :: Maybe Program
    
    70
    +    -- ^ assembler used to assemble LLVM backend output; typically @clang@
    
    71
    +
    
    75 72
           -- Windows-specific tools
    
    76 73
         , tgtWindres :: Maybe Program
    
    74
    +
    
    75
    +      -- Darwin-specific tools
    
    76
    +    , tgtOtool   :: Maybe Program
    
    77
    +    , tgtInstallNameTool :: Maybe Program
    
    77 78
         }
    
    78 79
         deriving (Read, Eq, Ord)
    
    79 80
     
    
    ... ... @@ -121,6 +122,11 @@ instance Show Target where
    121 122
         , ", tgtRanlib = " ++ show tgtRanlib
    
    122 123
         , ", tgtNm = " ++ show tgtNm
    
    123 124
         , ", tgtMergeObjs = " ++ show tgtMergeObjs
    
    125
    +    , ", tgtLlc = " ++ show tgtLlc
    
    126
    +    , ", tgtOpt = " ++ show tgtOpt
    
    127
    +    , ", tgtLlvmAs = " ++ show tgtLlvmAs
    
    124 128
         , ", tgtWindres = " ++ show tgtWindres
    
    129
    +    , ", tgtOtool = " ++ show tgtOtool
    
    130
    +    , ", tgtInstallNameTool = " ++ show tgtInstallNameTool
    
    125 131
         , "}"
    
    126 132
         ]