New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linker error makes it impossible to use a stack-provided ghc #2712

Closed
berdario opened this Issue Oct 16, 2016 · 83 comments

Comments

Projects
None yet
@berdario
Contributor

berdario commented Oct 16, 2016

This can be easily fixed in your GHC installation:

sed -i 's/-fno-PIE/-no-pie/g' ~/.stack/programs/x86_64-linux/ghc-nopie-8.0.1/lib/ghc-8.0.1/settings

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.)

  • Release Stack 1.2.1
  • Discover hsc2hs/config build errors cause (edit: maybe hsc2hs uses autotools directly? anyhow now we have a solution)
  • Prepare new ghc nopie build to fix the hsc2hs errors?

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 versions

I'm running Ubuntu 16.10, and I'm running

gcc (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005
GNU ld (GNU Binutils for Ubuntu) 2.27

The error is the same as in the other ticket, which I'll link again here

Stack version

Version 1.2.0 x86_64 hpack-0.14.0

Method of installation

Installed into ~/.local/bin/ via stack upgrade

@berdario

This comment has been minimized.

Contributor

berdario commented Oct 16, 2016

I think this might be the cause:

https://wiki.ubuntu.com/SecurityTeam/PIE

@mgsloan

This comment has been minimized.

Collaborator

mgsloan commented Oct 17, 2016

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.

@mgsloan mgsloan added this to the P2: Should milestone Oct 17, 2016

@berdario

This comment has been minimized.

Contributor

berdario commented Oct 17, 2016

I found that there are a few issues that have already been opened:

#2542

#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:

e3aa238

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)

@mgsloan

This comment has been minimized.

Collaborator

mgsloan commented Oct 17, 2016

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!

@mgsloan mgsloan removed the type: discuss label Oct 17, 2016

@mgsloan mgsloan modified the milestones: Support, P2: Should Oct 17, 2016

@berdario

This comment has been minimized.

Contributor

berdario commented Oct 17, 2016

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 :/ )

@berdario

This comment has been minimized.

Contributor

berdario commented Oct 17, 2016

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

@hvr

This comment has been minimized.

hvr commented Oct 25, 2016

Does this occur with GHCs from https://launchpad.net/~hvr/+archive/ubuntu/ghc as well?

@berdario

This comment has been minimized.

Contributor

berdario commented Oct 25, 2016

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

@sgraf812

This comment has been minimized.

Contributor

sgraf812 commented Oct 25, 2016

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?

@berdario

This comment has been minimized.

Contributor

berdario commented Oct 25, 2016

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 mved .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

@hvr

This comment has been minimized.

hvr commented Oct 25, 2016

@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?)

@robmoore

This comment has been minimized.

robmoore commented Oct 25, 2016

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
@rbasso

This comment has been minimized.

rbasso commented Oct 26, 2016

Same thing in Debian Sid with stack 1.2.0:

  • Doing anything with stack's downloaded GHCs fails.
  • Using system's GHC everything works fine.

Fixed in master 👍.

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.

@berdario

This comment has been minimized.

Contributor

berdario commented Oct 26, 2016

@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

@berdario

This comment has been minimized.

Contributor

berdario commented Oct 26, 2016

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

@berdario

This comment has been minimized.

Contributor

berdario commented Oct 27, 2016

@hvr This is the output of strace -f -s 10000 -v -e trace=execve stack build ^| grep hsc:

https://gist.github.com/48a2afdadad3edfc8db606ed58269443

@hvr

This comment has been minimized.

hvr commented Oct 28, 2016

@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.

@berdario

This comment has been minimized.

Contributor

berdario commented Oct 28, 2016

@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
@hvr

This comment has been minimized.

hvr commented Oct 28, 2016

@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

@berdario

This comment has been minimized.

Contributor

berdario commented Oct 28, 2016

@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...

@hvr

This comment has been minimized.

hvr commented Oct 28, 2016

@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)

@berdario

This comment has been minimized.

Contributor

berdario commented Oct 28, 2016

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?

@wilx

This comment has been minimized.

wilx commented Oct 28, 2016

#2712 (comment)

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.

@ardeleanasm

This comment has been minimized.

ardeleanasm commented Jul 24, 2017

Seems to have same linking problem for clock.

OS: 4.11.9-1-ARCH
GHC: 8.0.2
Stack Version: 1.4.0

--  While building package clock-0.7.2 using:
      /home/mihai/.stack/setup-exe-cache/x86_64-linux-tinfo6-nopie/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0 build --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1
    Logs have been written to: /home/mihai/Development/qchas/.stack-work/logs/clock-0.7.2.log

    Configuring clock-0.7.2...
    Building clock-0.7.2...
    Preprocessing library clock-0.7.2...
    Clock.hsc:44:0: warning: "hsc_alignment" redefined
    In file included from .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/System/Clock_hsc_make.c:1:0:
    /home/mihai/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/template-hsc.h:88:0: note: this is the location of the previous definition
     #define hsc_alignment(t...) \
     
    /usr/bin/ld: .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/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 .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/System/Clock_hsc_make.o failed (exit code 1)
    command was: /usr/bin/gcc .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/System/Clock_hsc_make.o .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/System/Clock_hsc_utils.o -o .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/System/Clock_hsc_make -fno-PIE -fno-stack-protector -L/home/mihai/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/base-4.9.1.0 -Wl,-R,/home/mihai/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/base-4.9.1.0 -L/home/mihai/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/integer-gmp-1.0.0.1 -Wl,-R,/home/mihai/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/integer-gmp-1.0.0.1 -lgmp -L/home/mihai/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/ghc-prim-0.5.0.0 -Wl,-R,/home/mihai/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/ghc-prim-0.5.0.0 -L/home/mihai/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/rts -Wl,-R,/home/mihai/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/rts -lm -lrt -ldl -lpthread

is there a fix?

Edit: Seems that the problem was fixed by installing ncurses5-compat-libs.

@nd2s

This comment has been minimized.

nd2s commented Jul 27, 2017

@ardeleanasm I'm on stack 1.5.0 on Arch and reinstalling doesn't work.

@ardeleanasm

This comment has been minimized.

ardeleanasm commented Jul 27, 2017

@nd2s I don't have the problem anymore. I installed ncurses5-compat-libs, removed /home/user/.stack/ and reinstalled stack. hope it works!

@nd2s

This comment has been minimized.

nd2s commented Jul 27, 2017

@ardeleanasm Installing ncurses5-compat-libs fixed it, didn't need to reinstall stack. Many thanks!

@ardeleanasm

This comment has been minimized.

ardeleanasm commented Jul 27, 2017

@nd2s you're welcome and I'm glad I could help you!

@schoettl

This comment has been minimized.

schoettl commented Aug 8, 2017

I had the same problem since about 2 weeks. I'm on Arch Linux with stack 1.5.1 and GHC 7.10.3 (according to the build plan).

Finally, the @berdario's fix solved the problem for me.

My project is a @yesodweb Yesod app, so maybe it is related to position independent execution (PIE). I don't have hardening-wrapper installed. I tried a lot with -static, -fPIC, ... as suggested in similar problem reports.

There is a short FAQ entry on this problem, too.

@NorfairKing

This comment has been minimized.

Contributor

NorfairKing commented Sep 28, 2017

I'm having this problem now and installing ncurses5-compat-libs doesn't work, even after removing ~/.stack and re-installing stack.

EDIT:
In my case I had to un-install ncurses5-compat-libs and install ncurses-full.

@Gzernov

This comment has been minimized.

Gzernov commented Oct 24, 2017

I've also had this problem on arch. As been said on wiki there are some troubles with dynamic and static link. So, basically, I tried to installed some libs depend on old base (<4.10) with brand new ghc, just from arch repo, and then ran into dependency hell with errors like described above. So what i've done

  1. Installed static linked stack from official site (dynamically on official arch repo)
  2. Installed ghc with stack --install-ghc
  3. Tried to install stylish-haskell with stack, failed to compile old-time with '-fPIC' error
  4. Manually extract it with
stack unpack old-time
cd old-time
stack init
stack build 
  1. Found out that it need old base lib, so firstly tried to install ghc 7.10.3 with stack, but again the same error. Than i did the following
cd ~/.stack/programs/x86_64-linux
rm -rf ghc-tinfo6-nopie-7.10.3
tar xvfJ ghc-tinfo6-nopie-7.10.3.tar.xz
cd ghc-7.10.3 
./configure --with-hs-cpp-flags='-E -undef -traditional -fPIC -fno-PIE' --prefix=~/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-7.10.3
make install
cd ~/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-7.10.3/lib/ghc-7.10.3/
vi settings 
  1. Changed C compiler flags to ("C compiler flags", "-fno-PIE -fPIC -fno-stack-protector")
  2. Than returned to old-time dir and rebuild it. (Do not forget to remove .stack-work)

That's it! Finally I managed to install stylish-haskell.

@t3hmrman

This comment has been minimized.

t3hmrman commented Nov 5, 2017

Just ran into this issue on arch, trying to build a project that had been building fine up until now. After checking this issue and #3518 , What worked for me was a slight variation of @Gzernov 's process above:

  1. Download statically linked stack from stackage
  2. Use downloaded stack to enter ghci (by running stack ghci)

That worked for me, but unfortunately, stack build still didn't produce anything (it produced a file named a.out once I believe, but not consistently, and it seems to be ignoring the project configuration).

After that I remembered that I have --static specified in my .cabal file ld-options, and thought maybe removing that might help, and avoid trying to even do a static build at all locally (it didn't help).

Luckily for me when it's time to actually deploy I build my project inside a docker container (and during local development run from GHCI), so being able to start GHCI is enough for me as far as local development goes.

UPDATE - stack build does seem to work properly with statically linked stack executable after a while... I just used stack ghci as normal and after a while stack build produced the output I'd expect (and built the expected executables). Sorry I don't have a better timeline of what I actually did that might have affected stack build.

@pera

This comment has been minimized.

pera commented Nov 10, 2017

@t3hmrman I think the problem in Arch started a month ago after this change to the ncurses package.

Check senorhesles's workaround: adding "-no-pie" did the trick for me.

@mkoloberdin

This comment has been minimized.

mkoloberdin commented Nov 18, 2017

@Gzernov, @t3hmrman, @pera The following workaround alleviates this issue on Arch Linux:

Install ghc with:

stack setup --ghc-build=ncurses6

Then add ghc-build: ncurses6 to ~/.stack/config.yaml, otherwise stack will try to download and install the tinfo6-nopie build on every attempt to use stack.

@schoettl

This comment has been minimized.

schoettl commented Nov 28, 2017

This problem still exists on Arch with current stack 1.5.1 and GHC 8.0.2.

I had to change this in the settings file:

vi ~/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/settings 
- ("C compiler flags", "-fno-PIE -fno-stack-protector"),
+ ("C compiler flags", "-no-pie -fno-stack-protector"),

Before I found this solution, I desperately removed everything related to xmonad, haskell, stack, cabal, ghc, including ~/.stack, ~/.cabal. Then I installed only stack and tried stack --install-ghc; stack install xmonad. The second command failed at the setlocale package with weired ld related errors. After the changed the settings file everything worked.

@drvink

This comment has been minimized.

drvink commented Dec 20, 2017

I'm having this problem with Arch and Stack 1.6.1 with ghc 8.2.2 as well. Changing to -no-pie as mentioned in #2712 (comment) fixes the issue for me.

@chrissound

This comment has been minimized.

chrissound commented Dec 24, 2017

Adding ghc-build: nopie to ~/.stack/config.yaml fixed this for me.. Not sure if it's the same issue...

@borsboom

This comment has been minimized.

Contributor

borsboom commented Dec 24, 2017

@chrissound, @drvink: This is being discussed in #3518.

borsboom added a commit that referenced this issue Dec 30, 2017

borsboom added a commit that referenced this issue Jan 5, 2018

borsboom added a commit that referenced this issue Jan 5, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment