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

Segfault when running a static binary built on Alpine musl #6934

Closed
j8r opened this issue Oct 12, 2018 · 10 comments
Closed

Segfault when running a static binary built on Alpine musl #6934

j8r opened this issue Oct 12, 2018 · 10 comments

Comments

@j8r
Copy link
Contributor

j8r commented Oct 12, 2018

I use a library I made, clicr library, which consists of recursive macros.
When compiling this program statically with crystal build --static cli.cr in an alpine:latest, running ./cli ver give this result:

Invalid memory access (signal 11) at address 0x0
[1]    21902 segmentation fault (core dumped)  ./cli

Code:

require "clicr"
def run
  Clicr.create(
    commands: {
      ver: {
        info:   "Version with general system information",
        action: "version",
      },
    }
  )
end

def version
  puts 0.1
end

run

In gdb, when run and then backtrace, I got:

Program received signal SIGBUS, Bus error.
0x00007ffff7f4d428 in GC_find_limit_with_bound ()
(gdb) backtrace
#0  0x00007ffff7f4d428 in GC_find_limit_with_bound ()
#1  0x00007ffff7f4d4eb in GC_init_linux_data_start ()
#2  0x00007ffff7f4c521 in GC_init ()
#3  0x00007ffff7f09770 in init () at /usr/lib/crystal/core/gc/boehm.cr:88
#4  0x00007ffff7f456eb in main () at /usr/lib/crystal/core/crystal/main.cr:35
#5  0x00007ffff7ef1996 in main () at /usr/lib/crystal/core/crystal/main.cr:106

Building the code with dynamic linking works - crystal build cli.cr && ./cli ver returns 0.1

Crystal version:

/ # crystal -v
Crystal 0.26.1 (2018-08-30)

LLVM: 5.0.1
Default target: x86_64-alpine-linux-musl
@RX14
Copy link
Contributor

RX14 commented Oct 12, 2018

looks like a bdwgc bug

@RX14
Copy link
Contributor

RX14 commented Oct 12, 2018

actually, that gdb SIGBUS is expected, you should keep using continue when you get a SIGBUS inside GC_find_limit* until you get to the real segfault

@j8r
Copy link
Contributor Author

j8r commented Oct 12, 2018

Thanks @RX14 , after continuing:

Continuing.
[New LWP 22454]
[New LWP 22455]
[New LWP 22456]

Thread 1 "cli" received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()

@RX14
Copy link
Contributor

RX14 commented Oct 12, 2018

useful...

@ysbaddaden
Copy link
Contributor

Sounds a lot like #4276

@j8r
Copy link
Contributor Author

j8r commented Oct 12, 2018

Compiling with crystal build --link-flags "-static -lunwind" seems to do the trick...

@j8r
Copy link
Contributor Author

j8r commented Oct 12, 2018

Reduced example:

raise ""
Invalid memory access (signal 11) at address 0x0
[1]    1481 segmentation fault (core dumped)  ./bin

Duplicate of #4276

@j8r j8r closed this as completed Oct 12, 2018
@RX14
Copy link
Contributor

RX14 commented Oct 13, 2018

@j8r does --static --link-flags=-lunwind fix it? If those link flags fix the issue I think we can fix it for everyone

@j8r
Copy link
Contributor Author

j8r commented Oct 13, 2018

I've followed @ysbaddaden 's suggestion. The backtrace is empty, but at least the static linking procudes a working binary.

@rdp
Copy link
Contributor

rdp commented Dec 19, 2021

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

No branches or pull requests

4 participants