Skip to content

-fPIC errors with --profile on Arch Linux #3877

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

Open
RichardWarfield opened this issue Feb 19, 2018 · 5 comments
Open

-fPIC errors with --profile on Arch Linux #3877

RichardWarfield opened this issue Feb 19, 2018 · 5 comments

Comments

@RichardWarfield
Copy link

RichardWarfield commented Feb 19, 2018

General summary/comments (optional)

This is likely related to #3518 and #3409 etc. But while users seem to have resolved those issues for GHC 8.2.2 and up, I see the same (or a similar) issue when using the --profile flag. Building without --profile works fine.

Steps to reproduce

stack build --profile --system-ghc (with Arch ghc-static package)
or
stack build --profile

Expected

The project should build without errors and with profiling data.

Actual

Linking fails with thousands of errors like these:

$ stack build --profile --system-ghc 

> Linking .stack-work/dist/x86_64-linux/Cabal-2.0.1.0/build/voyhask-ffi/libvoyhask-ffi.so.4 ...
> /usr/bin/ld.gold: error: .stack-work/dist/x86_64-linux/Cabal-2.0.1.0/build/voyhask-ffi/voyhask-ffi-tmp/DateUtil.p_o: requires dynamic R_X86_64_PC32 reloc against 'stg_ap_p_fast' which may overflow at runtime; recompile with -fPIC
> /usr/bin/ld.gold: error: .stack-work/dist/x86_64-linux/Cabal-2.0.1.0/build/voyhask-ffi/voyhask-ffi-tmp/LazyBear/Class.p_o: requires dynamic R_X86_64_PC32 reloc against 'stg_ap_0_fast' which may overflow at runtime; recompile with -fPIC
> /usr/bin/ld.gold: error: .stack-work/dist/x86_64-linux/Cabal-2.0.1.0/build/voyhask-ffi/voyhask-ffi-tmp/LazyBear/Series.p_o: requires dynamic R_X86_64_PC32 reloc against 'stg_sel_1_upd_info' which may overflow at runtime; recompile with -fPIC
> /usr/bin/ld.gold: error: .stack-work/dist/x86_64-linux/Cabal-2.0.1.0/build/voyhask-ffi/voyhask-ffi-tmp/LazyBear/DynamicFrame.p_o: requires dynamic R_X86_64_PC32 reloc against 'stg_sel_1_upd_info' which may overflow at runtime; recompile with -fPIC
> /usr/bin/ld.gold: error: .stack-work/dist/x86_64-linux/Cabal-2.0.1.0/build/voyhask-ffi/voyhask-ffi-tmp/Voyager/Common.p_o: requires dynamic R_X86_64_PC32 reloc against 'stg_ap_p_fast' which may overflow at runtime; recompile with -fPIC
> ...
> /usr/bin/ld.gold: error: /usr/lib/ghc-8.2.2/base-4.10.1.0/libHSbase-4.10.1.0_p.a(Semigroup.p_o): requires unsupported dynamic reloc 11; recompile with -fPIC
> /usr/bin/ld.gold: error: /usr/lib/ghc-8.2.2/base-4.10.1.0/libHSbase-4.10.1.0_p.a(Semigroup.p_o): requires unsupported dynamic reloc 11; recompile with -fPIC
> /usr/bin/ld.gold: error: /usr/lib/ghc-8.2.2/base-4.10.1.0/libHSbase-4.10.1.0_p.a(Semigroup.p_o): requires unsupported dynamic reloc 11; recompile with -fPIC
> /usr/bin/ld.gold: error: /usr/lib/ghc-8.2.2/base-4.10.1.0/libHSbase-4.10.1.0_p.a(Semigroup.p_o): requires unsupported dynamic reloc 11; recompile with -fPIC
> 

Stack version

I have tried both 1.6.3 and the latest git master.

$ stack --version
Version 1.7.0, Git revision cd7ed8f44ea0ac0809ebc9125a05b0b7273765e9 (5683 commits) x86_64 hpack-0.21.2

Method of installation

I have tried:

  • The official binaries
  • The main Arch repository -- the stack and stack-bin packages

I have also tried various builds of GHC 8.2.2 (stack installed builds with ghc-build and tinfo6; as well as the ghc and ghc-static builds from the Arch packages). All exhibit this problem.

@borsboom
Copy link
Contributor

Interesting that system GHC exhibits the same problem. Have you tried adjusting the GHC settings file (in <GHC-ROOT>/lib/ghc-<GHC-VERSION>/settings)?

@RichardWarfield
Copy link
Author

I tried adding -fPIC to the system GHC settings (which I found in /usr/lib/ghc-8.2.2/settings).

 ("C compiler flags", " -fPIC -fno-stack-protector"),
 ("C compiler link flags", " -fPIC -fuse-ld=gold"),

Same result.

However -- I tried building a simple application (stack new teststack simple --system-ghc; stack build --system-ghc --profile) and this did work. So, the issue seems to relate to how my project is set up. Which is strange because I don't think there is anything at all funky about my .cabal or stack.yaml configuration. I'll try to isolate the issue now.

@RichardWarfield
Copy link
Author

OK, this seems to have something to do with building a shared foreign library. By removing the below foreign-library stanza from my .cabal file, I can make the problem go away.

foreign-library teststack-ffi
  type:                native-shared
  lib-version-info:    6:3:2

--  if os(Windows)
--    options: standalone
--    mod-def-file: MyForeignLib.def

  other-modules:       FFI
  hs-source-dirs:      src
  c-sources:           ffi_init.c
  default-language:    Haskell2010
  build-depends:       base >= 4.7 && < 5
                     , teststack
                     , containers
                     , text
                     , data-msgpack
                     , bytestring
                     , time
                     , Decimal
                     , vector
                     , parallel
                     , hashable
                     , data-msgpack
                     , string-conversions
                     , binary
                     , bytestring
                     , haxl
                     , aeson
                     , scientific
                     , network-msgpack-rpc
                     , boxes
                     , mtl
                     , resource-pool
                     , monad-logger
                     , resourcet
                     , singletons
                     , ghc-prim
                     , exceptions
                     , unordered-containers
                     , fgl
                     , regex-pcre
                     , postgresql-simple
                     , postgresql-libpq
                     , async
                     , formatting
                     , QuickCheck
                     , quickcheck-instances
                     , vector-algorithms
                     , mmorph
                     , fast-logger
  default-extensions:  OverloadedStrings, PackageImports, StandaloneDeriving, GADTs,
                       TypeFamilies, FlexibleInstances, MultiParamTypeClasses, DeriveGeneric,
                       DataKinds, TypeOperators, FlexibleContexts, RankNTypes, PolyKinds,
                       ScopedTypeVariables, DeriveGeneric, GeneralizedNewtypeDeriving

@pmalhaire
Copy link

pmalhaire commented Mar 12, 2018

I have the same issue with a simple ghc build using arch :

echo 'main = putStrLn "toto"' > test.hs && ghc test.hs

result

[1 of 1] Compiling Main             ( test.hs, test.o )
Linking test ...
/usr/bin/ld.gold: error: test.o: requires unsupported dynamic reloc 11; recompile with -fPIC
/usr/bin/ld.gold: error: /usr/local/haskell/ghc-8.2.2-x86_64/lib/ghc-8.2.2/base-4.10.1.0/libHSbase-4.10.1.0.a(Base.o): requires unsupported dynamic reloc 11; recompile with -fPIC
/usr/bin/ld.gold: error: /usr/local/haskell/ghc-8.2.2-x86_64/lib/ghc-8.2.2/base-4.10.1.0/libHSbase-4.10.1.0.a(Base.o): requires unsupported dynamic reloc 11; recompile with -fPIC
...

@aviaviavi
Copy link

I'm seeing the same sort of requires unsupported dynamic reloc 11; recompile with -fPIC errors on Alpine Linux (the alpine:latest docker image to be more precise)

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

No branches or pull requests

5 participants