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

Invalid memory access (signal 11) #4391

Closed
petoem opened this Issue May 8, 2017 · 12 comments

Comments

Projects
None yet
5 participants
@petoem
Copy link
Contributor

petoem commented May 8, 2017

I recently ported a haste-client from ruby to crystal.
My crystal version: https://github.com/petoem/haste-client

Operation System: Solus OS, Kernel 4.9.26
Crystal 0.22.0 [3c71228] (2017-04-20) LLVM 3.5.0

When trying to compile the haste-client it gives this output:

crystal build src/haste.cr --release
Invalid memory access (signal 11) at address 0x8
[0x56ef3f] __crystal_sigfault_handler +63
[0x28c3914] sigfault_handler +40
[0x7f01b3be9b30] ???
[0x229c03b] ???
[0x229cea1] ???
[0x229f361] ???
[0x22a0fb1] ???
[0x27f5fdf] _ZN4llvm13FPPassManager13runOnFunctionERNS_8FunctionE +607
[0x27f601b] _ZN4llvm13FPPassManager11runOnModuleERNS_6ModuleE +43
[0x27f5c57] _ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE +759
[0x2623047] ???
[0x26237f5] LLVMTargetMachineEmitToFile +325
[0x14f585b] ???
[0x14343cf] ???
[0x1cb6645] ???
[0x5a23f9] ???
[0x56e86d] main +18893
[0x7f01b3554671] __libc_start_main +241
[0x53b871] ???

The same with this:

crystal deps build --release
Building: haste
Error target haste failed to compile:
Invalid memory access (signal 11) at address 0x8
[0x56ef3f] __crystal_sigfault_handler +63
[0x28c3914] sigfault_handler +40
[0x7f019f8d7b30] ???
[0x229c03b] ???
[0x229cea1] ???
[0x229f361] ???
[0x22a0fb1] ???
[0x27f5fdf] _ZN4llvm13FPPassManager13runOnFunctionERNS_8FunctionE +607
[0x27f601b] _ZN4llvm13FPPassManager11runOnModuleERNS_6ModuleE +43
[0x27f5c57] _ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE +759
[0x2623047] ???
[0x26237f5] LLVMTargetMachineEmitToFile +325
[0x14f585b] ???
[0x14343cf] ???
[0x1cb6645] ???
[0x5a23f9] ???
[0x56e86d] main +18893
[0x7f019f242671] __libc_start_main +241
[0x53b871] ???

i can successfully compile it with the following commands:
crystal deps build
crystal build src/haste.cr

It seems that adding --release makes it fail.

oh, by the way it compiles with crystal deps build --production but i have no idea what --production flag does.

@ysbaddaden

This comment has been minimized.

Copy link
Member

ysbaddaden commented May 8, 2017

Would you be able to compile crystal itself against LLVM 3.8? We have known issues with older LLVM versions which we're removing support for (further releases will use LLVM 3.8.1).

@petoem

This comment has been minimized.

Copy link
Contributor

petoem commented May 8, 2017

@ysbaddaden i have just noticed that my installed LLVM version is 3.9.1 but crystal --version reports 3.5.0.

I tried to compile crystal as described in the docs. (with additional git checkout tags/0.22.0)
But running make spec gives this.

Using /usr/bin/llvm-config [version=3.9.1]
./bin/crystal build  -o .build/all_spec spec/all_spec.cr
Using compiled compiler at .build/crystal
Error in spec/all_spec.cr:1: while requiring "prelude"

require "spec"
^

in src/prelude.cr:15: while requiring "exception"

require "exception"
^

in src/exception.cr:1: while requiring "callstack"

require "callstack"
^

in src/callstack.cr:1: while requiring "c/dlfcn": can't find file 'c/dlfcn' relative to '/home/petoem/Projects/crystal/src'

require "c/dlfcn"
^

make: *** [Makefile:102: .build/all_spec] Error 1
@ysbaddaden

This comment has been minimized.

Copy link
Member

ysbaddaden commented May 8, 2017

We don't seem to have a libc bindings for your host, or we don't understand/support the target to select one. What does llvm-config --host-target prints?

@petoem

This comment has been minimized.

Copy link
Contributor

petoem commented May 8, 2017

llvm-config --host-target
x86_64-solus-linux

What are the supported target triples for crystal?

@kirbyfan64

This comment has been minimized.

Copy link
Contributor

kirbyfan64 commented May 8, 2017

I think maybe you could just do something like crystal build --triple x86_64-linux-gnu thing.cr.

@petoem

This comment has been minimized.

Copy link
Contributor

petoem commented May 8, 2017

I made a hello world test file, with this code:

puts "Hello World !"

I tried to compile it and it works normally. With --release and --target set to x86_64-linux-gnu.

But compiling my haste-client works only without --release mode.
If I try to use --release mode it fails as before.

@RX14

This comment has been minimized.

Copy link
Member

RX14 commented May 8, 2017

So, why does solus have a separate target triple, and what are the differences (if any) between it's abi and x86_64-linux-gnu? I can't find any info on the internet. If there are none then we should just alias it.

@petoem

This comment has been minimized.

Copy link
Contributor

petoem commented May 8, 2017

You can take a look at the llvm package or others here.
https://git.solus-project.com/packages/llvm/

@ysbaddaden

This comment has been minimized.

Copy link
Member

ysbaddaden commented May 9, 2017

About the --release issue: it would seem the issue isn't related to the LLVM version, thanks for testing. Now we have another bug 😞

About the host target, this is part a Solus issue, part a Crystal issue.

The Solus issue is that the x86_64-solus-linux target tiple is invalid. We understand it as:

  • arch=x86_64 (correct)
  • sys=solus (wrong: it's the vendor)
  • abi=linux (wrong: it's the sys)

The triple is missing an actual ABI (libc) to target. Assuming the libc is glibc, it should be x86_64-solus-linux-gnu instead, or plainly x86_64-linux-gnu, or x86_64-linux-musl for musl-libc, or arm-linux-gnueabi for glibc on ARM, arm-linux-android for Android (unsupported), ...

The Crystal issue is that we use pre-generated libc bindings. Ideally we should generate them automatically from C headers. That would avoid the issue, but it's more complicated to put in place and would require more libraries (i.e. libclang).

@petoem

This comment has been minimized.

Copy link
Contributor

petoem commented May 9, 2017

Yes, Solus OS uses glibc.
I thought, maybe x86_64-linux-gnu works and @RX14 said it could be aliased, but i didn't know how.
So i just copied src/lib_c/x86_64-linux-gnu to src/lib_c/x86_64-solus-linux. 😆
It compiles "make" successfully as before, but now make spec works too.

Output:

 make spec
Using /usr/bin/llvm-config [version=3.9.1]
./bin/crystal build  -o .build/all_spec spec/all_spec.cr
Using compiled compiler at .build/crystal
.build/all_spec 
.....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................*.........................................................................................................................................................................................................................................................................................................................................................................**.............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................*.........................................................................................................................................................................................................................................................**...............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................*....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................*..............................................*.....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................Using compiled compiler at .build/crystal
.Using compiled compiler at .build/crystal
.Using compiled compiler at .build/crystal
.............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................F...........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................*.............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................***................................................................................................................................................................................................................................................................................................................................

Pending:
  Code gen: lib codegens lib var set and get
  Code gen: primitives codegens pointer of int
  Code gen: primitives sums two numbers out of an [] of Number
  Semantic: cast casts from union to incompatible union gives error
  Semantic: def overload restricts on generic type with free type arg
  Semantic: def overload restricts on generic type without type arg
  Semantic: instance var doesn't infer type to be nilable if using self.class in call in assign
  Semantic: pointer allows using pointer with subclass
  Semantic: primitives types pointer of int
  Math Functions for computing quotient and remainder
  Thread::ConditionVariable signals
  Thread::ConditionVariable broadcasts
  Thread::ConditionVariable waits and send signal

Failures:

  1) File touch raises if file cannot be accessed
     Failure/Error: expect_raises Errno, "Operation not permitted" do

       Expected Errno but nothing was raised

     # spec/std/file_spec.cr:1023

Finished in 28:42 minutes
12143 examples, 1 failures, 0 errors, 13 pending

Failed examples:

crystal spec spec/std/file_spec.cr:1022 # File touch raises if file cannot be accessed
make: *** [Makefile:77: spec] Error 1
@petoem

This comment has been minimized.

Copy link
Contributor

petoem commented May 9, 2017

Copying the directory src/lib_c/x86_64-linux-gnu to src/lib_c/x86_64-solus-linux solved it.
Now my haste-client compiles successfully with --release mode added.

@ysbaddaden

This comment has been minimized.

Copy link
Member

ysbaddaden commented May 9, 2017

Maybe create a symlink instead of copying, so pulling a new Crystal version will automatically update the libc (it might change), but I guess it doesn't matter much since the next release should be compiled with LLVM 3.8.1

Closing, since this is an LLVM issue...

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