Unhandled ELF relocation(RelA) type 42 when using ArchLinux
I have repository which compiles OK both on Arch and Ubuntu using stack LTS 5. Repository Link. On Ubuntu, I can also ghc-mod check files without a problem, but on Arch I get:
ghc-mod: /home/simeon/.stack/snapshots/x86_64-linux/lts-5.0/7.10.3/lib/x86_64-linux-ghc-7.10.3/HDBC-sqlite3-2.3.3.1-J7BRkfYWClZD8ttodrMiVd/libHSHDBC-sqlite3-2.3.3.1-J7BRkfYWClZD8ttodrMiVd.a: unhandled ELF relocation(RelA) type 42
unable to load package HDBC-sqlite3-2.3.3.1
On Ubuntu, GHC is 7.10.3 downloaded during stack setup and ghc-mod is compiled using it.
On Arch, I tried both compiling GHC and ghc-mod, and using system packages for both. I get the same results.
Here is ghc-mod debug from Arch:
Root directory: /home/simeon/repos/HLINQ
Current directory: /home/simeon/repos/HLINQ
GHC Package flags:
-hide-all-packages -no-user-package-db -package-db
/home/simeon/.stack/snapshots/x86_64-linux/lts-5.0/7.10.3/pkgdb
-package-db
/home/simeon/repos/HLINQ/.stack-work/install/x86_64-linux/lts-5.0/7.10.3/pkgdb
-package-id HDBC-2.4.0.1-9022dccb33fa7027f85b22fa779bd1cb
-package-id HDBC-sqlite3-2.3.3.1-1b20b2adef4cb0b0aa3ee08f557903c9
-package-id base-4.8.2.0-0d6d1084fbc041e1cded9228e80e264d
-package-id convertible-1.1.1.0-629af81285a24a4dffdb5da84aa32fd3
-package-id hashable-1.2.4.0-1c5b5b3e4d9b3066cec16b077238de40
-package-id
template-haskell-2.10.0.0-3c4cb52230f347282af9b2817f013181
GHC System libraries: /usr/lib/ghc-7.10.3
GHC user options:
Stack ghc executable: Just "/usr/bin/ghc"
Stack ghc-pkg executable:Just "/usr/bin/ghc-pkg"
Cabal file: Just "/home/simeon/repos/HLINQ/HLINQ.cabal"
Project: StackProject (StackEnv {seDistDir = ".stack-work/dist/x86_64-linux/Cabal-1.22.5.0", seBinPath = ["/home/simeon/.stack/snapshots/x86_64-linux/lts-5.0/7.10.3/bin","/home/simeon/.local/bin","/usr/local/sbin","/usr/local/bin","/usr/bin","/usr/bin/site_perl","/usr/bin/vendor_perl","/usr/bin/core_perl"], seSnapshotPkgDb = "/home/simeon/.stack/snapshots/x86_64-linux/lts-5.0/7.10.3/pkgdb", seLocalPkgDb = "/home/simeon/repos/HLINQ/.stack-work/install/x86_64-linux/lts-5.0/7.10.3/pkgdb"})
Cabal entrypoints:
Setup.hs
Main (/home/simeon/repos/HLINQ/Setup.hs)
library
Database.HLINQ (/home/simeon/repos/HLINQ/Database/HLINQ.hs)
Database.HLINQ.Info (/home/simeon/repos/HLINQ/Database/HLINQ/Info.hs)
Database.HLINQ.Utilities (/home/simeon/repos/HLINQ/Database/HLINQ/Utilities.hs)
Database.HLINQ.Info.Internal (/home/simeon/repos/HLINQ/Database/HLINQ/Info/Internal.hs)
Database.HLINQ.Deconstructor (/home/simeon/repos/HLINQ/Database/HLINQ/Deconstructor.hs)
Database.HLINQ.Constructor (/home/simeon/repos/HLINQ/Database/HLINQ/Constructor.hs)
Cabal components:
Setup.hs
Main (/home/simeon/repos/HLINQ/Setup.hs)
library
Database.HLINQ (/home/simeon/repos/HLINQ/Database/HLINQ.hs)
Database.HLINQ.Info
Database.HLINQ.Info (/home/simeon/repos/HLINQ/Database/HLINQ/Info.hs)
Database.HLINQ.Utilities
Database.HLINQ.Info.Internal
Database.HLINQ.Deconstructor
Database.HLINQ.Utilities (/home/simeon/repos/HLINQ/Database/HLINQ/Utilities.hs)
Database.HLINQ.Info.Internal (/home/simeon/repos/HLINQ/Database/HLINQ/Info/Internal.hs)
Database.HLINQ.Utilities
Database.HLINQ.Deconstructor
Database.HLINQ.Constructor
Database.HLINQ.Deconstructor (/home/simeon/repos/HLINQ/Database/HLINQ/Deconstructor.hs)
Database.HLINQ.Constructor
Database.HLINQ.Constructor (/home/simeon/repos/HLINQ/Database/HLINQ/Constructor.hs)
GHC Cabal options:
Setup.hs
library
-fbuilding-cabal-package -O -outputdir
.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build -odir
.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build -hidir
.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build -stubdir
.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build -i
-i.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build -i.
-i.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build/autogen
-I.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build/autogen
-I.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build -optP-include
-optP.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build/autogen/cabal_macros.h
-hide-all-packages -no-user-package-db -package-db
/home/simeon/.stack/snapshots/x86_64-linux/lts-5.0/7.10.3/pkgdb
-package-db
/home/simeon/repos/HLINQ/.stack-work/install/x86_64-linux/lts-5.0/7.10.3/pkgdb
-package-id HDBC-2.4.0.1-9022dccb33fa7027f85b22fa779bd1cb
-package-id HDBC-sqlite3-2.3.3.1-1b20b2adef4cb0b0aa3ee08f557903c9
-package-id base-4.8.2.0-0d6d1084fbc041e1cded9228e80e264d
-package-id convertible-1.1.1.0-629af81285a24a4dffdb5da84aa32fd3
-package-id hashable-1.2.4.0-1c5b5b3e4d9b3066cec16b077238de40
-package-id
template-haskell-2.10.0.0-3c4cb52230f347282af9b2817f013181
-XHaskell2010
GHC search path options:
Setup.hs
library
-i -i.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build -i.
-i.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build/autogen
-I.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build/autogen
-I.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build -optP-include
-optP.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build/autogen/cabal_macros.h
And ghc-mod debug from Ubuntu VM:
Root directory: /vagrant
Current directory: /vagrant
GHC Package flags:
-hide-all-packages -no-user-package-db -package-db
/home/vagrant/.stack/snapshots/x86_64-linux/lts-5.0/7.10.3/pkgdb
-package-db
/vagrant/.stack-work/install/x86_64-linux/lts-5.0/7.10.3/pkgdb
-package-id HDBC-2.4.0.1-6fef4f36861a75d59952102632a5fb32
-package-id HDBC-sqlite3-2.3.3.1-1b20b2adef4cb0b0aa3ee08f557903c9
-package-id base-4.8.2.0-0d6d1084fbc041e1cded9228e80e264d
-package-id convertible-1.1.1.0-82b9cd7e0c1851d519f2368947fa1dcf
-package-id hashable-1.2.4.0-53b854df9b1b40e67238bc0b030f3c19
-package-id
template-haskell-2.10.0.0-3c4cb52230f347282af9b2817f013181
GHC System libraries: /home/vagrant/.stack/programs/x86_64-linux/ghc-7.10.3/lib/ghc-7.10.3
GHC user options:
Stack ghc executable: Just "/home/vagrant/.stack/programs/x86_64-linux/ghc-7.10.3/bin/ghc"
Stack ghc-pkg executable:Just "/home/vagrant/.stack/programs/x86_64-linux/ghc-7.10.3/bin/ghc-pkg"
Cabal file: Just "/vagrant/HLINQ.cabal"
Project: StackProject (StackEnv {seDistDir = ".stack-work/dist/x86_64-linux/Cabal-1.22.5.0", seBinPath = ["/home/vagrant/.stack/snapshots/x86_64-linux/lts-5.0/7.10.3/bin","/home/vagrant/.stack/programs/x86_64-linux/ghc-7.10.3/bin","/home/vagrant/.local/bin","/usr/local/sbin","/usr/local/bin","/usr/sbin","/usr/bin","/sbin","/bin","/usr/games","/usr/local/games"], seSnapshotPkgDb = "/home/vagrant/.stack/snapshots/x86_64-linux/lts-5.0/7.10.3/pkgdb", seLocalPkgDb = "/vagrant/.stack-work/install/x86_64-linux/lts-5.0/7.10.3/pkgdb"})
Cabal entrypoints:
Setup.hs
Main (/vagrant/Setup.hs)
library
Database.HLINQ (/vagrant/Database/HLINQ.hs)
Database.HLINQ.Info (/vagrant/Database/HLINQ/Info.hs)
Database.HLINQ.Utilities (/vagrant/Database/HLINQ/Utilities.hs)
Database.HLINQ.Info.Internal (/vagrant/Database/HLINQ/Info/Internal.hs)
Database.HLINQ.Deconstructor (/vagrant/Database/HLINQ/Deconstructor.hs)
Database.HLINQ.Constructor (/vagrant/Database/HLINQ/Constructor.hs)
Cabal components:
Setup.hs
Main (/vagrant/Setup.hs)
library
Database.HLINQ (/vagrant/Database/HLINQ.hs)
Database.HLINQ.Info
Database.HLINQ.Info (/vagrant/Database/HLINQ/Info.hs)
Database.HLINQ.Utilities
Database.HLINQ.Info.Internal
Database.HLINQ.Deconstructor
Database.HLINQ.Utilities (/vagrant/Database/HLINQ/Utilities.hs)
Database.HLINQ.Info.Internal (/vagrant/Database/HLINQ/Info/Internal.hs)
Database.HLINQ.Utilities
Database.HLINQ.Deconstructor
Database.HLINQ.Constructor
Database.HLINQ.Deconstructor (/vagrant/Database/HLINQ/Deconstructor.hs)
Database.HLINQ.Constructor
Database.HLINQ.Constructor (/vagrant/Database/HLINQ/Constructor.hs)
GHC Cabal options:
Setup.hs
library
-fbuilding-cabal-package -O -outputdir
.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build -odir
.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build -hidir
.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build -stubdir
.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build -i
-i.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build -i.
-i.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build/autogen
-I.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build/autogen
-I.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build -optP-include
-optP.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build/autogen/cabal_macros.h
-hide-all-packages -no-user-package-db -package-db
/home/vagrant/.stack/snapshots/x86_64-linux/lts-5.0/7.10.3/pkgdb
-package-db
/vagrant/.stack-work/install/x86_64-linux/lts-5.0/7.10.3/pkgdb
-package-id HDBC-2.4.0.1-6fef4f36861a75d59952102632a5fb32
-package-id HDBC-sqlite3-2.3.3.1-1b20b2adef4cb0b0aa3ee08f557903c9
-package-id base-4.8.2.0-0d6d1084fbc041e1cded9228e80e264d
-package-id convertible-1.1.1.0-82b9cd7e0c1851d519f2368947fa1dcf
-package-id hashable-1.2.4.0-53b854df9b1b40e67238bc0b030f3c19
-package-id
template-haskell-2.10.0.0-3c4cb52230f347282af9b2817f013181
-XHaskell2010
GHC search path options:
Setup.hs
library
-i -i.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build -i.
-i.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build/autogen
-I.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build/autogen
-I.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build -optP-include
-optP.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build/autogen/cabal_macros.h
I've experienced this on Debian sid too, I don't remember if it was reloc type 42 or something else but other than that. I tracked it down to a change in GNU LD tripping up the dynamic linker in GHCi, the weird thing is that the reloc type I was looking at was added quite a few years ago so it's strange the error is only popping up now.
Maybe Stack is defaulting to dynamic linking whereas Cabal does static linking by default? I'm not actually sure what the defaults are though.
Anyways I'd try disabling dynamic linking.
I'm facing this problem as well, but with the double-conversion-2.0.1.0 package and without using stack (plain Cabal package), also on Arch. I'd like to try out disabling dynamic linking but could not dig out if that's possible for me (or how). Could you provide some pointers on how to do this, @DanielG ?
Hmm, looks like I was wrong. I could've sworn there is a --disable-library-dynamic flag for cabal but there isn't.
Since I can't think of any other workaround we'll have to report this upstream instead. Can you try loading an affected package in ghci and see if that break too? If that's the case reporting this is easy, if it is something ghc-mod specific though then I'll have to give it a closer look.
$ ghci -package double-conversion-2.0.1.0 should do, my guess would be that it will only crash once you actually import something from that package and maybe even only after you use something though so try that.
Hi,
I'm also experiencing this problem on Arch (unhandled ELF relocation(RelA) type 42 unable to load package yaml-0.8.16).
I'm not sure if this information can help, but if I create trivial file (no imports, simple main with basic type error) and call on it: stack exec ghc-mod -- check src/Check.hs I'm getting proper report from ghc-mod. It is enough to add QuasiQuoting or TemplateHaskell (I wasn't able to find any other problematic addon) language extensions to cause "unhandled ELF relocation".
My experiments with ghci -package double-conversion-2.0.1.0 worked, so it seems to be a ghc-mod problem. I'm also under the impression that it's related to TemplateHaskell, I just threw out some unused LANGUAGE pragmas (TH was among them); et voila: ghc-mod can again deal with my code. At least this solves my immediate problem. :-)
I also just encountered this on Arch with the package persistent-sqlite-2.2 (so TemplateHaskell is used for deriving Persistent fields). Loading it into ghci with ghci -package persistent-sqlite-2.2 works.
It's also curious that this only started happening in the last several days. A few days earlier I was able to ghc-mod check the same files without problems. I did an upgrade of system packages yesterday, yet I couldn't find anything that looked related in the list of packages upgraded.
@waldheinz If it's related to TH you can try passing -XTemplateHaskell to ghci so it has the same compiler configuration that ghc-mod would use. ghci -package double-conversion-2.0.1.0 -XTemplateHaskell.
@dkasak @paluh same request to you guys.
I'm also experiencing this problem on a new Ubuntu 16.04 installation, for the double-conversion-2.0.1.0 package. GHCi loading works for me, also with -XTemplateHaskell passed.
@DanielG ghci loads successfully even with -XTemplateHaskell.
@DanielG Same for me, though I'm not sure if I'm testing correctly. Here is what I do:
$ ghci -package double-conversion-2.0.1.0 -XTemplateHaskell
GHCi, version 7.10.3: http://www.haskell.org/ghc/ :? for help
Prelude> import Data.Double.Conversion.Text
Prelude Data.Double.Conversion.Text> import Data.Text
Prelude Data.Double.Conversion.Text Data.Text> toShortest 0.5
"0.5"
Is this enough to say that it works?
Happening to me as well with yaml-0.8.15.3. GHCI works just fine, even with -XTemplateHaskell
I'm getting this on Arch Linux too. In my case I blew away all of my ~/.{cabal,ghc,ghc-mod,stack} dirs, ran stack install ghc-mod then ran stack exec ghc-mod check src/Lib.hs and got:
ghc-mod: /home/golly/haskell/.stack/snapshots/x86_64-linux/lts-5.10/7.10.3/lib/x86_64-linux-ghc-7.10.3/cryptonite-0.10-9z0j8QI27Av2VIWw0mEkTO/libHScryptonite-0.10-9z0j8QI27Av2VIWw0mEkTO.a: unhandled ELF relocation(RelA) type 42
unable to load package `cryptonite-0.10'
Are there any known workarounds for this?
For arch linux, you can downgrade to 2016-02-21 and rebuild the cabal sandbox to get it working again.
On an up to date Arch, I can reproduce it by creating a new project and sandbox, installing glib-0.13.2, and adding {-# LANGUAGE TemplateHaskell #-} to Main.hs.
Output:
ghc-mod: /path/to/project/.cabal-sandbox/lib/x86_64-linux-ghc-7.10.3/glib-0.13.2.2-1k0TiRm3S3u0RjZ08MH1od/libHSglib-0.13.2.2-1k0TiRm3S3u0RjZ08MH1od.a: unhandled ELF relocation(RelA) type 42
unable to load package `glib-0.13.2.2'
Removing the TemplateHaskell pragma or not installing glib makes it work correctly.
One of the packages that was upgraded on 2016-02-21 was glibc, from 2.22-4 to 2.23-1, so that package may be the source of the problem.
The source of this problem seems to be that gas >= 2.26 uses some new relocation types (in particular type 42, aka R_X86_64_REX_GOTPCRELX), which are not supported by ghc's linker. As a workaround, these relocation types can be disabled by invoking ghc with the flag -opta-Wa,-mrelax-relocations=no. If you're using cabal you can pass the flag to ghc as follows:
cabal install --ghc-options="-opta-Wa,-mrelax-relocations=no"
It's probably necessary to reinstall all packages with this flag.
Could ghc-mod use the system dynamic linker (just like ghci) to fix this properly?
@sam142 Ah, that makes sense. I was just looking at the wrong component. I'm not aware of ghci being able to use the system linker is that something new or what exactly are you referring to?
Never mind found the docs for that https://ghc.haskell.org/trac/ghc/wiki/DynamicGhcPrograms.
I'm seeing this error as well:
$ runghc hello.hs
ghc: /home/sjackman/.linuxbrew/Cellar/ghc/7.10.3b/libexec/integer-gmp/lib/libgmp.a: unhandled ELF relocation(RelA) type 42
ghc: unable to load package `integer-gmp-1.0.0.0'
I'm also using gas 2.26.20160125. I don't see the error with ghc instead of runghc:
$ ghc hello.hs -o hello
$ ./hello
Hello, world!
Is there a fix, other than using an older version of binutils? Is there an upstream ghc ticket tracking this issue?
I'm facing the same problem with cipher-aes-0.2.11 after bootstrapping a minimal yesod project on ubuntu 16.04:
$ stack exec ghc-mod check Application.hs
ghc-mod: /home/docker/.stack/snapshots/x86_64-linux/lts-6.1/7.10.3/lib/x86_64-linux-ghc-7.10.3/cipher-aes-0.2.11-LCbQiUgBdfG1swKGFESvIB/libHScipher-aes-0.2.11-LCbQiUgBdfG1swKGFESvIB.a: unhandled ELF relocation(RelA) type 42
unable to load package `cipher-aes-0.2.11'
Using the ghc options -opta-Wa,-mrelax-relocations=no for cipher-aes didn't work.
I created a minimal docker file [1] to reproduce the error.
[1] https://gist.github.com/jmaicher/6d8b0e692285e4fe4f68cade25cbf127
filed a ghc ticket here https://ghc.haskell.org/trac/ghc/ticket/12147