Link rts symbols weakly
Motivation
Currently rts symbols are undefined in ghc shared libraries (on Linux).
This causes:
$ ldd -r libHSzlib-0.6.2-BdOecmQ0rL1HOiGypdSgxY-ghc8.6.5.so | grep "undefined symbol" | wc -l
459
$ ldd -r libHSzlib-0.6.2-BdOecmQ0rL1HOiGypdSgxY-ghc8.6.5.so | grep "undefined symbol"
undefined symbol: stg_gc_unpt_r1 (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
undefined symbol: stg_setThreadAllocationCounterzh (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
undefined symbol: stg_getThreadAllocationCounterzh (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
undefined symbol: stg_traceMarkerzh (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
undefined symbol: stg_traceEventzh (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
undefined symbol: stg_clearCCSzh (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
undefined symbol: stg_getApStackValzh (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
undefined symbol: stg_unpackClosurezh (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
undefined symbol: stg_newBCOzh (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
undefined symbol: stg_mkApUpd0zh (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
undefined symbol: stg_numSparkszh (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
undefined symbol: stg_getSparkzh (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
undefined symbol: stg_compactSizzezh (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
undefined symbol: stg_compactAddWithSharingzh (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
undefined symbol: stg_compactAddzh (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
undefined symbol: stg_compactFixupPointerszh (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
undefined symbol: stg_compactAllocateBlockzh (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
undefined symbol: stg_compactGetNextBlockzh (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
undefined symbol: stg_compactGetFirstBlockzh (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
undefined symbol: stg_compactContainsAnyzh (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
undefined symbol: stg_compactContainszh (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
undefined symbol: stg_compactResizzezh (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
undefined symbol: stg_compactNewzh (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
undefined symbol: stg_makeStableNamezh (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
undefined symbol: stg_deRefStablePtrzh (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
undefined symbol: stg_makeStablePtrzh (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
undefined symbol: stg_finalizzeWeakzh (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
undefined symbol: stg_deRefWeakzh (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
undefined symbol: stg_addCFinalizzerToWeakzh (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
undefined symbol: stg_mkWeakNoFinalizzerzh (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
undefined symbol: stg_mkWeakzh (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
undefined symbol: stg_threadStatuszh (/usr/lib64/libHSghc-prim-0.5.3-ghc8.6.5.so)
:
:
Apparently this is due to the RTS being chosen at runtime.
$ objdump -x libHSzlib-0.6.2-BdOecmQ0rL1HOiGypdSgxY-ghc8.6.5.so | grep NEEDED | grep libHSrts
$
This probably affects all versions of ghc with shared libraries.
Proposal
Linking libHSrts symbols as weak symbols should prevent these undefined symbol warnings.
Edited by Jens Petersen