[GHC] #12755: Build from source fails on Ubuntu 16.10: ld: -r and -pie may not be used together

#12755: Build from source fails on Ubuntu 16.10: ld: -r and -pie may not be used together -------------------------------------+------------------------------------- Reporter: SamuelMarks | Owner: Type: bug | Status: new Priority: high | Milestone: Component: Build System | Version: 8.0.1 Keywords: | Operating System: Linux Architecture: x86_64 | Type of failure: Building GHC (amd64) | failed Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- {{{ "inplace/bin/ghc-stage1" -hisuf hi -osuf o -hcsuf hc -static -H32m -O -Wall -this-unit-id ghc-prim-0.5.0.0 -hide-all-packages -i -ilibraries/ghc-prim/. -ilibraries/ghc-prim/dist-install/build -ilibraries /ghc-prim/dist-install/build/autogen -Ilibraries/ghc-prim/dist- install/build -Ilibraries/ghc-prim/dist-install/build/autogen -Ilibraries /ghc-prim/. -optP-include -optPlibraries/ghc-prim/dist- install/build/autogen/cabal_macros.h -package-id rts -this-unit-id ghc- prim -XHaskell2010 -O2 -no-user-package-db -rtsopts -Wno-trustworthy-safe -Wno-deprecated-flags -Wnoncanonical-monad-instances -odir libraries /ghc-prim/dist-install/build -hidir libraries/ghc-prim/dist-install/build -stubdir libraries/ghc-prim/dist-install/build -split-objs -dynamic-too -c libraries/ghc-prim/./GHC/Types.hs -o libraries/ghc-prim/dist- install/build/GHC/Types.o -dyno libraries/ghc-prim/dist- install/build/GHC/Types.dyn_o /usr/bin/ld: -r and -pie may not be used together collect2: error: ld returned 1 exit status `gcc' failed in phase `Linker'. (Exit code: 1) libraries/ghc-prim/ghc.mk:4: recipe for target 'libraries/ghc-prim/dist- install/build/GHC/Types.o' failed make[1]: *** [libraries/ghc-prim/dist-install/build/GHC/Types.o] Error 1 Makefile:129: recipe for target 'all' failed make: *** [all] Error 2 }}} Googling showed other builds with similar errors, for a bug report [which is now resolved]: - https://wiki.ubuntu.com/SteveBeattie/PIENotes - https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1518483 Running with `ld` GNU ld (GNU Binutils for Ubuntu) 2.27. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12755 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12755: Build from source fails on Ubuntu 16.10: ld: -r and -pie may not be used together -------------------------------------+------------------------------------- Reporter: SamuelMarks | Owner: Type: bug | Status: new Priority: high | Milestone: Component: Build System | Version: 8.0.1 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 Type of failure: Building GHC | (amd64) failed | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by hvr): This is a known issue and there should be already related tickets filed about this in the GHC wiki. Also, in https://launchpad.net/~hvr/+archive/ubuntu/ghc I addressed this problem by simply calling `configure` a bit differently to make it work which basically comes down to {{{ CONF_CC_OPTS_STAGE2=-fno-PIE \ CONF_GCC_LINKER_OPTS_STAGE2=-no-pie \ CONF_LD_LINKER_OPTS_STAGE2=-no-pie \ ./configure }}} Did somebody come up with a reliable autoconf test already to detect whether `gcc` has `-no-pie` on by default? IIRC you can't rely on CPP for this and you really have to perform a compile and analyse the result, which is the main reason we haven't implemented it yet... -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12755#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12755: Build from source fails on Ubuntu 16.10: ld: -r and -pie may not be used together -------------------------------------+------------------------------------- Reporter: SamuelMarks | Owner: Type: bug | Status: new Priority: high | Milestone: Component: Build System | Version: 8.0.1 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 Type of failure: Building GHC | (amd64) failed | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by SamuelMarks): Thanks for those arguments, the build is currently running (no errors yet =]). Automated solutions to this problem include `grep` of: {{{ gcc -dumpspecs }}} Or a `readelf` like from [http://www.trapkit.de/tools/checksec.html checksec.sh]: {{{ #!bash if readelf -h $1 2>/dev/null | grep -q 'Type:[[:space:]]*EXEC'; then echo -n -e '\033[31mNo PIE \033[m ' elif readelf -h $1 2>/dev/null | grep -q 'Type:[[:space:]]*DYN'; then if readelf -d $1 2>/dev/null | grep -q '(DEBUG)'; then echo -n -e '\033[32mPIE enabled \033[m ' else echo -n -e '\033[33mDSO \033[m ' fi else echo -n -e '\033[33mNot an ELF file\033[m ' fi }}} Alternatively in C++ take a look at this [http://lists.llvm.org/pipermail /cfe-commits/Week-of-Mon-20130408/077610.html LLVM patch implementation] of `isPIEDefault`. [https://wiki.dlang.org/LDC ldc] uses `llvm::Reloc::PIC_` to check, see: [https://github.com/ximion/ldc/blob/d9496882163e173ea718756a7fb0cbc627c5326f/... ldc/driver/targetmachine.cpp#L521]. In particular see `Reloc::Model TargetMachine::getRelocationModel() const` in LLVM's [http://llvm.org/docs/doxygen/html/classllvm_1_1TargetMachine.html#a87f1815c4... TargetMachine.cpp]. Additionally there's this `gcc` patch [http://gcc.gnu.org/ml/gcc- patches/2016-07/msg01257.html check -nopie in configure]. The compile-and-see approach you mentioned is used in various places also, e.g.: `gccSupportsFlag` function under [https://github.com/gcc- mirror/gcc/blob/be239ed2ba619747b64629895116f209b58baee8/libgo/go/cmd/go/build.go#L3082 gcc/libgo/go/cmd/go/build.go#L3082]. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12755#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12755: Build from source fails on Ubuntu 16.10: ld: -r and -pie may not be used together -------------------------------------+------------------------------------- Reporter: SamuelMarks | Owner: Type: bug | Status: closed Priority: high | Milestone: 8.0.2 Component: Build System | Version: 8.0.1 Resolution: duplicate | Keywords: Operating System: Linux | Architecture: x86_64 Type of failure: Building GHC | (amd64) failed | Test Case: Blocked By: | Blocking: Related Tickets: #12759 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => closed * resolution: => duplicate * related: => #12759 * milestone: => 8.0.2 Comment: The problem here is that we pass `-Wl,-r` to `gcc` when joining object files and linking libraries. This is incompatible with the implicit `-pie` which the affected gcc versions assume. It turns out that GCC 6 has a `-r` flag which we could use in place of `-Wl,-r` and would do the right thing. Unfortunately it is undocumented so I'm rather reluctant to depend upon it. Really I suspect the correct solution here is to simply use `ld` directly for everything except for the final link (since linking an executable will likely require linking against `libgcc`). However, this is out of scope for 8.0.2. Consequently, I think the next best solution is to simply ensure we pass `-no-pie` to `gcc` when we do not intend on linking an executable. I have done exactly this in Phab:D2691 which has been merged to `master` (bae4a55b1fb403f610b4b55a1b6fb3f03e9c2026) and `ghc-8.0` (). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12755#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12755: Build from source fails on Ubuntu 16.10: ld: -r and -pie may not be used together -------------------------------------+------------------------------------- Reporter: SamuelMarks | Owner: Type: bug | Status: closed Priority: high | Milestone: 8.0.2 Component: Build System | Version: 8.0.1 Resolution: duplicate | Keywords: Operating System: Linux | Architecture: x86_64 Type of failure: Building GHC | (amd64) failed | Test Case: Blocked By: | Blocking: Related Tickets: #12759 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by rwbarton): What is the plan for binary releases regarding this change? Seeing as the decision about whether to pass `-no-pie` is made at build time, will there be a version available for those whose gcc is too old to support it? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12755#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

What is the plan for binary releases regarding this change? Seeing as
#12755: Build from source fails on Ubuntu 16.10: ld: -r and -pie may not be used together -------------------------------------+------------------------------------- Reporter: SamuelMarks | Owner: Type: bug | Status: closed Priority: high | Milestone: 8.0.2 Component: Build System | Version: 8.0.1 Resolution: duplicate | Keywords: Operating System: Linux | Architecture: x86_64 Type of failure: Building GHC | (amd64) failed | Test Case: Blocked By: | Blocking: Related Tickets: #12759 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): the decision about whether to pass -no-pie is made at build time, will there be a version available for those whose gcc is too old to support it? Oh dear, right. I suppose this will need to be placed in `settings`. Thanks for pointing that out. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12755#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC