haskell / haskell/cabal

foreign-libraries break with --enable-profiling

Open
#4,243 13 comments 1 reaction 0 assignees View on GitHub
Cabal: stanza/foreign-library type: bug
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

When I compile a project with `foreign-library` sections with `--enable-profiling` `ld` complains about impossible relocations when compiling the flib component. I am using Cabal/cabal-install from [master](https://github.com/haskell/cabal/commit/9db9e696ba14640a3da6c0856f9f0034ed6fe083).

The errors look suspiciously simmilar to the ones from the [GHC bug report about Debian/Ubuntu enabling PIE by default](https://ghc.haskell.org/trac/ghc/ticket/12759), not sure if that's actually related. I'm pretty sure my compilers aren't affected by that since I can also reproduce it in jessie, see below.

To reproduce:

```
$ git clone https://gist.github.com/b0c119d866799812fa2c9d367d67e84a.git
$ cd b0c119d866799812fa2c9d367d67e84a
$ cabal new-build --enable-profiling
```

On Debian jessie (using the ghc-7.8.4 bindist):
```
Resolving dependencies...
In order, the following will be built (use -v for more details):
- foreign-lib-0 (flib:foo) --enable-profiling (first run)
Configuring component flib:foo from foreign-lib-0...
Preprocessing foreign library 'foo' for foreign-lib-0...
[1 of 1] Compiling Lib ( Lib.hs, /home/dxld/share/dev/hs/testing/foreign-lib/dist-newstyle/build/x86_64-linux/ghc-7.8.4/foreign-lib-0/c/foo/build/foo/foo-tmp/Lib.p_o )
[1 of 1] Compiling Lib ( Lib.hs, /home/dxld/share/dev/hs/testing/foreign-lib/dist-newstyle/build/x86_64-linux/ghc-7.8.4/foreign-lib-0/c/foo/build/foo/foo-tmp/Lib.p_o ) [flags changed]
Linking /home/dxld/share/dev/hs/testing/foreign-lib/dist-newstyle/build/x86_64-linux/ghc-7.8.4/foreign-lib-0/c/foo/build/foo/libfoo.so ...
/usr/bin/ld: /usr/local/lib/ghc-7.8.4/base-4.7.0.2/libHSbase-4.7.0.2_p.a(Base__115.p_o): relocation R_X86_64_32S against `era' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/ghc-7.8.4/base-4.7.0.2/libHSbase-4.7.0.2_p.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
```

On Debian sid:
```
Resolving dependencies...
In order, the following will be built (use -v for more details):
- foreign-lib-0 (flib:foo) --enable-profiling (first run)
Configuring component flib:foo from foreign-lib-0...
Preprocessing foreign library 'foo' for foreign-lib-0...
[1 of 1] Compiling Lib ( Lib.hs, /home/dxld/share/dev/hs/testing/foreign-lib/dist-newstyle/build/x86_64-linux/ghc-8.0.2/foreign-lib-0/c/foo/build/foo/foo-tmp/Lib.p_o )
[1 of 1] Compiling Lib ( Lib.hs, /home/dxld/share/dev/hs/testing/foreign-lib/dist-newstyle/build/x86_64-linux/ghc-8.0.2/foreign-lib-0/c/foo/build/foo/foo-tmp/Lib.p_o ) [flags changed]
Linking /home/dxld/share/dev/hs/testing/foreign-lib/dist-newstyle/build/x86_64-linux/ghc-8.0.2/foreign-lib-0/c/foo/build/foo/libfoo.so ...
/usr/bin/ld: /home/dxld/var/local/stow/ghc-8.0.2/lib/ghc-8.0.2/base-4.9.1.0/libHSbase-4.9.1.0_p.a(Base__165.p_o): relocation R_X86_64_32S against symbol `era' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/dxld/var/local/stow/ghc-8.0.2/lib/ghc-8.0.2/base-4.9.1.0/libHSbase-4.9.1.0_p.a(Base__166.p_o): relocation R_X86_64_32S against symbol `era' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/dxld/var/local/stow/ghc-8.0.2/lib/ghc-8.0.2/base-4.9.1.0/libHSbase-4.9.1.0_p.a(Base__170.p_o): relocation R_X86_64_32S against symbol `era' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/dxld/var/local/stow/ghc-8.0.2/lib/ghc-8.0.2/base-4.9.1.0/libHSbase-4.9.1.0_p.a(Base__172.p_o): relocation R_X86_64_32S against symbol `era' can not be used when making a shared object; recompile with -fPIC
[...]
/usr/bin/ld: /usr/lib/ghc/ghc-prim-0.5.0.0/libHSghc-prim-0.5.0.0_p.a(Types__328.p_o): relocation R_X86_64_32S against symbol `era' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/lib/ghc/ghc-prim-0.5.0.0/libHSghc-prim-0.5.0.0_p.a(Types__327.p_o): relocation R_X86_64_32S against symbol `era' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/lib/ghc/base-4.9.0.0/libHSbase-4.9.0.0_p.a(Base__1.p_o): relocation R_X86_64_PC32 against undefined symbol `CCS_LIST' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
`gcc' failed in phase `Linker'. (Exit code: 1)
```

Verbose output with `-v` here: [Sid log](https://gist.githubusercontent.com/DanielG/b0c119d866799812fa2c9d367d67e84a/raw/d5b9ebade9e8fe2cd71e9016e300831ce6584318/debian-sid-verbose.log), [Jessie log](https://gist.githubusercontent.com/DanielG/b0c119d866799812fa2c9d367d67e84a/raw/d5b9ebade9e8fe2cd71e9016e300831ce6584318/debian-jessie-verbose.log).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.