xxHash duplicate symbol errors on FreeBSD
The error
https://gitlab.haskell.org/haskell/ghcup-hs/-/jobs/697465
Linking /var/tmp/gitlab_runner/builds/Jksa8Z9c/0/haskell/ghcup-hs/dist-newstyle/build/x86_64-freebsd/ghc-8.10.4/ghcup-0.1.15/x/ghcup/opt/build/ghcup/ghcup ...
ld.lld: error: duplicate symbol: XXH64
>>> defined at xxhash.c
>>> xxhash.o:(XXH64) in archive /var/tmp/gitlab_runner/builds/Jksa8Z9c/0/haskell/ghcup-hs/cabal/store/ghc-8.10.4/zstd-0.1.2.0-41edf371612e6dd17899e92e3231b7a5a77df77b5d45ac6717572bb1bbf86811/lib/libHSzstd-0.1.2.0-41edf371612e6dd17899e92e3231b7a5a77df77b5d45ac6717572bb1bbf86811.a
>>> defined at xxhash.c:693 (/home/gitlab-runner/builds/emU_Mn9f/0/ghc/ghc/rts/xxhash.c:693)
>>> RTS.thr_o:(.text.XXH64+0x0) in archive /var/tmp/gitlab_runner/builds/Jksa8Z9c/0/haskell/ghcup-hs/.ghcup/ghc/8.10.4/lib/ghc-8.10.4/rts/libHSrts_thr.a
ld.lld: error: duplicate symbol: XXH32
[...]
Error context
- ghcup-0.1.15
- FreeBSD 12.2-RELEASE-p7
- https://hackage.haskell.org/package/zstd as a dependency
- GHC-8.10.4
This results in a symbol clash:
$ nm /home/viktor/.local/ghc-8.10/lib/ghc-8.10.5/lib/x86_64-freebsd-ghc-8.10.5/rts-1.0.1/libHSrts-1.0.1.a | grep 'T XXH' | awk '{print $NF}' | head -n4
XXH32
XXH32_canonicalFromHash
XXH32_copyState
XXH32_createState
$ nm /home/viktor/.cabal/store/ghc-8.10.5/zstd-0.1.2.0-478106f0a6264ffbc385f3b396440e7b48b3cb4925a1f186
0dc611ebd2bc441c/lib/libHSzstd-0.1.2.0-478106f0a6264ffbc385f3b396440e7b48b3cb4925a1f1860dc611ebd2bc441c.a | grep 'T XXH' | awk '{print $NF}' | head -n4
XXH32
XXH32_canonicalFromHash
XXH32_copyState
XXH32_createState
We couldn't reproduce the linking error with 8.10.5 however.
Discussion on IRC
@vdukhovni1 pointed out that the RTS shouldn't expose those symbols:
10:12 <vdukhovni> These functions SHOULD NOT have been exposed from the RTS as-is. Ideally, they'd be static in just the one file (rts/Hash.c) that uses them.
10:13 <maerwald> Ok, are you planning to create a ticket?
10:14 <vdukhovni> This is supported by defining "XXH_PRIVATE_API", and not compiling "xxhash.c" directly.
10:14 <vdukhovni> But not actually done in the RTS.
10:14 <vdukhovni> Can you take care of this, at least open an issue? I'm way over time budget on this...
10:15 <maerwald> sure, thanks for the pointers
10:17 <vdukhovni> See xxhash.h:
10:17 <vdukhovni> /* ****************************
10:17 <vdukhovni> * API modifier
10:17 <vdukhovni> ******************************/
10:17 <vdukhovni> /** XXH_PRIVATE_API
10:17 <vdukhovni> * This is useful to include xxhash functions in `static` mode
10:17 <vdukhovni> * in order to inline them, and remove their symbol from the public list.
10:17 <vdukhovni> * Methodology :
10:17 <vdukhovni> * #define XXH_PRIVATE_API
10:17 <vdukhovni> * #include "xxhash.h"
10:17 <vdukhovni> * `xxhash.c` is automatically included.
10:18 <vdukhovni> * It's not useful to compile and link it as a separate module.
The originating commit seems to be 542f89ff
Edited by Julian Ospald