GHC issueshttps://gitlab.haskell.org/ghc/ghc/-/issues2019-07-07T18:32:27Zhttps://gitlab.haskell.org/ghc/ghc/-/issues/11042Template Haskell / GHCi does not respect extra-lib-dirs2019-07-07T18:32:27ZMathieu BoespflugTemplate Haskell / GHCi does not respect extra-lib-dirsIn particular when compiling on NixOS, but also in many other situations, it is often needed to pass --extra-lib-dirs / --extra-include-dirs to cabal/stack, to help GHC find required system libraries. This works fine for GHC, but not GHC...In particular when compiling on NixOS, but also in many other situations, it is often needed to pass --extra-lib-dirs / --extra-include-dirs to cabal/stack, to help GHC find required system libraries. This works fine for GHC, but not GHCi, and therefore also not Template Haskell code.
Minimal example attached. Try it in an environment where libz is not in a standard location, e.g. inside a nix-shell. Note that if you remove the template Haskell splice in Main.hs, the code compiles just fine.
This affects GHC 7.10.2, but also HEAD from 2015-08-28, even one including Tamar Christina's 5d841108acef950fed6a5e608ac9b18e7431aa87 commit cherry-picked. I haven't been able to test more recent HEAD, because of unrelated compilation issues.
I surmise that a fix to #10458, which currently blocks using HaskellR in GHCi, would also fix this, but I'm not sure. The error message I get is different:
```
$ stack build --skip-ghc-check --extra-lib-dirs=/nix/store/31w31mc8immhpnmxvcl4l0fvc3i5iwh0-zlib-1.2.8/lib --extra-include-dirs=/nix/store/31w31mc8immhpnmxvcl4l0fvc3i5iwh0-zlib-1.2.8/include
b-0.1.0.0: build
Preprocessing executable 'b' for b-0.1.0.0...
[2 of 2] Compiling Main ( src/Main.hs, .stack-work/dist/x86_64-linux/Cabal-1.23.0.0/build/b/b-tmp/Main.o )
<command line>: can't load .so/.DLL for: libz.so (libz.so: cannot open shared object file: No such file or directory)
-- While building package b-0.1.0.0 using:
/home/mboes/.stack/setup-exe-cache/setup-Simple-Cabal-1.23.0.0-x86_64-linux-ghc-7.11.20150828 --builddir=.stack-work/dist/x86_64-linux/Cabal-1.23.0.0/ build exe:b --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | --------------- |
| Version | 7.10.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | #5289, #10458 |
| Blocking | |
| CC | Phyx-, trommler |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Template Haskell / GHCi does not respect extra-lib-dirs","status":"New","operating_system":"","component":"Compiler","related":[5289,10458],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"7.10.2","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":["Phyx-","trommler"],"type":"Bug","description":"In particular when compiling on NixOS, but also in many other situations, it is often needed to pass --extra-lib-dirs / --extra-include-dirs to cabal/stack, to help GHC find required system libraries. This works fine for GHC, but not GHCi, and therefore also not Template Haskell code.\r\n\r\nMinimal example attached. Try it in an environment where libz is not in a standard location, e.g. inside a nix-shell. Note that if you remove the template Haskell splice in Main.hs, the code compiles just fine.\r\n\r\nThis affects GHC 7.10.2, but also HEAD from 2015-08-28, even one including Tamar Christina's 5d841108acef950fed6a5e608ac9b18e7431aa87 commit cherry-picked. I haven't been able to test more recent HEAD, because of unrelated compilation issues.\r\n\r\nI surmise that a fix to #10458, which currently blocks using HaskellR in GHCi, would also fix this, but I'm not sure. The error message I get is different:\r\n\r\n{{{\r\n$ stack build --skip-ghc-check --extra-lib-dirs=/nix/store/31w31mc8immhpnmxvcl4l0fvc3i5iwh0-zlib-1.2.8/lib --extra-include-dirs=/nix/store/31w31mc8immhpnmxvcl4l0fvc3i5iwh0-zlib-1.2.8/include\r\nb-0.1.0.0: build\r\nPreprocessing executable 'b' for b-0.1.0.0...\r\n[2 of 2] Compiling Main ( src/Main.hs, .stack-work/dist/x86_64-linux/Cabal-1.23.0.0/build/b/b-tmp/Main.o )\r\n<command line>: can't load .so/.DLL for: libz.so (libz.so: cannot open shared object file: No such file or directory)\r\n \r\n-- While building package b-0.1.0.0 using: \r\n /home/mboes/.stack/setup-exe-cache/setup-Simple-Cabal-1.23.0.0-x86_64-linux-ghc-7.11.20150828 --builddir=.stack-work/dist/x86_64-linux/Cabal-1.23.0.0/ build exe:b --ghc-options \" -ddump-hi -ddump-to-file\"\r\n Process exited with code: ExitFailure 1\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->8.8.1Peter Trommlerptrommler@acm.orgPeter Trommlerptrommler@acm.orghttps://gitlab.haskell.org/ghc/ghc/-/issues/15854PPC: Panic in native code generator2019-07-07T18:02:42ZPeter Trommlerptrommler@acm.orgPPC: Panic in native code generatorHead fails on powerpc64le:
```
ghc-stage1: panic! (the 'impossible' happened)
(GHC version 8.7.20181103 for powerpc64le-unknown-linux):
PPC.CodeGen.getRegister: no match
Please report this as a GHC bug: http://www.haskell.or...Head fails on powerpc64le:
```
ghc-stage1: panic! (the 'impossible' happened)
(GHC version 8.7.20181103 for powerpc64le-unknown-linux):
PPC.CodeGen.getRegister: no match
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
libraries/ghc-prim/ghc.mk:4: recipe for target 'libraries/ghc-prim/dist-install/build/GHC/PrimopWrappers.o' failed
```
I think I know what is going on and will work on a fix.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.7 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"PPC: Panic in native code generator","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"8.8.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.7","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Head fails on powerpc64le:\r\n{{{\r\nghc-stage1: panic! (the 'impossible' happened)\r\n (GHC version 8.7.20181103 for powerpc64le-unknown-linux):\r\n PPC.CodeGen.getRegister: no match\r\n\r\nPlease report this as a GHC bug: http://www.haskell.org/ghc/reportabug\r\n\r\nlibraries/ghc-prim/ghc.mk:4: recipe for target 'libraries/ghc-prim/dist-install/build/GHC/PrimopWrappers.o' failed\r\n}}}\r\n\r\nI think I know what is going on and will work on a fix.","type_of_failure":"OtherFailure","blocking":[]} -->8.8.1Peter Trommlerptrommler@acm.orgPeter Trommlerptrommler@acm.org