Skip to content
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

stack build segfaults on Void Linux with musl 1.1.24 #6325

Open
ii8 opened this issue Oct 31, 2023 · 25 comments
Open

stack build segfaults on Void Linux with musl 1.1.24 #6325

ii8 opened this issue Oct 31, 2023 · 25 comments

Comments

@ii8
Copy link

ii8 commented Oct 31, 2023

I am running stack build on a barebones hello world project. The build fails but the output says only "While executing the build plan, Stack encountered the error:" with no error description below, and further down it says "scroll up to its section to see the error" with no error description above.

stack.yaml:

resolver: lts-21.19

packages:
- .

package.yaml:

name: myproject

executable:
  main: Main.hs

Main.hs:

main = putStrLn "hello"

stack output when you run build:

$ stack build
Building all executables for myproject once. After a successful build of all of them, only specified executables will be rebuilt.
myproject> configure (exe)

Error: [S-7282]
       Stack failed to execute the build plan.
       
       While executing the build plan, Stack encountered the error:
       
       [S-7011]
       While building package myproject-0.0.0 (scroll up to its section to see the error) using:
       /home/myuser/.stack/setup-exe-cache/x86_64-linux-tinfo6-libc6-pre232/Cabal-simple_6HauvNHV_3.8.1.0_ghc-9.4.7 --verbose=1 --builddir=.stack-work/dist/x86_64-linux-tinfo6-libc6-pre232/ghc-9.4.7 configure --with-ghc=/home/myuser/.stack/programs/x86_64-linux/ghc-tinfo6-libc6-pre232-9.4.7/bin/ghc-9.4.7 --with-ghc-pkg=/home/myuser/.stack/programs/x86_64-linux/ghc-tinfo6-libc6-pre232-9.4.7/bin/ghc-pkg-9.4.7 --user --package-db=clear --package-db=global --package-db=/home/myuser/.stack/snapshots/x86_64-linux-tinfo6-libc6-pre232/bb234be5e34390aa6066ae442c07ce42f759301c485fd18d04e6ee0055f99fee/9.4.7/pkgdb --package-db=/home/myuser/c/myproject/.stack-work/install/x86_64-linux-tinfo6-libc6-pre232/bb234be5e34390aa6066ae442c07ce42f759301c485fd18d04e6ee0055f99fee/9.4.7/pkgdb --libdir=/home/myuser/c/myproject/.stack-work/install/x86_64-linux-tinfo6-libc6-pre232/bb234be5e34390aa6066ae442c07ce42f759301c485fd18d04e6ee0055f99fee/9.4.7/lib --bindir=/home/myuser/c/myproject/.stack-work/install/x86_64-linux-tinfo6-libc6-pre232/bb234be5e34390aa6066ae442c07ce42f759301c485fd18d04e6ee0055f99fee/9.4.7/bin --datadir=/home/myuser/c/myproject/.stack-work/install/x86_64-linux-tinfo6-libc6-pre232/bb234be5e34390aa6066ae442c07ce42f759301c485fd18d04e6ee0055f99fee/9.4.7/share --libexecdir=/home/myuser/c/myproject/.stack-work/install/x86_64-linux-tinfo6-libc6-pre232/bb234be5e34390aa6066ae442c07ce42f759301c485fd18d04e6ee0055f99fee/9.4.7/libexec --sysconfdir=/home/myuser/c/myproject/.stack-work/install/x86_64-linux-tinfo6-libc6-pre232/bb234be5e34390aa6066ae442c07ce42f759301c485fd18d04e6ee0055f99fee/9.4.7/etc --docdir=/home/myuser/c/myproject/.stack-work/install/x86_64-linux-tinfo6-libc6-pre232/bb234be5e34390aa6066ae442c07ce42f759301c485fd18d04e6ee0055f99fee/9.4.7/doc/myproject-0.0.0 --htmldir=/home/myuser/c/myproject/.stack-work/install/x86_64-linux-tinfo6-libc6-pre232/bb234be5e34390aa6066ae442c07ce42f759301c485fd18d04e6ee0055f99fee/9.4.7/doc/myproject-0.0.0 --haddockdir=/home/myuser/c/myproject/.stack-work/install/x86_64-linux-tinfo6-libc6-pre232/bb234be5e34390aa6066ae442c07ce42f759301c485fd18d04e6ee0055f99fee/9.4.7/doc/myproject-0.0.0 --exact-configuration --ghc-option=-fhide-source-paths
       Process exited with code: ExitFailure (-11) 

Stack version

$ stack --version
Version 2.13.1, Git revision 8102bb8afce90fc954f48efae38b87f37cabc988 x86_64 hpack-0.36.0

Installed on x86_64 void-linux with it's package manager xbps. Upgraded with stack upgrade

@mpilgrem
Copy link
Member

@ii8, thanks for reporting. The ExitFailure (-11) flags a segmentation fault, which means that something has essentially 'crashed', and that likely explains why Stack has not handled whatever has happened 'nicely'. Your package.yaml is very sparse, even for a bare bones project. Do have any luck with a simple stack new foo type project?

@mpilgrem
Copy link
Member

OK, on Windows, that package.yaml results in the Stack-supplied Hpack generating a my-project.cabal:

cabal-version: 1.12

-- This file has been generated from package.yaml by hpack version 0.35.2.
--
-- see: https://github.com/sol/hpack

name:           my-project
version:        0.0.0
license:        BSD3
license-file:   LICENSE
build-type:     Simple

executable my-project
  main-is: Main.hs
  other-modules:
      Paths_my_project
  default-language: Haskell2010

and Stack gets further - it complains about the missing build-depends: base in the Cabal file. Not sure why it is not getting that far on a Linux system (albeit one that has libc < 2.32).

@ii8
Copy link
Author

ii8 commented Oct 31, 2023

running:

stack new foo
cd foo
stack build

causes the same problem still with exit code -11.

I have switched to just using cabal on it's own and things work fine that way.

@mpilgrem
Copy link
Member

mpilgrem commented Oct 31, 2023

Does Stack detecting libc < 2.32 seem correct to you? I don't know Void Linux, but this list makes me think that glibc should be version 2.36.

@ii8
Copy link
Author

ii8 commented Oct 31, 2023

libc is musl 1.1.24, forgot to mention my bad

@mpilgrem
Copy link
Member

Ah ha! So, for some reason, Stack is not identifying that it is a musl system.

@mpilgrem
Copy link
Member

For linux64-musl, Stack will fetch https://downloads.haskell.org/~ghc/9.4.7/ghc-9.4.7-x86_64-alpine3_12-linux.tar.xz. If that version of GHC will also work on a musl/Void Linux system, you could try stack --ghc-build musl build ...

@mpilgrem
Copy link
Member

Alternatively, if Cabal (the tool) is working for you, I assume that you have a version of GHC on the PATH that works on your system. You can instruct Stack to use that 'system' GHC, and not to download GHCs, with stack --system-ghc --no-install-ghc build. (Those options can also be configured in Stack's YAML configuration files.)

@mpilgrem
Copy link
Member

Finally, Stack's strategy for detecting musl is to look for libc.musl-x86_64.so.1 in /lib or /lib64. I do not know why that is not working on your system.

@ii8
Copy link
Author

ii8 commented Oct 31, 2023

system-ghc setting in yaml file is ignored, setting --system-ghc on commandline is also ignored, the same thing happens. running stack ghci fails to build but then ghci does start successfully.

Here is what it looks like on void linux musl:

$ ls /lib/*musl*
/lib/ld-musl-x86_64.so.1
$ ls /usr/lib/*musl*
/usr/lib/ld-musl-x86_64.so.1
$ ls /lib/libc.*
/lib/libc.a  /lib/libc.so
$ ls /usr/lib/libc.*
/usr/lib/libc.a  /usr/lib/libc.so
$ ldd
musl libc (x86_64)
Version 1.1.24
Dynamic Program Loader
Usage: ldd [options] [--] pathname

@mpilgrem
Copy link
Member

So that I can understand your 'system' GHC (if any), what does which -a ghc and ghc --version yield?

@ii8
Copy link
Author

ii8 commented Oct 31, 2023

$ which -a ghc
/usr/bin/ghc
/usr/sbin/ghc
/sbin/ghc
/bin/ghc
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 9.0.2

@mpilgrem
Copy link
Member

So, --system-ghc is being ignored by Stack because resolver: lts-21.19 is asking for GHC 9.4.7, and your system is providing GHC 9.0.2. lts-19.33 asks for GHC 9.0.2.

@ii8
Copy link
Author

ii8 commented Oct 31, 2023

Yea I figured, but I had already commented that, with lts-19.33 and system-ghc it does indeed work.

@ii8
Copy link
Author

ii8 commented Oct 31, 2023

I'm looking but it seems difficult to find a non-hacky way to determine which libc a system is using.

@mpilgrem
Copy link
Member

Stack looking for libc.musl-x86_64.so.1 to detect musl may be too Alpine Linux-centric, but that is only a problem if the 'Alpine Linux' version of GHC actually works on Void Linux too. So, I would be interested to know how stack --ghc-build musl build behaves.

@ii8
Copy link
Author

ii8 commented Oct 31, 2023

Preparing to install GHC (musl) to an isolated location. This will not interfere with any system-level installation.
Downloaded ghc-musl-9.4.7.                                      
ar: conftest.a: No such file or directory                                            
Installed GHC.     
[1 of 3] Compiling Main             ( /home/myuser/.stack/setup-exe-src/setup-6HauvNHV.hs, /home/myuser/.stack/setup-exe-src/setup-6HauvNHV.o )
[2 of 3] Compiling StackSetupShim   ( /home/myuser/.stack/setup-exe-src/setup-shim-6HauvNHV.hs, /home/myuser/.stack/setup-exe-src/setup-shim-6HauvNHV.o )
[3 of 3] Linking /home/myuser/.stack/setup-exe-cache/x86_64-linux-musl/tmp-Cabal-simple_6HauvNHV_3.8.1.0_ghc-9.4.7
Building all executables for foo once. After a successful build of all of them, only specified executables will be rebuilt.
foo> configure (lib + exe)

Error: [S-7282]
       Stack failed to execute the build plan.
       
       While executing the build plan, Stack encountered the error:
       
       [S-7011]
       While building package foo-0.1.0.0 (scroll up to its section to see the error) using:
       /home/myuser/.stack/setup-exe-cache/x86_64-linux-musl/Cabal-simple_6HauvNHV_3.8.1.0_ghc-9.4.7 --verbose=1 --builddir=.stack-work/dist/x86_64-linux-musl/ghc-9.4.7 configure --with-ghc=/home/myuser/.stack/programs/x86_64-linux/ghc-musl-9.4.7/bin/ghc-9.4.7 --with-ghc-pkg=/home/myuser/.stack/programs/x86_64-linux/ghc-musl-9.4.7/bin/ghc-pkg-9.4.7 --user --package-db=clear --package-db=global --package-db=/home/myuser/.stack/snapshots/x86_64-linux-musl/e284ba1d292408131bfbb2f58cc66af0a14ce56590e73e5be83625570d5fa33b/9.4.7/pkgdb --package-db=/home/myuser/c/foo/.stack-work/install/x86_64-linux-musl/e284ba1d292408131bfbb2f58cc66af0a14ce56590e73e5be83625570d5fa33b/9.4.7/pkgdb --libdir=/home/myuser/c/foo/.stack-work/install/x86_64-linux-musl/e284ba1d292408131bfbb2f58cc66af0a14ce56590e73e5be83625570d5fa33b/9.4.7/lib --bindir=/home/myuser/c/foo/.stack-work/install/x86_64-linux-musl/e284ba1d292408131bfbb2f58cc66af0a14ce56590e73e5be83625570d5fa33b/9.4.7/bin --datadir=/home/myuser/c/foo/.stack-work/install/x86_64-linux-musl/e284ba1d292408131bfbb2f58cc66af0a14ce56590e73e5be83625570d5fa33b/9.4.7/share --libexecdir=/home/myuser/c/foo/.stack-work/install/x86_64-linux-musl/e284ba1d292408131bfbb2f58cc66af0a14ce56590e73e5be83625570d5fa33b/9.4.7/libexec --sysconfdir=/home/myuser/c/foo/.stack-work/install/x86_64-linux-musl/e284ba1d292408131bfbb2f58cc66af0a14ce56590e73e5be83625570d5fa33b/9.4.7/etc --docdir=/home/myuser/c/foo/.stack-work/install/x86_64-linux-musl/e284ba1d292408131bfbb2f58cc66af0a14ce56590e73e5be83625570d5fa33b/9.4.7/doc/foo-0.1.0.0 --htmldir=/home/myuser/c/foo/.stack-work/install/x86_64-linux-musl/e284ba1d292408131bfbb2f58cc66af0a14ce56590e73e5be83625570d5fa33b/9.4.7/doc/foo-0.1.0.0 --haddockdir=/home/myuser/c/foo/.stack-work/install/x86_64-linux-musl/e284ba1d292408131bfbb2f58cc66af0a14ce56590e73e5be83625570d5fa33b/9.4.7/doc/foo-0.1.0.0 --dependency=base=base-4.17.2.0 --exact-configuration --ghc-option=-fhide-source-paths
       Process exited with code: ExitFailure (-11) 

@ii8
Copy link
Author

ii8 commented Oct 31, 2023

I doubt this is useful, but just in case

(gdb) r
Starting program: /home/myuser/.stack/setup-exe-cache/x86_64-linux-musl/Cabal-simple_6HauvNHV_3.8.1.0_ghc-9.4.7 

Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) bt
#0  0x0000000000000000 in ?? ()
#1  0x00007ffff7ed3775 in ?? () from /lib/libgmp.so.10
#2  0x0000000000000d9d in ?? ()
#3  0x00007ffff7fbfe18 in do_init_fini (queue=<optimized out>) at ldso/dynlink.c:1493
#4  0x00007ffff7fc1d60 in __libc_start_init () at ldso/dynlink.c:1506
#5  0x00007ffff7f69ff0 in libc_start_main_stage2 (main=0x40da17 <main>, argc=1, argv=0x7fffffffe088) at src/env/__libc_start_main.c:91
#6  0x000000000040c796 in _start ()

@mpilgrem
Copy link
Member

mpilgrem commented Oct 31, 2023

Thanks. That is disappointing. I think that may mean you are either (a) stuck with Void Linux-supplied GHC 9.0.2 or (b) need a later GHC that has been built by somebody specifically for Void Linux/musl - however, I am now at the boundary of my own knowledge.

@mpilgrem
Copy link
Member

Cross-referencing to an open issue in the GHCup (installer) project: https://gitlab.haskell.org/haskell/ghcup-hs/-/issues/368

@ii8
Copy link
Author

ii8 commented Oct 31, 2023

I'm fine with using 9.0.2, if I need a newer one I can always compile it from source.

@mpilgrem mpilgrem changed the title Stack build fails but does not say what the error was stack build segfaults on Void Linux with musl 1.1.24 Oct 31, 2023
@ii8
Copy link
Author

ii8 commented Oct 31, 2023

I think a good solution here would be for the binaries distributed from haskell.org to be statically linked, at least these alpine musl builds, so they work on any system.

@hasufell
Copy link
Contributor

There are fully static bindists, but they don't work well: https://downloads.haskell.org/~ghc/9.4.7/ghc-9.4.7-x86_64-alpine3_12-linux-static.tar.xz

@mpilgrem
Copy link
Member

mpilgrem commented Oct 31, 2023

There are 'official' x86_64/statically-linked binary distributions of GHC for Linux: eg https://www.haskell.org/ghc/download_ghc_9_4_7.html#linux_x86_64. However, I understand them to have bugs: eg https://gitlab.haskell.org/ghc/ghc/-/issues/23043. EDIT: my post crossed with @hasufell's.

@ii8
Copy link
Author

ii8 commented Oct 31, 2023

That report was made by me hah, looks like I went through this problem before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants