-
Notifications
You must be signed in to change notification settings - Fork 701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ld-options
are passed to GCC when linking hsc2hs object files
#8824
Comments
Need some people who understand linker and ffi issues well to comment here. @bgamari @mpickering |
Friendly bump |
Running into this again 😞 So another bump? |
NicolasT
added a commit
to NicolasT/landlock-hs
that referenced
this issue
Mar 31, 2024
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
NicolasT
added a commit
to NicolasT/landlock-hs
that referenced
this issue
Mar 31, 2024
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`. This requires the Cabal format to be bumped to 3.6. See: haskell/cabal#8824
NicolasT
added a commit
to NicolasT/landlock-hs
that referenced
this issue
Mar 31, 2024
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`. This requires the Cabal format to be bumped to 3.6. See: haskell/cabal#8824
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It appears that, when a
library
specifies someld-options
, theseld-options
are passed togcc
when it's invoked to link some object files generated as part of some the pipeline to turn ahsc
file into ahs
file, i.e., when the C code generated byhsc2hs
(which should output the finalhs
file) gets linked.This is counter-intuitive, and (IMHO) incorrect: any
ld-options
set by somelibrary
should be used to link said library into some Haskell executable, not whenhsc2hs
is used by some project to link thehsc2hs
-generated program.In my case, my library specifies
-Wl,-wrap,sigfillset
asld-options
, and the library itself does provide the (then required)__wrap_sigfillset
symbol. However, when-Wl,-wrap,sigfillset
is passed to thegcc
invocation of thehsc2hs
pipeline, on some platforms, build fails since my library is not linked into the generator executable (and indeed, it should not be). This leaves__wrap_sigfillset
undefined, which on some platforms is OK (if there's no reference), but on some platforms it's not (there,libgcc
seems to usesigfillset
internally).Looking at the failing command (see below), I wonder whether most of these options should be used when linking the
hsc2hs
generator program at all: this program should not use any Haskell libraries at all, so why should all paths to Haskell libraries be passed in (-L...
), andrpath
s set (-Wl,-R,...
), or link againstlibdl
orlibgmp
simply because the RTS or, e.g.,ghc-bignum
would rely on this if they were linked in?To reproduce, clone https://github.com/NicolasT/landlock-hs.git, checkout tag
psx-0.1.1.1
and runcabal test psx-test
on some system exposing the issue, e.g., in thedocker.io/haskell:9.2-slim
container image.The issue can not be reproduced on Fedora 36, or in the
buildpack-deps:jammy
container image (which is used in the package CI).Cabal version: 3.8.1.0 (in the
docker.io/haskell:9.2-slim
container image)GHC version: 9.2.6 (in the
docker.io/haskell:9.2-slim
container image)GCC version: 8.3.0 (in the
docker.io/haskell:9.2-slim
container image)Error output when running in `docker.io/haskell:9.2-slim`, formatted for readability
Note how
which are the
ld-options
set by thepsx
library are passed through, which should not be the case.The text was updated successfully, but these errors were encountered: