[GHC] #13810: Gold linker fails

#13810: Gold linker fails ----------------------------------------+--------------------------------- Reporter: ksaric | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Keywords: linker | Operating System: Linux Architecture: Unknown/Multiple | Type of failure: None/Unknown Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: ----------------------------------------+--------------------------------- When using gold linker in the project, the compilation fails. The same error occurs even when using nix, without stack. The bug can be reproduced very easily. You can clone from here (https://github.com/ksaric/bronze-linker) and `stack build`. Or you can: - `stack new project` - `cd project` - `stack build` Now it builds. - then add gold flags to cabal like here - https://github.com/ksaric /bronze-linker/blob/master/bronze-linker.cabal#L22-L25 - `stack build` Now it fails. ---- Linking .stack-work/dist/x86_64-linux-nix/Cabal-1.24.2.0/build/bronze- linker-exe/bronze-linker-exe ... /nix/store/x9v0yxy5iybp2m2ccqwqkvxgjy7zrw8f-binutils-2.28/bin/ld.gold: --hash-size=31: unknown option /nix/store/x9v0yxy5iybp2m2ccqwqkvxgjy7zrw8f-binutils-2.28/bin/ld.gold: use the --help option for usage information collect2: error: ld returned 1 exit status 'cc' failed in phase 'Linker'. (Exit code: 1) ---- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13810 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13810: Gold linker fails ---------------------------------+---------------------------------------- Reporter: ksaric | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: linker Operating System: Linux | Architecture: Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+---------------------------------------- Comment (by domenkozar): Following fixes it: ``` diff --git a/bronze-linker.cabal b/bronze-linker.cabal index 548dbb9..00e0b5b 100644 --- a/bronze-linker.cabal +++ b/bronze-linker.cabal @@ -31,6 +31,8 @@ executable bronze-linker-exe build-depends: base , bronze-linker default-language: Haskell2010 + ghc-options: -optl-fuse-ld=gold + ld-options: -fuse-ld=gold test-suite bronze-linker-test type: exitcode-stdio-1.0 Discard this hunk from worktree [y,n,q,a,d,/,e,?]? y ``` -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13810#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13810: Gold linker fails ---------------------------------+---------------------------------------- Reporter: ksaric | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: linker Operating System: Linux | Architecture: Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+---------------------------------------- Comment (by ksaric): @domenkozar Ok, now I added the project https://github.com/ksaric/bronze-linker-client to try out. It depends on the project https://github.com/ksaric/bronze- linker and it doesn't compile. Also, I added three branches to the original project in question: - `demo/failing-example` - `demo/working-counter-example` - `demo/full-working` You can see that when using gold linker in the executable only, things work correctly - `demo/working-counter-example`. I'm not sure this is intentional, and I thought it's connected to the actual bug I found, which is that when you try to compile a project that has a dependency that uses gold linker, the aforementioned error occurs - you can reproduce that with the project I added - https://github.com/ksaric/bronze-linker-client. I hope this is clearer, and yes, I'm confused as well, this is kind of strange. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13810#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13810: Gold linker fails ---------------------------------+---------------------------------------- Reporter: ksaric | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: linker Operating System: Linux | Architecture: Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+---------------------------------------- Comment (by domenkozar): So here's my understanding how bug happens on GHC 8.0.2: If library A is linked with gold and library B depends on A, no matter if B is specified to be linked with gold or not, it fails to detect that it should use the gold linker. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13810#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13810: Gold linker fails ---------------------------------+---------------------------------------- Reporter: ksaric | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: linker Operating System: Linux | Architecture: Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+---------------------------------------- Comment (by ksaric): Right. And if you try to explicitly add gold linker flags to library B, it doesn't help, since GHC thinks (heh, I wish) that it doesn't need to use gold linker for project A, even if the project A has defined gold linker explicitly. Anyone can try to modify the project https://github.com/ksaric/bronze- linker-client with the flags and without them, and **it will fail in both cases**. So: - project A is using gold linker - project B is using project A ''Project B can't compile because it's sending parameters for "regular" ld, and not gold linker.'' -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13810#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13810: Gold linker fails ---------------------------------+---------------------------------------- Reporter: ksaric | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: linker Operating System: Linux | Architecture: Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+---------------------------------------- Changes (by domenkozar): * cc: domen.kozar@… (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13810#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13810: Gold linker fails ---------------------------------+---------------------------------------- Reporter: ksaric | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: linker Operating System: Linux | Architecture: Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+---------------------------------------- Changes (by nh2): * cc: nh2 (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13810#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13810: Gold linker fails ---------------------------------+---------------------------------------- Reporter: ksaric | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: linker Operating System: Linux | Architecture: Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+---------------------------------------- Changes (by basvandijk): * cc: basvandijk (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13810#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13810: Gold linker fails ---------------------------------+---------------------------------------- Reporter: ksaric | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: linker Operating System: Linux | Architecture: Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+---------------------------------------- Comment (by bgamari): I'm looking at the example described in the ticket summary: The issue here is that the library component was registered with (quoting `ghc-pkg dump`), {{{ ld-options: -fuse-ld=gold }}} Consequently, when we go to link the executable GHC will add this flag to its usual link flags, the latter of which assume that we are using BFD `ld`. Frankly, I don't see any better way to handle this beyond just teaching GHC to use `ld` when possible. I'm working on this (see #13541) but unfortunately it isn't likely that this will make the already-terribly- late 8.2.1. We may be able to work it in to 8.2.2 if we hear very vocal support from users, however. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13810#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13810: Gold linker fails ---------------------------------+---------------------------------------- Reporter: ksaric | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: linker Operating System: Linux | Architecture: Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+---------------------------------------- Comment (by nh2): Replying to [comment:8 bgamari]:
beyond just teaching GHC to use `ld` when possible
Do you mean `gold`?
Consequently, when we go to link the executable GHC will add this flag to its usual link flags, the latter of which assume that we are using BFD ld.
I don't quite understand this. Isn't the key problem here that the concept of the "ld program" and the "ld-options" are unhealthily mixed up? It seems to me that if one could explicitly distinguish "I want this linker" and "I want these ld-flags", the problem wouldn't exist, because then the choice of linker would not be propagated through `ld-options`. In other words, isn't the problem here that we're linking through the compiler (e.g. `gcc`) instead of the actual linker binary? Because otherwise we'd not even be using the `-fuse-ld` flag. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13810#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13810: Gold linker fails ---------------------------------+---------------------------------------- Reporter: ksaric | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: linker Operating System: Linux | Architecture: Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+---------------------------------------- Comment (by nh2): (Another workaround might be to make ghc ignore the `-fuse-ld` flag as a flag that can traverse `ld-options` through `build-depends`, but that option seems more hacky than linking directly with a linker executable, if that is possible.) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13810#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13810: Gold linker fails ---------------------------------+---------------------------------------- Reporter: ksaric | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: linker Operating System: Linux | Architecture: Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+---------------------------------------- Comment (by bgamari):
Do you mean gold?
Whoops, yes.
I don't quite understand this. Isn't the key problem here that the concept of the "ld program" and the "ld-options" are unhealthily mixed up?
In other words, isn't the problem here that we're linking through the compiler (e.g. `gcc`) instead of the actual linker binary? Because otherwise we'd not even be using the `-fuse-ld` flag.
I've played around with the idea of involing `ld` ourselves and have concluded that it's almost certainly going to hurt more than it helps. Linking tends to be terribly platform specific and rather difficult to get right (see also: `gcc -dumpspecs`). Moreover, linkers on many platforms tend to be, shall we say, quirky. I don't see us being able to robustly implement the logic necessary to drive the linker as well as `gcc`. Keep in mind that GHC is not only responsible for linking Haskell; we are often asked to link against native code, some of which may require peculiar linking behavior (e.g. one of those many rules seen in `gcc -dumpspecs`). This isn't to say that `gcc`'s abstraction over linking is quite perfect; far from it. However, it's IMHO much better than having to dive into the muck ourselves. Moreover, I don't think thinking ourselves would necessarily help the crux of this problem: the user essentially gave us conflicting linking options. Really, the user shouldn't have to give us *any* linker options in this case; `ghc` should just handle linker choice for you. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13810#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13810: Gold linker fails ---------------------------------+---------------------------------------- Reporter: ksaric | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: wontfix | Keywords: linker Operating System: Linux | Architecture: Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+---------------------------------------- Changes (by bgamari): * status: new => closed * resolution: => wontfix * milestone: => 8.2.1 Comment: We have decided that we will merge the fix #13541 for 8.2.1, so there should be no need to pass ld flags like this in the future. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13810#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13810: Gold linker fails ---------------------------------+---------------------------------------- Reporter: ksaric | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: wontfix | Keywords: linker Operating System: Linux | Architecture: Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ---------------------------------+---------------------------------------- Comment (by ksaric): Ok, great, thanks! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13810#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13810: Gold linker fails
---------------------------------+----------------------------------------
Reporter: ksaric | Owner: (none)
Type: bug | Status: closed
Priority: normal | Milestone: 8.2.1
Component: Compiler | Version: 8.0.1
Resolution: wontfix | Keywords: linker
Operating System: Linux | Architecture: Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
---------------------------------+----------------------------------------
Comment (by Ben Gamari
participants (1)
-
GHC