Summary: | dev-lang/ghc-7.10.3 with PIE (gcc-7.3) - ld: /usr/lib64/ghc-7.10.3/rts/libHSrts.a(PrimOps.o): relocation R_X86_64_32S against symbol `g0' can not be used when making a PIE object; recompile with -fPIC | ||
---|---|---|---|
Product: | Gentoo Linux | Reporter: | Wolfram Kahl <kahl> |
Component: | Current packages | Assignee: | Gentoo's Haskell Language team <haskell> |
Status: | UNCONFIRMED --- | ||
Severity: | normal | ||
Priority: | Normal | ||
Version: | unspecified | ||
Hardware: | All | ||
OS: | Linux | ||
Whiteboard: | |||
Package list: | Runtime testing required: | --- | |
Attachments: | Output of `emerge --info` |
Could it be that you have not rebuilt ghc after switching to gcc-6+? -no-pie should be enough and is detected at build time: https://gitweb.gentoo.org/repo/gentoo.git/tree/dev-lang/ghc/ghc-7.10.3.ebuild#n251 I did emerge =dev-lang/ghc-7.10.3 on a brand-new gentoo install, from: stage3-amd64-20181227T214502Z.tar.xz I would hope that the resulting /usr/bin/ghc can compile a HelloWorld program... The referenced line enables: append-ghc-cflags compile link -no-pie I'd currently guess that the problem is that this does not pass -no-pie to the linker for pure Haskell compilations that do not involve C compilations. |
Created attachment 559052 [details] Output of `emerge --info` This is probably a continuation of the story of #606666: On a fresh stage3 install, to my delight, emerging ghc-7.10.3 works, and ghci appears to work. However, using ghc for compiling executables fails: Save the following in `Hello.hs`: ```` haskell module Main where main = putStrLn "Hello World!" ```` Then both ghc --make -O Hello rm Hello.o Hello.hi; ghc --make Hello fail with spectacularly long lists of linker errors ending in: ... /usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /usr/lib64/ghc-7.10.3/rts/libHSrts.a(PrimOps.o): relocation R_X86_64_32S against symbol `g0' can not be used when making a PIE object; recompile with -fPIC /usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /usr/lib64/ghc-7.10.3/rts/libHSrts.a(AutoApply.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC /usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /usr/lib64/ghc-7.10.3/base_HQfYBxpPvuw8OunzQu6JGM/libHSbase-4.8.2.0-HQfYBxpPvuw8OunzQu6JGM.a(FD__100.o): warning: relocation against `dup2@@GLIBC_2.2.5' in read-only section `.text' /usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: final link failed: Nonrepresentable section on output collect2: error: ld returned 1 exit status Trying profiling: rm Hello.o Hello.hi; ghc --make -prof Hello produces a shorter error report: [1 of 1] Compiling Main ( Hello.hs, Hello.o ) /usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: -r and -pie may not be used together collect2: error: ld returned 1 exit status Installing packages with USE=profile similarly fails: USE=profile emerge -av1 transformers ... [26 of 27] Compiling Control.Applicative.Backwards ( Control/Applicative/Backwards.hs, dist/build/Control/Applicative/Backwards.o ) [27 of 27] Compiling Data.Functor.Reverse ( Data/Functor/Reverse.hs, dist/build/Data/Functor/Reverse.o ) [ 1 of 27] Compiling Control.Monad.IO.Class ( legacy/pre711/Control/Monad/IO/Class.hs, dist/build/Control/Monad/IO/Class.p_o ) /usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: -r and -pie may not be used together collect2: error: ld returned 1 exit status <no location info>: ghc: phase `Linker' failed (exitcode = 1) ... All these are fixed by changing the last line of /usr/bin/ghc to: exec "$executablename" -B"$topdir" -optl-no-pie ${1+"$@"} Since I saw the ghc-7.10.3 emerge process invoke ghc with -optc-march=native -opta-march=native -optl-Wl,-O1 -optl-Wl,--as-needed -optc-no-pie -optl-no-pie I am however not confident that adding just -optl-no-pie is really sufficient --- probably more need to be added (including -fPIC / -optc-fPIC and/or -optc-fno-stack-protector ?). (I need ghc-7.10.3 for a production system based on Hase (haste-lang.org).)