Magnus pushed to branch wip/mangoiv/improve-linker-discovery at Glasgow Haskell Compiler / GHC

Commits:

2 changed files:

Changes:

  • m4/bindist_determine_linker.m4
    ... ... @@ -101,8 +101,10 @@ AC_DEFUN([BINDIST_DETERMINE_LINKER],[
    101 101
          then linker_set_successfully=no
    
    102 102
               try_set_linker_to "$LD"
    
    103 103
               if test "z$linker_set_successfully" != "zyes";
    
    104
    -             then AC_MSG_FAILURE([ $tmp_ld is an invalid linker. If your C compiler accepts the '--ld-path' flag,
    
    105
    -                  \$LD can be either of an executable name that is in \$PATH *or* a path to an executable.
    
    104
    +             then AC_MSG_WARN([ Could not tell the C compiler to use \$LD ( $tmp_ld ), falling back to
    
    105
    +                  the C compiler's default linker for linking. \$LD will still be used for merging objects.
    
    106
    +                  If your C compiler accepts the '--ld-path' flag, \$LD can be either of an executable name 
    
    107
    +                  that is in \$PATH *or* a path to an executable.
    
    106 108
                       If your C compiler only supports the '--fuse-ld' flag, \$LD can only be one of the linker flavours supported
    
    107 109
                       by it. Mind that if your C compiler supports '--ld-path', 'configure' will always prefer using an absolute path
    
    108 110
                       to your linker as that is less error-prone.])
    

  • utils/ghc-toolchain/src/GHC/Toolchain/Tools/Link.hs
    ... ... @@ -62,7 +62,7 @@ findCcLink target ld progOpt userLdOverride archOs cc readelf ar ranlib = checki
    62 62
       -- Use the specified linker or try using the C compiler
    
    63 63
       rawCcLink <- findProgram "C compiler for linking" progOpt [] <|> pure (programFromOpt progOpt (prgPath $ ccProgram cc) [])
    
    64 64
       ccLinkProgram <- if
    
    65
    -    -- A cc with linker was already specified, don't doubt the user's proficiency,
    
    65
    +    -- A cc with linker was already specified, don't question the user's proficiency,
    
    66 66
         -- autonomy and right to segmentation faults
    
    67 67
         | Just _ <- progOpt.poFlags -> pure rawCcLink
    
    68 68
         -- we get a $LD; now figure out how to pass it to the $CC
    
    ... ... @@ -71,7 +71,7 @@ findCcLink target ld progOpt userLdOverride archOs cc readelf ar ranlib = checki
    71 71
         -- we are lenient and just act as if $LD wasn't set and enable-ld-override
    
    72 72
         -- is off
    
    73 73
         , ldPathOrFlavour /= "ld" -> do
    
    74
    -        flip oneOf'
    
    74
    +        asum
    
    75 75
     
    
    76 76
               [ do
    
    77 77
                 -- first check if the c compiler supports --ld-path, which goes best with $LD
    
    ... ... @@ -81,18 +81,22 @@ findCcLink target ld progOpt userLdOverride archOs cc readelf ar ranlib = checki
    81 81
                 checkLink rawCcLink [ fLdPath ldPath.prgPath ]
    
    82 82
               , -- second, check if the c compiler instead understands -fuse-ld (linker "flavour");
    
    83 83
                 -- do not try to expand the path first since absolute paths are not valid linker flavours
    
    84
    -            checkLink rawCcLink [ fUseLd ldPathOrFlavour] ]
    
    85
    -
    
    86
    -          -- $LD was set but we couldn't figure out how to pass it to $CC. This is a hard failure,
    
    87
    -          -- we report it.
    
    88
    -          [ ldPathOrFlavour <> " is an invalid linker."
    
    89
    -          , "$LD can be either of an executable name that is in $PATH *or* a"
    
    90
    -            <> " path to an executable."
    
    91
    -          , "If your C compiler only supports the '-fuse-ld' flag, $LD can"
    
    92
    -            <> " only be one of the linker flavours supported by it."
    
    93
    -          , "Mind that if your C compiler supports '--ld-path', 'configure'"
    
    94
    -            <> " will always prefer using an absolute path to your linker as"
    
    95
    -            <> " that is less error-prone." ]
    
    84
    +            checkLink rawCcLink [ fUseLd ldPathOrFlavour]
    
    85
    +
    
    86
    +          -- $LD was set but we couldn't figure out how to pass it to $CC. This happens in some cross compilation
    
    87
    +          -- scenarios, but we should warn about it.
    
    88
    +          , do
    
    89
    +            logInfo $ unlines
    
    90
    +               [ "Warning: could not tell the C compiler to use $LD (" <> ldPathOrFlavour <> ")."
    
    91
    +               , "$LD can be either of an executable name that is in $PATH *or* a path to an executable."
    
    92
    +               , "If your C compiler only supports the '-fuse-ld' flag, $LD can only be one of the linker"
    
    93
    +               <> " flavours supported by it."
    
    94
    +               , "Falling back to the C compiler's default linker for linking."
    
    95
    +               , "Mind that if your C compiler supports '--ld-path', 'configure'"
    
    96
    +               <> " will always prefer using an absolute path to your linker as"
    
    97
    +               <> " that is less error-prone." ]
    
    98
    +            checkLink rawCcLink []
    
    99
    +          ]
    
    96 100
     
    
    97 101
         -- $LD is not set or $LD=ld (see above)
    
    98 102
         -- Try to convince @cc@ to use a more efficient linker than @bfd.ld@