From 24242a540fa336b0bc69e428e97d0b897ce502b8 Mon Sep 17 00:00:00 2001 From: Nicolas Trangez Date: Mon, 1 Apr 2024 00:49:51 +0200 Subject: [PATCH] psx: work-around `hsc2hs` linking issue On some platforms, building a `hsc2hs` program requires `libgcc`, and on some platforms, `libgcc` uses `sigfillset`. For some reason (a bug, I'd say), `cabal` passes `ld-options` to the compiler when building the generated C file. In our case, this causes `sigfillset` to be wrapped (which is desired for the actual `psx` library), but since `__wrap_sigfillset` is never defined, the build fails. This work-around tells `hsc2hs` to include a small C file in its generated sources which defines `__wrap_sigfillset` as a proxy for `__real_sigfillset`. See: https://github.com/haskell/cabal/issues/8824 --- psx/CHANGELOG.md | 3 +++ psx/psx.cabal | 4 +++- psx/test/hsc2hs-stubs.c | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 psx/test/hsc2hs-stubs.c diff --git a/psx/CHANGELOG.md b/psx/CHANGELOG.md index 4e566be..c19c68e 100644 --- a/psx/CHANGELOG.md +++ b/psx/CHANGELOG.md @@ -10,6 +10,9 @@ * Update vendored sources. +* Fix build on platforms where a `hsc2hs` build links in `libgcc` which relies on + `sigfillset`. This requires the Cabal format version to be bumped to 3.6. + ## 0.1.1.1 -- 2023-02-28 * Remove `-Wl,-undefined,__wrap_sigfillset` from link options. diff --git a/psx/psx.cabal b/psx/psx.cabal index ca8e942..c6c3283 100644 --- a/psx/psx.cabal +++ b/psx/psx.cabal @@ -1,4 +1,4 @@ -cabal-version: 2.2 +cabal-version: 3.6 build-type: Simple name: psx version: 0.1.1.1 @@ -113,6 +113,7 @@ test-suite psx-test-threaded main-is: psx-test-threaded.hs other-modules: TestCases c-sources: test/detect-psx.c + hsc2hs-options: -i hsc2hs-stubs.c include-dirs: test build-depends: , async ^>=2.2.3 @@ -131,6 +132,7 @@ test-suite psx-test main-is: psx-test.hs other-modules: TestCases c-sources: test/detect-psx.c + hsc2hs-options: -i hsc2hs-stubs.c include-dirs: test build-depends: , async ^>=2.2.3 diff --git a/psx/test/hsc2hs-stubs.c b/psx/test/hsc2hs-stubs.c new file mode 100644 index 0000000..f1afa66 --- /dev/null +++ b/psx/test/hsc2hs-stubs.c @@ -0,0 +1,20 @@ +/* Stubs for linking `hsc2hs` programs to succeed. + * + * For some reason, `cabal` passes a library's `ld-options` to the C compiler + * when building `hsc2hs` C files. However, in our case, these flags request + * wrapping of (e.g.) `sigfillset`. On some platforms, `libgcc` gets linked in + * as well, and on some platforms this `libgcc` relies on `sigfillset`, hence + * linking fails unless `__wrap_sigfillset` is declared. + * + * This module relays calls to the underlying `__real_*` implementation. + * + * See https://github.com/haskell/cabal/issues/8824 + */ + +#include + +extern int __real_sigfillset(sigset_t *set); + +int __wrap_sigfillset(sigset_t *set) { + return __real_sigfillset(set); +}