Closed berdario closed 7 years ago
I think this might be the cause:
It seems likely that is the cause! Good sleuthing. I am using ubuntu 16.04, which is before the release with gcc hardening. I have ld-2.26.1
What should be done about this? Linking is not something I am very familiar with. Do we need to have a way to compile everything -fPIC? Perhaps we need to use the --no-pie
or --nopie
option on new enough GCCs? Is handling this the responsibility of Cabal.
I found that there are a few issues that have already been opened:
https://github.com/commercialhaskell/stack/issues/2542
https://github.com/commercialhaskell/stack/issues/2711
Frustratingly, all of them are now closed...
The good thing, is that a fix to add a ghc-build
option to disable PIE has been committed:
https://github.com/commercialhaskell/stack/commit/e3aa2388cefc083605091c55e92d9af09e048182
The bad thing is... I don't have that flag in Stack 1.2.0 :/
I'm currently building stack from sources, hopefully it'll work
(regardless if it works, stack setup --no-system-ghc
cannot work on Ubuntu 16.10 for stack <= 1.2.0
... so that should at least be mentioned/documented)
Those issues were recently resolved, they are not yet in a released version of stack. Use stack built from the git repo to get the fix!
Yeah, I tried it out.... it almost works
I'm not yet sure if the detection is broken... I'll test that soon
Anyhow, building my project still fails:
Configuring memory-0.13...
Building memory-0.13...
Preprocessing library memory-0.13...
/usr/bin/ld: .stack-work/dist/x86_64-linux-nopie/Cabal-1.24.0.0/build/Data/Memory/MemMap/Posix_hsc_make.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
linking .stack-work/dist/x86_64-linux-nopie/Cabal-1.24.0.0/build/Data/Memory/MemMap/Posix_hsc_make.o failed (exit code 1)
command was: /usr/bin/gcc .stack-work/dist/x86_64-linux-nopie/Cabal-1.24.0.0/build/Data/Memory/MemMap/Posix_hsc_make.o .stack-work/dist/x86_64-linux-nopie/Cabal-1.24.0.0/build/Data/Memory/MemMap/Posix_hsc_utils.o -o .stack-work/dist/x86_64-linux-nopie/Cabal-1.24.0.0/build/Data/Memory/MemMap/Posix_hsc_make -fno-PIE -fno-stack-protector -L/home/dario/.stack/programs/x86_64-linux/ghc-nopie-8.0.1/lib/ghc-8.0.1/bytestring-0.10.8.1 -Wl,-R,/home/dario/.stack/programs/x86_64-linux/ghc-nopie-8.0.1/lib/ghc-8.0.1/bytestring-0.10.8.1 -L/home/dario/.stack/programs/x86_64-linux/ghc-nopie-8.0.1/lib/ghc-8.0.1/deepseq-1.4.2.0 -Wl,-R,/home/dario/.stack/programs/x86_64-linux/ghc-nopie-8.0.1/lib/ghc-8.0.1/deepseq-1.4.2.0 -L/home/dario/.stack/programs/x86_64-linux/ghc-nopie-8.0.1/lib/ghc-8.0.1/array-0.5.1.1 -Wl,-R,/home/dario/.stack/programs/x86_64-linux/ghc-nopie-8.0.1/lib/ghc-8.0.1/array-0.5.1.1 -L/home/dario/.stack/programs/x86_64-linux/ghc-nopie-8.0.1/lib/ghc-8.0.1/base-4.9.0.0 -Wl,-R,/home/dario/.stack/programs/x86_64-linux/ghc-nopie-8.0.1/lib/ghc-8.0.1/base-4.9.0.0 -L/home/dario/.stack/programs/x86_64-linux/ghc-nopie-8.0.1/lib/ghc-8.0.1/integer-gmp-1.0.0.1 -Wl,-R,/home/dario/.stack/programs/x86_64-linux/ghc-nopie-8.0.1/lib/ghc-8.0.1/integer-gmp-1.0.0.1 -lgmp -L/home/dario/.stack/programs/x86_64-linux/ghc-nopie-8.0.1/lib/ghc-8.0.1/ghc-prim-0.5.0.0 -Wl,-R,/home/dario/.stack/programs/x86_64-linux/ghc-nopie-8.0.1/lib/ghc-8.0.1/ghc-prim-0.5.0.0 -L/home/dario/.stack/programs/x86_64-linux/ghc-nopie-8.0.1/lib/ghc-8.0.1/rts -Wl,-R,/home/dario/.stack/programs/x86_64-linux/ghc-nopie-8.0.1/lib/ghc-8.0.1/rts -lm -lrt -ldl
I guess that hsc2hs needs to be fixed as well (this feels like a can of worms :/ )
I confirm that the autodetection for the correct build-type works correctly.
I'd have suggested to release 1.2.1 as soon as possible, but without the fixes for hsc2hs there'll still be plenty of people who will find themselves unable to build their projects
Does this occur with GHCs from https://launchpad.net/~hvr/+archive/ubuntu/ghc as well?
I got the build working with your ghc... I'll try again to confirm by wiping my ~/.stack and rebuilding with the stack-supplied's ghc
Since about a week I'm experiencing strange build errors within Travis (and only there, not even in a local container): https://travis-ci.org/sgraf812/feed-gipeda/jobs/170090429
This also happens for previously green builds (e.g. from 2 months ago) when I restart them, but only my LTS-2.22 and LTS-6.2* builds are affected, the LTS-3.* and LTS-7.* builds are fine.
Is this related?
I got the build working with your ghc... I'll try again to confirm by wiping my ~/.stack and rebuilding with the stack-supplied's ghc
I mv
ed .stack
to .stack.bak
, and tried again... the problem happens with hvr's packages as well
not sure how earlier I got it to work at all
@berdario it would be interesting to see how exactly hsc2hs
is called; I've been using hsc2hs
on Ubuntu 16.10 w/o any issue (otoh, I use cabal, so this may be a Stack specific issue; so maybe hsc2hs
is called differently with Stack?)
I'm running Ubuntu 16.10 and seeing messages about fPIC as well.
/usr/bin/ld: /tmp/stack-sanity-check16859/Main.o: relocation R_X86_64_32S against symbol `stg_bh_upd_frame_info' can not be used when making a shared object; recompile with -fPIC
Same thing in Debian Sid with stack 1.2.0:
Fixed in master :+1:.
Building master with a snapshot that uses the same GHC version already available in the system works fine as a workaround , until stack 1.2.1 is released.
@hvr do you have any suggestions to discover how hsc2hs is being invoked by stack? The only idea I have is to use strace
(but it might take me a while to use it to find it out)
This is the content of the network
build log file:
[1 of 2] Compiling Main ( /tmp/stack1461/network-2.6.3.1/Setup.hs, /tmp/stack1461/network-2.6.3.1/.stack-work/dist/x86_64-linux/Cabal-1.24.0.0/setup/Main.o )
[2 of 2] Compiling StackSetupShim ( /tmp/stack1461/SetupShim.hs, /tmp/stack1461/network-2.6.3.1/.stack-work/dist/x86_64-linux/Cabal-1.24.0.0/setup/StackSetupShim.o )
Linking /tmp/stack1461/network-2.6.3.1/.stack-work/dist/x86_64-linux/Cabal-1.24.0.0/setup/setup ...
Configuring network-2.6.3.1...
configure: WARNING: unrecognized options: --with-compiler
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for gcc... /usr/bin/gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... configure: error: in `/tmp/stack1461/network-2.6.3.1':
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details
Unfortunately, there's no config.log
in the same directory. Do you have any idea where it might be?
Weirdly, memory
and clock
have the PIC-related error, but network
has a different one...
@rbasso
to avoid confusion, be aware that's not a sufficient solution. Try to build an empty project with any of the following packages among the build-depends: network
, memory
, clock
I updated the issue description with a (for now quite minimal) checklist about the steps that we can take... feel free to amend it as new details are understood
@hvr This is the output of strace -f -s 10000 -v -e trace=execve stack build ^| grep hsc
:
@berdario I don't use Stack myself so I can't debug this, but from the looks of it this is very likely a bug in Stack; it works flawless with cabal
and my PPA Ubuntu 16.10 packages.
@hvr I see (sorry, after this I'll stop notifying you), but there's one last interesting tidbit (as I mentioned in the other issue): This also happens with Cabal, if invoked via stack (so apparently, a few environment variables are enough to trigger the problem) like stack exec -- env -u GHC_PACKAGE_PATH cabal new-build -v
In order, the following will be built:
clock-0.7.2 (lib:clock) (requires build)
network-2.6.3.1 (lib:network) (requires build)
sfoo2-0.1.0.0 (lib:sfoo2 exe:sfoo2-exe) *test (dependency rebuilt)
creating /tmp/sfoo2/dist-newstyle/build
creating /tmp/sfoo2/dist-newstyle/tmp
Extracting
/home/dario/.cabal/packages/hackage.haskell.org/clock/0.7.2/clock-0.7.2.tar.gz
to /tmp/sfoo2/dist-newstyle/tmp/clock-27928...
Extracting
/home/dario/.cabal/packages/hackage.haskell.org/network/2.6.3.1/network-2.6.3.1.tar.gz
to /tmp/sfoo2/dist-newstyle/tmp/network-27928...
Updating clock.cabal with the latest revision from the index.
creating dist
Configuring clock-0.7.2...
/home/dario/.local/bin/cabal act-as-setup --build-type=Simple -- configure
--verbose=2 --builddir=dist --ghc
--prefix=/home/dario/.cabal/store/ghc-8.0.1/clock-0.7.2-f7bbbe23389d0d21e0674117ade8b1ebfca0e0c3219d350650a9dfb98261cd3d
--bindir=/home/dario/.cabal/store/ghc-8.0.1/clock-0.7.2-f7bbbe23389d0d21e0674117ade8b1ebfca0e0c3219d350650a9dfb98261cd3d/bin
--libdir=/home/dario/.cabal/store/ghc-8.0.1/clock-0.7.2-f7bbbe23389d0d21e0674117ade8b1ebfca0e0c3219d350650a9dfb98261cd3d/lib
--libsubdir=
--libexecdir=/home/dario/.cabal/store/ghc-8.0.1/clock-0.7.2-f7bbbe23389d0d21e0674117ade8b1ebfca0e0c3219d350650a9dfb98261cd3d/libexec
--datadir=/home/dario/.cabal/store/ghc-8.0.1/clock-0.7.2-f7bbbe23389d0d21e0674117ade8b1ebfca0e0c3219d350650a9dfb98261cd3d/share
--datasubdir=
--docdir=/home/dario/.cabal/store/ghc-8.0.1/clock-0.7.2-f7bbbe23389d0d21e0674117ade8b1ebfca0e0c3219d350650a9dfb98261cd3d/share/doc
--htmldir=/home/dario/.cabal/store/ghc-8.0.1/clock-0.7.2-f7bbbe23389d0d21e0674117ade8b1ebfca0e0c3219d350650a9dfb98261cd3d/share/doc/html
--haddockdir=/home/dario/.cabal/store/ghc-8.0.1/clock-0.7.2-f7bbbe23389d0d21e0674117ade8b1ebfca0e0c3219d350650a9dfb98261cd3d/share/doc/html
--sysconfdir=/home/dario/.cabal/store/ghc-8.0.1/clock-0.7.2-f7bbbe23389d0d21e0674117ade8b1ebfca0e0c3219d350650a9dfb98261cd3d/etc
--enable-library-vanilla --disable-library-profiling --enable-shared
--disable-executable-dynamic --disable-profiling --profiling-detail=default
--library-profiling-detail=default --enable-optimization --disable-debug-info
--disable-library-for-ghci --disable-split-objs --disable-executable-stripping
--disable-library-stripping --package-db=clear --package-db=global
--package-db=/home/dario/.cabal/store/ghc-8.0.1/package.db --flags=-llvm
--ipid=clock-0.7.2-f7bbbe23389d0d21e0674117ade8b1ebfca0e0c3219d350650a9dfb98261cd3d
--dependency=base=base-4.9.0.0 --disable-tests --disable-coverage
--exact-configuration --disable-benchmarks --with-ghc=/opt/ghc/bin/ghc
--with-ghc-pkg=/opt/ghc/bin/ghc-pkg
Redirecting build log to {handle: /home/dario/.cabal/logs/clock-0.7.2.log}
Updating network.cabal with the latest revision from the index.
creating dist
Configuring network-2.6.3.1...
/home/dario/.local/bin/cabal act-as-setup --build-type=Configure -- configure
--verbose=2 --builddir=dist --ghc
--prefix=/home/dario/.cabal/store/ghc-8.0.1/network-2.6.3.1-99cda5afd75e215db7c6caec4d6b56c40df41034fae26acb83e05712eb725a4f
--bindir=/home/dario/.cabal/store/ghc-8.0.1/network-2.6.3.1-99cda5afd75e215db7c6caec4d6b56c40df41034fae26acb83e05712eb725a4f/bin
--libdir=/home/dario/.cabal/store/ghc-8.0.1/network-2.6.3.1-99cda5afd75e215db7c6caec4d6b56c40df41034fae26acb83e05712eb725a4f/lib
--libsubdir=
--libexecdir=/home/dario/.cabal/store/ghc-8.0.1/network-2.6.3.1-99cda5afd75e215db7c6caec4d6b56c40df41034fae26acb83e05712eb725a4f/libexec
--datadir=/home/dario/.cabal/store/ghc-8.0.1/network-2.6.3.1-99cda5afd75e215db7c6caec4d6b56c40df41034fae26acb83e05712eb725a4f/share
--datasubdir=
--docdir=/home/dario/.cabal/store/ghc-8.0.1/network-2.6.3.1-99cda5afd75e215db7c6caec4d6b56c40df41034fae26acb83e05712eb725a4f/share/doc
--htmldir=/home/dario/.cabal/store/ghc-8.0.1/network-2.6.3.1-99cda5afd75e215db7c6caec4d6b56c40df41034fae26acb83e05712eb725a4f/share/doc/html
--haddockdir=/home/dario/.cabal/store/ghc-8.0.1/network-2.6.3.1-99cda5afd75e215db7c6caec4d6b56c40df41034fae26acb83e05712eb725a4f/share/doc/html
--sysconfdir=/home/dario/.cabal/store/ghc-8.0.1/network-2.6.3.1-99cda5afd75e215db7c6caec4d6b56c40df41034fae26acb83e05712eb725a4f/etc
--enable-library-vanilla --disable-library-profiling --enable-shared
--disable-executable-dynamic --disable-profiling --profiling-detail=default
--library-profiling-detail=default --enable-optimization --disable-debug-info
--disable-library-for-ghci --disable-split-objs --disable-executable-stripping
--disable-library-stripping --package-db=clear --package-db=global
--package-db=/home/dario/.cabal/store/ghc-8.0.1/package.db
--ipid=network-2.6.3.1-99cda5afd75e215db7c6caec4d6b56c40df41034fae26acb83e05712eb725a4f
--dependency=base=base-4.9.0.0 --dependency=bytestring=bytestring-0.10.8.1
--dependency=unix=unix-2.7.2.0 --disable-tests --disable-coverage
--exact-configuration --disable-benchmarks --with-ghc=/opt/ghc/bin/ghc
--with-ghc-pkg=/opt/ghc/bin/ghc-pkg
Redirecting build log to {handle: /home/dario/.cabal/logs/network-2.6.3.1.log}
Building clock-0.7.2...
/home/dario/.local/bin/cabal act-as-setup --build-type=Simple -- build
--verbose=2 --builddir=dist
Redirecting build log to {handle: /home/dario/.cabal/logs/clock-0.7.2.log}
network.log:
Configuring network-2.6.3.1...
Dependency base ==4.9.0.0: using base-4.9.0.0
Dependency bytestring ==0.10.8.1: using bytestring-0.10.8.1
Dependency unix ==2.7.2.0: using unix-2.7.2.0
Using Cabal-1.24.0.0 compiled by ghc-8.0
Using compiler: ghc-8.0.1
Using install prefix:
/home/dario/.cabal/store/ghc-8.0.1/network-2.6.3.1-99cda5afd75e215db7c6caec4d6b56c40df41034fae26acb83e05712eb725a4f
Binaries installed in:
/home/dario/.cabal/store/ghc-8.0.1/network-2.6.3.1-99cda5afd75e215db7c6caec4d6b56c40df41034fae26acb83e05712eb725a4f/bin
Libraries installed in:
/home/dario/.cabal/store/ghc-8.0.1/network-2.6.3.1-99cda5afd75e215db7c6caec4d6b56c40df41034fae26acb83e05712eb725a4f/lib
Private binaries installed in:
/home/dario/.cabal/store/ghc-8.0.1/network-2.6.3.1-99cda5afd75e215db7c6caec4d6b56c40df41034fae26acb83e05712eb725a4f/libexec
Data files installed in:
/home/dario/.cabal/store/ghc-8.0.1/network-2.6.3.1-99cda5afd75e215db7c6caec4d6b56c40df41034fae26acb83e05712eb725a4f/share
Documentation installed in:
/home/dario/.cabal/store/ghc-8.0.1/network-2.6.3.1-99cda5afd75e215db7c6caec4d6b56c40df41034fae26acb83e05712eb725a4f/share/doc
Configuration files installed in:
/home/dario/.cabal/store/ghc-8.0.1/network-2.6.3.1-99cda5afd75e215db7c6caec4d6b56c40df41034fae26acb83e05712eb725a4f/etc
No alex found
Using ar found on system at: /usr/bin/ar
No c2hs found
No cpphs found
Using gcc version 6.2.0 found on system at: /usr/bin/gcc
Using ghc version 8.0.1 given by user at: /opt/ghc/bin/ghc
Using ghc-pkg version 8.0.1 given by user at: /opt/ghc/bin/ghc-pkg
No ghcjs found
No ghcjs-pkg found
No greencard found
Using haddock version 2.17.2 found on system at: /opt/ghc/bin/haddock
No happy found
Using haskell-suite found on system at: haskell-suite-dummy-location
Using haskell-suite-pkg found on system at: haskell-suite-pkg-dummy-location
No hmake found
Using hpc version 0.67 found on system at: /usr/bin/hpc
Using hsc2hs version 0.68 found on system at: /opt/ghc/8.0.1/bin/hsc2hs
No hscolour found
No jhc found
Using ld found on system at: /usr/bin/ld
No lhc found
No lhc-pkg found
Using pkg-config version 0.29.1 found on system at: /usr/bin/pkg-config
Using strip version 2.27 found on system at: /usr/bin/strip
Using tar found on system at: /bin/tar
No uhc found
/bin/sh ./configure '--with-compiler=ghc' '--prefix=/home/dario/.cabal/store/ghc-8.0.1/network-2.6.3.1-99cda5afd75e215db7c6caec4d6b56c40df41034fae26acb83e05712eb725a4f' '--bindir=/home/dario/.cabal/store/ghc-8.0.1/network-2.6.3.1-99cda5afd75e215db7c6caec4d6b56c40df41034fae26acb83e05712eb725a4f/bin' '--libdir=/home/dario/.cabal/store/ghc-8.0.1/network-2.6.3.1-99cda5afd75e215db7c6caec4d6b56c40df41034fae26acb83e05712eb725a4f/lib' '--libexecdir=/home/dario/.cabal/store/ghc-8.0.1/network-2.6.3.1-99cda5afd75e215db7c6caec4d6b56c40df41034fae26acb83e05712eb725a4f/libexec' '--datadir=/home/dario/.cabal/store/ghc-8.0.1/network-2.6.3.1-99cda5afd75e215db7c6caec4d6b56c40df41034fae26acb83e05712eb725a4f/share' '--sysconfdir=/home/dario/.cabal/store/ghc-8.0.1/network-2.6.3.1-99cda5afd75e215db7c6caec4d6b56c40df41034fae26acb83e05712eb725a4f/etc' 'CC=/usr/bin/gcc'
configure: WARNING: unrecognized options: --with-compiler
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for gcc... /usr/bin/gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... configure: error: in `/tmp/sfoo2/dist-newstyle/tmp/network-27928/network-2.6.3.1':
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details
clock.log:
Configuring clock-0.7.2...
Flags chosen: llvm=False
Dependency base ==4.9.0.0: using base-4.9.0.0
Using Cabal-1.24.0.0 compiled by ghc-8.0
Using compiler: ghc-8.0.1
Using install prefix:
/home/dario/.cabal/store/ghc-8.0.1/clock-0.7.2-f7bbbe23389d0d21e0674117ade8b1ebfca0e0c3219d350650a9dfb98261cd3d
Binaries installed in:
/home/dario/.cabal/store/ghc-8.0.1/clock-0.7.2-f7bbbe23389d0d21e0674117ade8b1ebfca0e0c3219d350650a9dfb98261cd3d/bin
Libraries installed in:
/home/dario/.cabal/store/ghc-8.0.1/clock-0.7.2-f7bbbe23389d0d21e0674117ade8b1ebfca0e0c3219d350650a9dfb98261cd3d/lib
Private binaries installed in:
/home/dario/.cabal/store/ghc-8.0.1/clock-0.7.2-f7bbbe23389d0d21e0674117ade8b1ebfca0e0c3219d350650a9dfb98261cd3d/libexec
Data files installed in:
/home/dario/.cabal/store/ghc-8.0.1/clock-0.7.2-f7bbbe23389d0d21e0674117ade8b1ebfca0e0c3219d350650a9dfb98261cd3d/share
Documentation installed in:
/home/dario/.cabal/store/ghc-8.0.1/clock-0.7.2-f7bbbe23389d0d21e0674117ade8b1ebfca0e0c3219d350650a9dfb98261cd3d/share/doc
Configuration files installed in:
/home/dario/.cabal/store/ghc-8.0.1/clock-0.7.2-f7bbbe23389d0d21e0674117ade8b1ebfca0e0c3219d350650a9dfb98261cd3d/etc
No alex found
Using ar found on system at: /usr/bin/ar
No c2hs found
No cpphs found
Using gcc version 6.2.0 found on system at: /usr/bin/gcc
Using ghc version 8.0.1 given by user at: /opt/ghc/bin/ghc
Using ghc-pkg version 8.0.1 given by user at: /opt/ghc/bin/ghc-pkg
No ghcjs found
No ghcjs-pkg found
No greencard found
Using haddock version 2.17.2 found on system at: /opt/ghc/bin/haddock
No happy found
Using haskell-suite found on system at: haskell-suite-dummy-location
Using haskell-suite-pkg found on system at: haskell-suite-pkg-dummy-location
No hmake found
Using hpc version 0.67 found on system at: /usr/bin/hpc
Using hsc2hs version 0.68 found on system at: /opt/ghc/8.0.1/bin/hsc2hs
No hscolour found
No jhc found
Using ld found on system at: /usr/bin/ld
No lhc found
No lhc-pkg found
Using pkg-config version 0.29.1 found on system at: /usr/bin/pkg-config
Using strip version 2.27 found on system at: /usr/bin/strip
Using tar found on system at: /bin/tar
No uhc found
Component build order: library
creating dist/build
creating dist/build/autogen
Building clock-0.7.2...
/opt/ghc/bin/ghc-pkg init dist/package.conf.inplace
Preprocessing library clock-0.7.2...
creating dist/build/System
/opt/ghc/8.0.1/bin/hsc2hs '--cc=/usr/bin/gcc' '--ld=/usr/bin/gcc' '--cflag=-fno-PIE' '--cflag=-fno-stack-protector' '--lflag=-fno-PIE' '--lflag=-fno-stack-protector' '--cflag=-D__GLASGOW_HASKELL__=800' '--cflag=-Dlinux_BUILD_OS=1' '--cflag=-Dx86_64_BUILD_ARCH=1' '--cflag=-Dlinux_HOST_OS=1' '--cflag=-Dx86_64_HOST_ARCH=1' '--cflag=-Icbits' '--cflag=-Idist/build/autogen' '--cflag=-include' '--cflag=dist/build/autogen/cabal_macros.h' '--cflag=-I/opt/ghc/8.0.1/lib/ghc-8.0.1/base-4.9.0.0/include' '--cflag=-I/opt/ghc/8.0.1/lib/ghc-8.0.1/integer-gmp-1.0.0.1/include' '--cflag=-I/opt/ghc/8.0.1/lib/ghc-8.0.1/include' '--lflag=-L/opt/ghc/8.0.1/lib/ghc-8.0.1/base-4.9.0.0' '--lflag=-Wl,-R,/opt/ghc/8.0.1/lib/ghc-8.0.1/base-4.9.0.0' '--lflag=-L/opt/ghc/8.0.1/lib/ghc-8.0.1/integer-gmp-1.0.0.1' '--lflag=-Wl,-R,/opt/ghc/8.0.1/lib/ghc-8.0.1/integer-gmp-1.0.0.1' '--lflag=-lgmp' '--lflag=-L/opt/ghc/8.0.1/lib/ghc-8.0.1/ghc-prim-0.5.0.0' '--lflag=-Wl,-R,/opt/ghc/8.0.1/lib/ghc-8.0.1/ghc-prim-0.5.0.0' '--lflag=-L/opt/ghc/8.0.1/lib/ghc-8.0.1/rts' '--lflag=-Wl,-R,/opt/ghc/8.0.1/lib/ghc-8.0.1/rts' '--lflag=-lm' '--lflag=-lrt' '--lflag=-ldl' -o dist/build/System/Clock.hs System/Clock.hsc
Clock.hsc:44:0: warning: "hsc_alignment" redefined
In file included from dist/build/System/Clock_hsc_make.c:1:0:
/opt/ghc/8.0.1/lib/ghc-8.0.1/template-hsc.h:88:0: note: this is the location of the previous definition
#define hsc_alignment(t...) \
/usr/bin/ld: dist/build/System/Clock_hsc_make.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
linking dist/build/System/Clock_hsc_make.o failed (exit code 1)
command was: /usr/bin/gcc dist/build/System/Clock_hsc_make.o dist/build/System/Clock_hsc_utils.o -o dist/build/System/Clock_hsc_make -fno-PIE -fno-stack-protector -L/opt/ghc/8.0.1/lib/ghc-8.0.1/base-4.9.0.0 -Wl,-R,/opt/ghc/8.0.1/lib/ghc-8.0.1/base-4.9.0.0 -L/opt/ghc/8.0.1/lib/ghc-8.0.1/integer-gmp-1.0.0.1 -Wl,-R,/opt/ghc/8.0.1/lib/ghc-8.0.1/integer-gmp-1.0.0.1 -lgmp -L/opt/ghc/8.0.1/lib/ghc-8.0.1/ghc-prim-0.5.0.0 -Wl,-R,/opt/ghc/8.0.1/lib/ghc-8.0.1/ghc-prim-0.5.0.0 -L/opt/ghc/8.0.1/lib/ghc-8.0.1/rts -Wl,-R,/opt/ghc/8.0.1/lib/ghc-8.0.1/rts -lm -lrt -ldl
@berdario That's interesting... which env-vars does stack exec
inject ? does it by any chance inject CFLAGS or LDFLAGS? Those could easily cause Cabal to override the flags it would have passed to hsc2hs
by default
@hvr sorry I just realized that cabal new-build
fails for me even when executed outside of stack (I guess that I got confused, since cabal-install 1.24's new-build doesn't correctly set the exit code)
OTOH, I installed cabal-install via stack...
@berdario just to be sure, as I'm not able to reproduce the problem you're experiencing locally with cabal: could you try in a new empty user-account with cabal-install-1.24 & ghc-8.0.1 from my ppa? (you can try cabal-install-head
instead if you want to avoid the exit-code bug ); also, I assume you have the 16.10 specific .deb installed? (e.g. ghc-8.0.1 8.0.1-13~16.10
)
I already tried... it works
But it fails with cabal-install-1.22
and it seems that if I build stack from git, it's picking up Cabal-1.22 I suspect that might be the reason, but that doesn't explain why a cabal-install-1.24, built from stack doesn't work... that couldn't possibly be linked against Cabal-1.22, right?
https://github.com/commercialhaskell/stack/issues/2712#issuecomment-256856693
I am not sure how it relates to stack
but I have used cabal install --hsc2hs-option=--cflag=-fPIC --configure-option='CFLAGS=-fPIC' ...
to work around these compilation issues when using Cabal directly.
Btw, I was wrong: it's not due to Cabal-1.2{2,4} cabal-install-1.22 doesn't work, but that's probably unrelated to the Cabal library itself. I just built a stack on GHC8.0 from git with cabal-install-1.24 and the problem still appears (but I now realized that from my earlier error outputs some version of stack that I used was already using Cabal-1.24
I guess that if this has been fixed in cabal-install (and not Cabal itself), it's probably just a matter of passing the correct hsc2hs flags to the build (just like wilx suggested), and stack should be patched to do it by default (always?)
PS: otoh, cabal-install itself doesn't seem to handle the -fPIC
option anywhere in its code, that seems to be mostly dealt with by Cabal itself. The most recent change (after 1.22.0, but I'm not sure if it was included in 1.22.6) would probably be this:
https://github.com/haskell/cabal/commit/382143aa7322605d1a9f0480e383490e186c7ea0
which fixed this other bug: https://github.com/haskell/cabal/issues/2207
I am getting this bug also on
~ uname -a
Linux workbox 4.6.0-1-amd64 #1 SMP Debian 4.6.4-1 (2016-07-18) x86_64 GNU/Linux
~ stack --version
Version 1.2.0, Git revision 241cd07d576d9c0c0e712e83d947e3dd64541c42 (4054 commits) x86_64 hpack-0.14.0
I am now unable to build my project at all, I have tried deleting contents of .~/.stack
and wiping local .stack-work
to no avail.
@berdario IMO, the -fPIC
option is a red herring; you should rather investigate why --flag=-no-pie
is sometimes inhibited (and you won't find that flag hardcoded anywhere in Cabal/cabal's code base as it wouldn't belong there)
Running debian sid and was blocked on this. Was able to workaround using stack's docker support...(In case it helps anyone getting unblocked until the fix is released.)
Some discussion on Reddit (and a linked Haskell-cafe thread)
btw, if you're running Stack-1.2.1 from git and you have a nopie build, you'd have seen that the settings file already has the suggested options, but this is not enough (I suspect that alan_zimm on reddit might have had the same issues)
On ghc's Trac there's also a link to this
The fix is to pass -no-pie along with -Wl,-r to the compiler, but unfortunately that flag is very new as well.
Which apparently means that (unless people want to drop support of old gcc (and what about other compilers?), setting -no-pie
in the gcc flags of the affected libraries is probably not the best solution
Possibly related: https://github.com/haskell/cabal/issues/4080
I ran into this on ubuntu 16.10, but enabling nix support worked around the issue (I already had nix installed, but not enabled with stack).
Encountered this issue on Debian testing.
It's really inconvenient that this issue actually prevents you from upgrading stack to the latest git master.
On the latest Ubuntu/Debian it's impossible to get Stack installed in such a way that anything at all will build correctly. I've worked around it to some extent with a few Docker hacks but it's not great by any means.
Edit: my hack is published at https://github.com/ahri/isolated-stack - just symlink the stack.sh from your path somewhere. It'll build the image the first time you execute the script. It executes in a Docker-contained Debian Jessie, dropping files in your ~/.stack and ~/.local/bin dirs, meaning you can "stack install hoogle" and have a hoogle binary sat in your normal ~/.local/bin without needing Docker at runtime for installed programs.
I should say, this is only aimed at running on Debian-derived OSs that experience these problems.
I got it working.
Go to /home/you/.stack/programs/x86_64-linux/ghc-8.0.1/lib/ghc-8.0.1/settings
and change the following values to:
("C compiler flags", "-fno-PIE -fno-stack-protector"),
("C compiler link flags", "-no-pie"),
("ld flags", "-no-pie"),
and you should be ok. If you also have a previous version of ghc installed, change the settings there too.
Alan Zimmerman mentioned this in a Haskell-Cafe email back on October 31st.
@senorhesles I already tried, it doesn't work
Try to install the packages that I mentioned earlier (network
, memory
, clock
). I'd be surprised if it'd work for you
(but if it does, it's interesting, since the might be some other differences that trigger this problem)
@senorhesles Thank you! This worked for me perfectly! And at a really good time since my docker workaround encountered another issue. I've compiled quite few dependencies just fine. @berdario This includes network as well. I'll have to subscribe to haskell-caffe again to get stuff like this.
One thing to note though..since those flags are most likely concatenated with others it's probably required to have a space after the opening quote. Or at least that's the pattern I was with the values that were already in the settings file. So it might be worth editing your comment.
It builds in my case Just adapt the ghc version which has the error (ghc-8.0.01 above or ghc-7.10 in my case: ~/.stack/programs/x86_64-linux/ghc-7.10.3/lib/ghc-7.10.3/settings )
cp settings settings.bak
And change the options as @senorhesles mentionned previously: ("C compiler flags", "-fno-PIE -fno-stack-protector"), ("C compiler link flags", "-no-pie"), ("ld flags", "-no-pie"),
It builds, yes, but I wonder the effects of adding such options (-no-pie) in long term use. Ok for the hack but how long should we maintain it (mv settings.bak settings) ?
I still cannot "stack install memory", even with these settings. Does it work for anyone else?
On Wed, Nov 16, 2016 at 10:08 AM, Alexandre Delanoë < notifications@github.com> wrote:
It builds in my case Just adapt the ghc version which has the error (ghc-8.0.01 above or ghc-7.10 in my case: ~/.stack/programs/x86_64-linux/ghc-7.10.3/lib/ghc-7.10.3/settings )
cp settings settings.bak
And change the options as @senorhesles https://github.com/senorhesles mentionned previously: ("C compiler flags", "-fno-PIE -fno-stack-protector"), ("C compiler link flags", "-no-pie"), ("ld flags", "-no-pie"),
It builds, yes, but I wonder the effects of adding such options (-no-pie) in long term use. Ok for the hack but how long should we maintain it (mv settings.bak settings) ?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/commercialhaskell/stack/issues/2712#issuecomment-260880515, or mute the thread https://github.com/notifications/unsubscribe-auth/AAZAB9i4I2Po45oLZe1td-_Ddjke1Mi2ks5q-roHgaJpZM4KYH8P .
@alanz nope, https://github.com/commercialhaskell/stack/issues/2712#issuecomment-260804267 didn't work for me on Ubuntu 16.10 as well
I had this issue running 16.10, so I though I would write up some instructions on how to work around it.
You run stack build
and get some error mentioning can not be used when making a shared object; recompile with -fPIC
.
ghc
in the terminal produces a not found message)stack build
not work?It seems that the ghc installed by stack has a problem. To make stack build
work we thus need to use a system ghc that is not installed by stack.
Remove the ghc installed by stack. Follow the directions here to remove your project's .stack-work
folder, and your ~/.stack
folder. The ghc installed by stack is in ~/.stack
, so deleting ~/.stack
removes it.
Install ghc from this PPA. I need ghc 8.0.1, so I do: sudo add-apt-repository ppa:hvr/ghc
, sudo apt update
, and sudo apt install ghc-8.0.1 ghc-8.0.1-prof ghc-8.0.1-htmldocs
Add ghc to the path. Add the line PATH="$PATH:/opt/ghc/bin"
to your ~/.profile
. Log out and log back in again.
stack build
should now work
Edit 1: To get stack build --profile
or stack build --trace
to work, you need to install ghc-$VER-prof
, so for me I needed to do sudo apt install ghc-8.0.1-prof
.
Edit 2: I just installed stack 1.3.0 via the Ubuntu software updater. I needed to do stack setup
, and then stack config set system-ghc --global true
to get stack build
to work again.
@rgleichman whoa cool, confirm that works for 8.0.1 and ubuntu 16.10!
I used this stack.yaml
with Stack 1.2.1:
compiler-check: match-exact
resolver: ghc-8.0.1.20161117
setup-info:
ghc:
linux64-nopie:
8.0.1.20161117:
url: http://downloads.haskell.org/~ghc/8.0.2-rc1/ghc-8.0.1.20161117-x86_64-deb8-linux.tar.xz
content-length: 112047972
sha1: 6a6e4c9c53c71cc84b6966a9f61948542fd2f15a
and it succeded to install memory
. So maybe this issue could be solved as soon as the new GHC will be available in a LTS? (this means that GHC 8.0.1 will not be supported with Stack on recent Linuxes, but I'd personally find that acceptable)
@senorhesles @delanoe how about ghcjs? where such options?
I think I figured out the problem with network
, memory
, old-time
, etc. ~/.stack/programs/x86_64-linux/ghc-nopie-8.0.1/lib/ghc-8.0.1/settings
contains these two lines:
("C compiler flags", "-fno-PIE -fno-stack-protector"),
("C compiler link flags", "-no-pie"),
They are applied by GHC at compile time and link time, respectively and everything works. However, autoconf builds executables in one shot with GCC (for testing various things) and passes only the first set. -fno-PIE
affects compilation; -no-pie
affects both compilation and linking. Replacing -fno-PIE
with -no-pie
in the first line fixes the issue. I don't know how the bindists are generated or how the options are set, otherwise I'd offer a PR.
Works for me, editing my local ghc settings file. Thanks.
https://github.com/commercialhaskell/stack/issues/2712#issuecomment-260804267
This worked for me! Thanks!!
@enolan - thanks! That was the one that fixed it for me.
thanks to @senorhesles and @enolan , the following settings are working for me
("C compiler flags", "-no-pie -fno-stack-protector"),
("C compiler link flags", "-no-pie"),
("ld flags", "-no-pie")
With fresh stack-1.3
, I have GHC installed successfully in nopie
mode, without modifying settings
file in GHC guts, but. as @berdario mentioned before,
Weirdly,
memory
andclock
have the PIC-related error, butnetwork
has a different one...
is still an issue.
This fixes the issue for me.
sed -i 's/-fno-PIE/-no-pie/g' ~/.stack/programs/x86_64-linux/ghc-nopie-8.0.1/lib/ghc-8.0.1/settings
Ubuntu 16.10, GCC 6.2, latest Stack
This can be easily fixed in your GHC installation:
Hopefully a fixed bindist (or the newer GHC 8.0.2 which ships with this fix already) will be released soon
Steps needed to support Linux distributions that enable PIE by default (Ubuntu 16.10, Debian Sid, etc.)
Old issue description:
This it the same issue that I reported in this other ticket, but I now realized that my "fix" of removing
~/.stack/programs/x86_64-linux/ghc-8.0.1/
actually brought stack in an inconsistent state... and without it being aware of it, it was always selecting the system-installed ghc.I thus moved away the whole
~/.stack/
directory, and tried to setup again... I tried both with lts version 7 and 6 (with--no-system-ghc
), and the setup of ghc fails at linking step with both versionsI'm running Ubuntu 16.10, and I'm running
The error is the same as in the other ticket, which I'll link again here
Stack version
Method of installation
Installed into
~/.local/bin/
viastack upgrade