
#15837: Hadrian should build dynamically linked ghc binary -------------------------------------+------------------------------------- Reporter: davide | Owner: davide Type: bug | Status: closed Priority: normal | Milestone: Component: Build System | Version: 8.6.1 (Hadrian) | Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D5385 Wiki Page: | Phab:D5327 -------------------------------------+------------------------------------- Comment (by davide): My commit (79d5427e1f9d) breaks the hadrian build in some cases. When building the default flavour, the ghc binary is linked with -lffi. When there is no system wide libffi .so installed, this will fail, even though there should be a locally built libffi. Here is an example of the command line generated by hadrian: {{{ $ _build/stage0/bin/ghc -Wall -hisuf hi -osuf o -hcsuf hc -fPIC -dynamic -hide-all-packages -no-user-package-db '-package-db _build/stage1/lib/package.conf.d' '-package-id array-0.5.2.0' '-package-id base-4.12.0.0' '-package-id bytestring-0.10.9.0' '-package-id containers-0.6.0.1' '-package-id deepseq-1.4.4.0' '-package-id directory-1.3.3.1' '-package-id filepath-1.4.2.1' '-package-id ghc-8.7' '-package-id ghc-boot-8.7' '-package-id ghc-prim-0.5.3' '-package-id ghci-8.7' '-package-id haskeline-0.7.4.3' '-package-id process-1.6.3.0' '-package-id time-1.9.2' '-package-id transformers-0.5.5.0' '-package-id unix-2.7.2.2' -i -i_build/stage1/ghc/build -i_build/stage1/ghc/build/ghc/autogen -ighc/. -Iincludes -I_build/generated -I_build/stage1/ghc/build -I/nix/store /x5ms5m9ga6v7vy3akc58yx279ggfnbnl-ghc-build-environment/include -I/home/david/MEGA/File_Dump/Well- Typed/GHC/_nosync_git/_build/T-15837_default/stage1/lib/x86_64-linux- ghc-8.7.20181205/ghc-8.7/include -I/home/david/MEGA/File_Dump/Well- Typed/GHC/_nosync_git/_build/T-15837_default/stage1/lib/x86_64-linux- ghc-8.7.20181205/process-1.6.3.0/include -I/home/david/MEGA/File_Dump /Well-Typed/GHC/_nosync_git/_build/T-15837_default/stage1/lib/x86_64 -linux-ghc-8.7.20181205/unix-2.7.2.2/include -I/home/david/MEGA/File_Dump /Well-Typed/GHC/_nosync_git/_build/T-15837_default/stage1/lib/x86_64 -linux-ghc-8.7.20181205/time-1.9.2/include -I/home/david/MEGA/File_Dump /Well-Typed/GHC/_nosync_git/_build/T-15837_default/stage1/lib/x86_64 -linux-ghc-8.7.20181205/bytestring-0.10.9.0/include -I/home/david/MEGA/File_Dump/Well- Typed/GHC/_nosync_git/_build/T-15837_default/stage1/lib/x86_64-linux- ghc-8.7.20181205/base-4.12.0.0/include -I/nix/store /x5ms5m9ga6v7vy3akc58yx279ggfnbnl-ghc-build-environment/include -I/home/david/MEGA/File_Dump/Well- Typed/GHC/_nosync_git/_build/T-15837_default/stage1/lib/x86_64-linux- ghc-8.7.20181205/integer-gmp-1.0.2.0/include -I/home/david/MEGA/File_Dump /Well-Typed/GHC/_nosync_git/_build/T-15837_default/stage1/lib/x86_64 -linux-ghc-8.7.20181205/rts-1.0/include -I_build/generated -optc- I_build/generated -optP-include -optP_build/stage1/ghc/build/ghc/autogen/cabal_macros.h -optc-fno-stack- protector -optP-DGHCI -odir _build/stage1/ghc/build -hidir _build/stage1/ghc/build -stubdir _build/stage1/ghc/build -dynamic -optl- Wl,-rpath -optl-Wl,$ORIGIN/../lib/x86_64-linux-ghc-8.7.20181205 -no-auto- link-packages -no-hs-main -optl-lgmp -Wnoncanonical-monad-instances -optc- Werror=unused-but-set-variable -optc-Wno-error=inline _build/stage1/ghc/build/c/hschooks.o _build/stage1/ghc/build/Main.o _build/stage1/ghc/build/GHCi/Leak.o _build/stage1/ghc/build/GHCi/UI.o _build/stage1/ghc/build/GHCi/UI/Info.o _build/stage1/ghc/build/GHCi/UI/Monad.o _build/stage1/ghc/build/GHCi/UI/Tags.o -o _build/stage1/bin/ghc -O2 -H32m -Wall -Wnoncanonical-monad-instances -Wnoncanonical-monadfail-instances -Wnoncanonical-monoid-instances -fno-warn-name-shadowing -threaded -XHaskell2010 -XNoImplicitPrelude -ghcversion- file=/home/david/MEGA/File_Dump/Well- Typed/GHC/_nosync_git/ghc/_build/generated/ghcversion.h -I_build/stage1/compiler/build -Wcpp-undef }}} Note that there is no mention of libffi (i.e. no use of `-lffi`). Ghc sees rts as a dependency, and sees `hs-libraries: HSrts-1.0 Cffi` in the ghc- pkg database and then adds `-lffi` to the linking command. Further more, bgamari has suggested that we may not be supposed to link with libffi. We build libffi via hadrian but don't generate a .so. Instead we copy the same .a file as as both an .a and an .so for all flavours {{{ | Copy file: _build/stage1/libffi/build/inst/include/ffi.h => _build/stage1/rts/build/ffi.h | Copy file: _build/stage1/libffi/build/inst/include/ffitarget.h => _build/stage1/rts/build/ffitarget.h | Copy file (untracked): _build/stage1/libffi/build/inst/lib/libffi.a => _build/stage1/rts/build/libCffi.a | Copy file (untracked): _build/stage1/libffi/build/inst/lib/libffi.a => _build/stage1/rts/build/libCffi_p.a | Copy file (untracked): _build/stage1/libffi/build/inst/lib/libffi.a => _build/stage1/rts/build/libCffi-ghc8.7.20181126.so | Copy file (untracked): _build/stage1/libffi/build/inst/lib/libffi.a => _build/stage1/rts/build/libCffi_thr.a | Copy file (untracked): _build/stage1/libffi/build/inst/lib/libffi.a => _build/stage1/rts/build/libCffi_thr_p.a | Copy file (untracked): _build/stage1/libffi/build/inst/lib/libffi.a => _build/stage1/rts/build/libCffi_debug_p.a | Copy file (untracked): _build/stage1/libffi/build/inst/lib/libffi.a => _build/stage1/rts/build/libCffi_thr_debug_p.a | Copy file (untracked): _build/stage1/libffi/build/inst/lib/libffi.a => _build/stage1/rts/build/libCffi_l.a | Copy file (untracked): _build/stage1/libffi/build/inst/lib/libffi.a => _build/stage1/rts/build/libCffi_thr_l.a | Copy file (untracked): _build/stage1/libffi/build/inst/lib/libffi.a => _build/stage1/rts/build/libCffi_debug.a | Copy file (untracked): _build/stage1/libffi/build/inst/lib/libffi.a => _build/stage1/rts/build/libCffi_thr_debug.a | Copy file (untracked): _build/stage1/libffi/build/inst/lib/libffi.a => _build/stage1/rts/build/libCffi-ghc8.7.20181126_thr.so | Copy file (untracked): _build/stage1/libffi/build/inst/lib/libffi.a => _build/stage1/rts/build/libCffi-ghc8.7.20181126_debug.so | Copy file (untracked): _build/stage1/libffi/build/inst/lib/libffi.a => _build/stage1/rts/build/libCffi-ghc8.7.20181126_l.so | Copy file (untracked): _build/stage1/libffi/build/inst/lib/libffi.a => _build/stage1/rts/build/libCffi-ghc8.7.20181126_thr_debug.so | Copy file (untracked): _build/stage1/libffi/build/inst/lib/libffi.a => _build/stage1/rts/build/libCffi-ghc8.7.20181126_thr_l.so }}} Though this may work for the .a files, it wont work for the .so. It's an easy fix to also build the .so and copy that instead: * modify `hadrian/src/Settings/Builders/Configure.hs` to use `--enable- shared=yes` when the way is dynamic. * modify `hadrian/src/Rules/Libffi.hs` to copy .so instead of .a when the way is dynamic. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15837#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler