Skip to content

Commit

Permalink
psx: work-around hsc2hs linking issue
Browse files Browse the repository at this point in the history
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: haskell/cabal#8824
  • Loading branch information
NicolasT committed Mar 31, 2024
1 parent 529002e commit 24242a5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions psx/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion psx/psx.cabal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cabal-version: 2.2
cabal-version: 3.6
build-type: Simple
name: psx
version: 0.1.1.1
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
20 changes: 20 additions & 0 deletions psx/test/hsc2hs-stubs.c
Original file line number Diff line number Diff line change
@@ -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 <signal.h>

extern int __real_sigfillset(sigset_t *set);

int __wrap_sigfillset(sigset_t *set) {
return __real_sigfillset(set);
}

0 comments on commit 24242a5

Please sign in to comment.