GHC uses otool and install_name_tool at TH time differently from how it was configured
Summary
When GHC needs to use dynamic library tooling otool
and install_name_tool
on macOS for linking a temporary dynamic library generated in TH, it uses system-default paths for those tools, which can be different from how GHC was configured (which can be checked by ghc --info)
This is a part of verbose logs from GHC session compiling a module which uses template haskell in a private project:
[21 of 22] Compiling PersistentModels.Core ... )
*** Parser [PersistentModels.Core]:
!!! Parser [PersistentModels.Core]: finished in 0.26 milliseconds, allocated 0.586 megabytes
*** Renamer/typechecker [PersistentModels.Core]:
*** Simplify [expr]:
!!! Simplify [expr]: finished in 0.03 milliseconds, allocated 0.024 megabytes
*** CorePrep [expr]:
!!! CorePrep [expr]: finished in 0.02 milliseconds, allocated 0.016 megabytes
...
*** systool:linker:
*** Linker:
...
*** otool:
/usr/bin/otool -L /tmp/nix-shell.FFEEu7/ghc18567_0/libghc_85.dylib
*** otool:
/usr/bin/otool -l /tmp/nix-shell.FFEEu7/ghc18567_0/libghc_85.dylib
*** Install Name Tool:
/usr/bin/install_name_tool -add_rpath /nix/store/0jjr9hc0b1z9m64dpd1hfr29z4cpfh3b-vector-0.13.0.0/lib/ghc-9.6.3/lib/aarch64-osx-ghc-9.6.3 -add_rpath /nix/store/3i2ba6lamqczg07wvpx8i9jwdq7c8ydw-ghc-9.6.3-with-packages/lib/ghc-9.6.3/lib/../lib/aarch64-osx-ghc-9.6.3 -add_rpath /nix/store/43bssi7nbpgmh9l0xvmbqb3dnsg0ap3i-aeson-pretty-0.8.9/lib/ghc-9.6.3/lib/aarch64-osx-ghc-9.6.3 -add_rpath /nix/store/4lpxh6xy46yaccqf7ra540wnfsf6d3zp-split-0.2.3.5/lib/ghc-9.6.3/lib/aarch64-osx-ghc-9.6.3 -add_rpath /nix/store/5ddiicmzrnid072niv22ch4lax3cs1wq-persistent-2.14.5.2/lib/ghc-9.6.3/lib/aarch64-osx-ghc-9.6.3 -add_rpath /nix/store/bjs9imsx36nk163rb8riaa9wfi4mx852-aeson-typescript-0.6.0.0/lib/ghc-9.6.3/lib/aarch64-osx-ghc-9.6.3 -add_rpath /nix/store/f27s9gl55g79lg6ax44nng85mgdsdnsg-classy-prelude-1.5.0.3/lib/ghc-9.6.3/lib/aarch64-osx-ghc-9.6.3 -add_rpath /nix/store/fji23aalpir3akxh3ssqadbxsdz4s65a-aeson-2.1.2.1/lib/ghc-9.6.3/lib/aarch64-osx-ghc-9.6.3 -add_rpath /nix/store/lshg3gsd3wflahjbsshpnris61m6ds99-mono-traversable-1.0.15.3/lib/ghc-9.6.3/lib/aarch64-osx-ghc-9.6.3 /tmp/nix-shell.FFEEu7/ghc18567_0/libghc_85.dylib
/Library/Developer/CommandLineTools/usr/bin/install_name_tool: warning: changes being made to the file will invalidate the code signature in: /tmp/nix-shell.FFEEu7/ghc18567_0/libghc_85.dylib
where ghc used here was configured like the following:
$ bazel run @rules_haskell_ghc_nixpkgs//:bin/ghc -- --info
INFO: Analyzed target @rules_haskell_ghc_nixpkgs//:bin/ghc (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
WARNING: /private/var/tmp/_bazel_ianwookim/5a88137bd20b51653b195b87767c18f9/external/rules_haskell_ghc_nixpkgs/BUILD:3:10: @rules_haskell_ghc_nixpkgs//:bin/ghc is a source file, nothing will be built for it. If you want to build a target that consumes this file, try --compile_one_dependency
INFO: Elapsed time: 0.162s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: /private/var/tmp/_bazel_ianwookim/5a88137bd20b51653b195b87767c18f9/external/rules_haskell_ghc_nixpkgs/bin/ghc --info
[("Project name","The Glorious Glasgow Haskell Compilation System")
,("GCC extra via C opts","")
,("C compiler command","/nix/store/sa6hywsm1mqfyd1xakyzv4ljjsb3hawh-clang-wrapper-11.1.0/bin/cc")
,("C compiler flags","--target=arm64-apple-darwin ")
,("C++ compiler command","/nix/store/sa6hywsm1mqfyd1xakyzv4ljjsb3hawh-clang-wrapper-11.1.0/bin/c++")
,("C++ compiler flags","--target=arm64-apple-darwin ")
,("C compiler link flags","")
,("C compiler supports -no-pie","NO")
,("Haskell CPP command","/nix/store/sa6hywsm1mqfyd1xakyzv4ljjsb3hawh-clang-wrapper-11.1.0/bin/cc")
,("Haskell CPP flags","-E -undef -traditional -Wno-invalid-pp-token -Wno-unicode -Wno-trigraphs")
,("ld command","/nix/store/m488d5iwzn93bdk1j5gxl77k3zb8y285-cctools-binutils-darwin-wrapper-11.1.0-973.0.1/bin/ld")
,("ld flags","")
,("ld supports compact unwind","YES")
,("ld supports filelist","YES")
,("ld supports response files","YES")
,("ld is GNU ld","NO")
,("Merge objects command","/nix/store/m488d5iwzn93bdk1j5gxl77k3zb8y285-cctools-binutils-darwin-wrapper-11.1.0-973.0.1/bin/ld")
,("Merge objects flags","-r")
,("ar command","/nix/store/x5bm27csww06snmzrsqhxfzl0i8mad5c-cctools-binutils-darwin-11.1.0-973.0.1/bin/ar")
,("ar flags","qcls")
,("ar supports at file","YES")
,("ar supports -L","NO")
,("ranlib command","/nix/store/x5bm27csww06snmzrsqhxfzl0i8mad5c-cctools-binutils-darwin-11.1.0-973.0.1/bin/ranlib")
,("otool command","/nix/store/x5bm27csww06snmzrsqhxfzl0i8mad5c-cctools-binutils-darwin-11.1.0-973.0.1/bin/otool")
,("install_name_tool command","/nix/store/m488d5iwzn93bdk1j5gxl77k3zb8y285-cctools-binutils-darwin-wrapper-11.1.0-973.0.1/bin/install_name_tool")
,("touch command","touch")
,("dllwrap command","/bin/false")
,("windres command","/bin/false")
,("unlit command","/nix/store/3i2ba6lamqczg07wvpx8i9jwdq7c8ydw-ghc-9.6.3-with-packages/lib/ghc-9.6.3/lib/bin/unlit")
,("cross compiling","NO")
,("target platform string","aarch64-apple-darwin")
,("target os","OSDarwin")
,("target arch","ArchAArch64")
,("target word size","8")
,("target word big endian","NO")
,("target has GNU nonexec stack","NO")
,("target has .ident directive","YES")
,("target has subsections via symbols","NO")
,("target has RTS linker","YES")
,("target has libm","YES")
,("Unregisterised","NO")
,("LLVM target","arm64-apple-darwin")
,("LLVM llc command","llc")
,("LLVM opt command","opt")
,("LLVM clang command","clang")
,("Use inplace MinGW toolchain","NO")
,("Use interpreter","YES")
,("Support SMP","YES")
,("RTS ways","debug thr thr_debug thr_p dyn debug_dyn thr_dyn thr_debug_dyn thr_debug_p debug_p")
,("Tables next to code","YES")
,("Leading underscore","YES")
,("Use LibFFI","YES")
,("RTS expects libdw","NO")
,("Project version","9.6.3")
,("Project Git commit id","6819b70a7739205a75f0b4fefcfcc9fdab39cab9")
,("Project Version Int","906")
,("Project Patch Level","3")
,("Project Patch Level1","3")
,("Project Patch Level2","0")
,("Booter version","9.2.4")
,("Stage","2")
,("Build platform","aarch64-apple-darwin")
,("Host platform","aarch64-apple-darwin")
,("Target platform","aarch64-apple-darwin")
,("Have interpreter","YES")
,("Object splitting supported","NO")
,("Have native code generator","YES")
,("Target default backend","native code generator")
,("Support dynamic-too","YES")
,("Support parallel --make","YES")
,("Support reexported-modules","YES")
,("Support thinning and renaming package flags","YES")
,("Support Backpack","YES")
,("Requires unified installed package IDs","YES")
,("Uses package keys","YES")
,("Uses unit IDs","YES")
,("GHC Dynamic","YES")
,("GHC Profiled","NO")
,("Debug on","NO")
,("LibDir","/nix/store/3i2ba6lamqczg07wvpx8i9jwdq7c8ydw-ghc-9.6.3-with-packages/lib/ghc-9.6.3/lib")
,("Global Package DB","/nix/store/3i2ba6lamqczg07wvpx8i9jwdq7c8ydw-ghc-9.6.3-with-packages/lib/ghc-9.6.3/lib/package.conf.d")
]
Note that this is closely related to the solved issue: #24211 (closed)
So with the fixed configuration (with the correct path information of otool
and install_name_tool
), the GHC should use the same full info when linking dynamic objects at run time unless the user specify other location using the -pgm..
arguments.
Environment
- GHC version used: GHC 9.6.3 with a backported patch from !11649 (closed)
Optional:
- Operating System: macOS Sonoma 14.2
- System Architecture: Apple M1 Max