-
-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Changing pkgsMusl.haskell.compiler.ghc927 to .ghc945: segmentation fault with hsc2hs-created executable #239357
Comments
@mpilgrem Thanks a lot for reporting this. I haven't yet had time to look into this in depth, but let me ping the rest of the Haskell team in case someone else has a good idea @NixOS/haskell. Also ping @nh2 since he's done some work recently in https://github.com/nh2/static-haskell-nix and may have an idea of what could be going on here. |
Can you try narrowing this down? Currently we have a lot of moving parts and so we'll have to narrow down the interaction of what parts causes this:
What's more it seems to me you have changed two components at the same time in your comparison (Alpine 3.17.2 and GHC 9.2.7 to Alpine 3.18.2 and GHC 9.4.5). Can you try doing a comparison between the GHC versions in the same Alpine version and between Alpine versions with the same version of GHC? Additionally it'd be great if you could instead of reproducing this via stack in the dependencies (i.e. Neither the musl GHC 9.4.5 from nixpkgs nor the one from Alpine's repos on their own can trigger the issue according to my testing. |
@sternenseemann, will do. That may take me a little while, in part because I depend on others for the Docker images, so please bear with me. |
As a first step, to my 'test' respository, I added package
EDIT: With Cabal verbosity at deafening, the contents of the response file are reported as:
|
As a second step, I have added The former (GHC 9.2.7) calls GHC 9.2.7/Alpine 13.7.2 (passes)
GHC 9.4.5/Alpine 3.18.2 (executable segfaults when run)
I understand (if ChatGPT is reliable) that the |
As a third step, I tried applying
In all cases, there was no problem. |
As a fourth step, I examined the C code produced by
#include "/nix/store/z7z6kw76wnp86r7k9srxzkl3aaa7nn6r-ghc-musl-9.2.7/lib/ghc-9.2.7/template-hsc.h"
int main (void)
{
hsc_line (1, "app/Lib.hsc");
hsc_fputs ("", hsc_stdout());
hsc_fputs ("-- This *.hsc files does not use any of the features of hsc2hs.\n"
"", hsc_stdout());
hsc_fputs ("\n"
"module Lib\n"
" ( magicInteger\n"
" ) where\n"
"\n"
"magicInteger :: Int\n"
"magicInteger = 13\n"
"", hsc_stdout());
return 0;
}
#include "/nix/store/z7z6kw76wnp86r7k9srxzkl3aaa7nn6r-ghc-musl-9.2.7/lib/ghc-9.2.7/template-hsc.h"
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <ctype.h>
int hsc_printf(const char *format, ...) {
int r;
va_list argp;
va_start(argp, format);
r = vprintf(format, argp);
va_end(argp);
return r;
}
int hsc_toupper(int c) {
return toupper(c);
}
int hsc_tolower(int c) {
return tolower(c);
}
int hsc_putchar(int c) {
return putchar(c);
}
int hsc_fputs(const char *s, void *stream) {
return fputs(s, (FILE *)stream);
}
void *hsc_stdout(void) {
return (void *)stdout;
} |
As a fifth step, I tried applying
EDIT: I also tried with just |
@sternenseemann, I think I can be more specific, as follows:
The creation of the Docker image involves: apk add --no-cache gmp-dev |
I tried to move from GHC 9.2.7 to GHC 9.2.8 and experienced the same problem: packages that use |
I was a little surprised that this was a GHC 9.2.7 to 9.2.8 problem, as well as a GHC 9.2.7 to GHC 9.4.5 problem, so I examined the difference between the diff --git a/Dockerfile b/Dockerfile
index 3861c95..59d4a8f 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -26,7 +26,7 @@ RUN apk upgrade --no-cache &&\
lld \
shadow # for stack --docker, provides groupadd
-RUN curl -sSLo /usr/local/bin/stack https://github.com/commercialhaskell/stack/releases/download/v2.9.3/stack-2.9.3-linux-x86_64-bin && \
+RUN curl -sSLo /usr/local/bin/stack https://github.com/commercialhaskell/stack/releases/download/v2.11.1/stack-2.11.1-linux-x86_64-bin && \
chmod +x /usr/local/bin/stack
# https://stackoverflow.com/a/41517423
diff --git a/ghc-musl.nix b/ghc-musl.nix
index 33055e3..543edb7 100644
--- a/ghc-musl.nix
+++ b/ghc-musl.nix
@@ -1,7 +1,7 @@
{ pkgs ? import
(builtins.fetchTarball {
url =
- "https://github.com/NixOS/nixpkgs/archive/81d5cb1550ef0a58c5ee529c743065cc93a7fb64.tar.gz";
+ "https://github.com/NixOS/nixpkgs/archive/17662bfb35c25ba1788a6fedcb00dde6379da7ec.tar.gz";
})
{ }
}:
@@ -9,8 +9,8 @@ let
alpineImage = pkgs.dockerTools.pullImage {
imageName = "alpine";
imageDigest =
- "sha256:e2e16842c9b54d985bf1ef9242a313f36b856181f188de21313820e177002501";
- sha256 = "sha256-YCYpUByIOig4zt/WIvDas3AwHjDYkIQJ6IEKuADJmgg=";
+ "sha256:25fad2a32ad1f6f510e528448ae1ec69a28ef81916a004d3629874104f8a7f70";
+ sha256 = "sha256-ymburWdn08/l5jqTAmdeXbBys0q01OmNuOVG4mnMzqk=";
};
in
pkgs.dockerTools.buildImage {
@@ -20,7 +20,7 @@ pkgs.dockerTools.buildImage {
fromImage = alpineImage;
contents = [
- pkgs.pkgsMusl.haskell.compiler.ghc927
+ pkgs.pkgsMusl.haskell.compiler.ghc928
pkgs.pkgsMusl.zlib
pkgs.pkgsMusl.zlib.dev
pkgs.pkgsMusl.ncurses
diff --git a/justfile b/justfile
index ef424f0..48acd77 100644
--- a/justfile
+++ b/justfile
@@ -1,4 +1,4 @@
-GHC_VERSION := "9.2.7"
+GHC_VERSION := "9.2.8"
# List all recipies
default:
@@ -6,11 +6,11 @@ default:
# Build docker image
build-image:
- docker image build . -f Dockerfile -t fpco/alpine-haskell-stack:{{GHC_VERSION}}
+ docker image build . -f Dockerfile -t ghcr.io/fpco/alpine-haskell-stack:{{GHC_VERSION}}
# Push image
push-image:
- docker push fpco/alpine-haskell-stack:{{GHC_VERSION}}
+ docker push ghcr.io/fpco/alpine-haskell-stack:{{GHC_VERSION}}
# Build nix image
build-nix-image:
@@ -22,4 +22,5 @@ load-nix-image:
# Test image
test-image:
- docker run --tty --interactive fpco/alpine-haskell-stack:{{GHC_VERSION}} sh
+ docker run --rm --tty ghcr.io/fpco/alpine-haskell-stack:{{GHC_VERSION}} ghc --version
+ docker run --rm --tty ghcr.io/fpco/alpine-haskell-stack:{{GHC_VERSION}} stack --version |
Describe the bug
Apologies if I am posting this in the wrong place - outside of maintaining the Haskell Tool Stack (Stack) project I am not a Nix user or a Docker user.
hsc2hs
is a preprocessor executable that comes with GHC. It produces a C program from an*.hsc
file that GHC compiles to an executable named*_hsc_make
, that produces Haskell code when it is run.In a Docker container, with Alpine Linux 3.17.2,
pkgsMusl.haskell.compiler.ghc927
works fine. However, a change topkgsMusl.haskell.compiler.ghc945
(with Alpine Linus 3.18.2) seems to result in the executable produced byhsc2hs
generating a segmentation fault when it is run.The 'official' build of GHC 9.4.5 - https://downloads.haskell.org/~ghc/9.4.5/ghc-9.4.5-x86_64-alpine3_12-linux-static-int_native.tar.xz - outside of a Docker container, does not exhibit the same
hsc2hs
problem (but it has different problems - with Template Haskell - https://gitlab.haskell.org/ghc/ghc/-/issues/23043#note_506034).Steps To Reproduce
I've created a respository with a small Haskell package
hsc2hs-test
that illustrates the problem in its CI: https://github.com/mpilgrem/alpine-haskell-stack-test. Its dependencyclock
is a small package that makes use ofhsc2hs
. The log in the failed CI jobTest CI (9.4.5)
shows the problem. (Clock_hsc_make
is the name of executable created byhsc2hs
.)Expected behavior
hsc2hs
withpkgsMusl.haskell.compiler.ghc945
works, as it did withpkgsMusl.haskell.compiler.ghc945
.Additional context
The Docker image used is created here: https://github.com/fpco/alpine-haskell-stack. The
ghc-musl.nix
creates imagepsibi/alpine-haskell-stack:v3
. TheDockerfile
adds things to it. Thejustfile
builds what is now imageghcr.io/fpco/alpine-haskell-stack:9.4.5
.This first came to light here: commercialhaskell/stack#6161. The (unrelated) Template Haskell problem with the 'official' GHC 9.4.5 build is discussed here: https://gitlab.haskell.org/ghc/ghc/-/issues/23043#note_506034.
Notify maintainers
I am in doubt, but I see
jobs.pkgsMusl.haskell.compiler.ghc
appears innixpkgs/pkgs/top-level /release-haskell.nix
and @sternenseemann and @cdepillabout have committed to that file recently.Metadata
Please run
nix-shell -p nix-info --run "nix-info -m"
and paste the result.I am not a Nix user.
The text was updated successfully, but these errors were encountered: