-
-
Notifications
You must be signed in to change notification settings - Fork 25
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
Memory address errors on linux x64 #7
Comments
Hi @Gelbpunkt, thanks for reporting the issue.
Sorry to read this. I'll try my best to fix the problem, but unfortunately I don't have access to a machine running Linux, so I'll have to guess a bit. Would you mind trying to run the following code with multithreading enabled and see if it runs fine? require "compiler/crystal/**"
puts "Main thread: #{Thread.current}"
sources = [
Crystal::Compiler::Source.new("hello.cr", %(puts "Hello world!")),
]
trigger = Channel(Nil).new
sync = Channel(String).new
Thread.new do
puts "Thread > #{Thread.current}"
kill_thread = Channel(Nil).new
spawn same_thread: true do
puts "Thread > Spawn on thread: #{Thread.current}"
begin
trigger.receive
puts "Thread > Compiling…"
compiler = Crystal::Compiler.new
compiler.no_codegen = true
puts "Thread > Before compilation."
result = compiler.compile(sources, "")
puts "Thread > Compilation done."
sync.send "Ok: #{!result.nil?}"
rescue e
sync.send "Error: #{e}"
end
kill_thread.send nil
end
kill_thread.receive
end
puts "Main > Waiting…"
trigger.send nil
puts sync.receive
puts "Main > Bye!" Basically saving the code in a file and running in a terminal: crystal run file.cr -Dpreview_mt --debug |
I am not sure what I should do with this. I started with errors like this: --: : command not found
Showing last frame. Use --error-trace for full trace.
In crystal/crystal-0.35.1-1/share/crystal/src/llvm/lib_llvm.cr:13:17
13 | VERSION = {{`#{LibLLVM::LLVM_CONFIG} --version`.chomp.stringify}}
^ which fixed itself after installing llvm-devel (version 10). /usr/bin/ld: /home/jens/crystal/crystal-0.35.1-1/share/crystal/src/llvm/ext/llvm_ext.o: in function `llvm::MetadataTracking::track(llvm::Metadata*&)':
llvm_ext.cc:(.text._ZN4llvm16MetadataTracking5trackERPNS_8MetadataE[_ZN4llvm16MetadataTracking5trackERPNS_8MetadataE]+0x42): undefined reference to `llvm::MetadataTracking::track(void*, llvm::Metadata&, llvm::PointerUnion<llvm::MetadataAsValue*, llvm::Metadata*>)'
collect2: error: ld returned 1 exit status
Error: execution of command failed with code: 1: `cc "${@}" -o /home/jens/.cache/crystal/crystal-run-test.tmp -rdynamic -L/home/jens/crystal/crystal-0.35.1-1/bin/../lib/crystal/lib -lz `command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libssl || printf %s '-lssl -lcrypto'` `command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libcrypto || printf %s '-lcrypto'` /home/jens/crystal/crystal-0.35.1-1/share/crystal/src/llvm/ext/llvm_ext.o `"/usr/bin/llvm-config" --libs --system-libs --ldflags 2> /dev/null` -lstdc++ -lpcre -lm -lgc -lpthread /home/jens/crystal/crystal-0.35.1-1/share/crystal/src/ext/libcrystal.a -levent_pthreads -levent -levent -lrt -ldl` I am guessing this is a LLVM version mismatch so I will compile crystal from source |
@Gelbpunkt Yes I'm sorry the snippet I posted forces you to compile the crystal compiler from source, which can be complicated. I think we can attempt to reproduce the issue with less accurate but simpler code first: crystal run file.cr -Dpreview_mt --debug # file.cr
puts "Main thread: #{Thread.current}"
trigger = Channel(Nil).new
sync = Channel(String).new
Thread.new do
puts "Thread > #{Thread.current}"
kill_thread = Channel(Nil).new
spawn same_thread: true do
puts "Thread > Spawn #{Fiber.current} on thread: #{Thread.current}"
begin
trigger.receive
GC.collect
sync.send "Ok"
rescue e
sync.send "Error: #{e}"
end
kill_thread.send nil
end
kill_thread.receive
end
puts "Main > Waiting…"
trigger.send nil
puts sync.receive
puts "Main > Bye!" |
While that did not run on a self-compiled crystal 1.0.0-dev: In test.cr:1:1
1 | puts "Main thread: #{Thread.current}"
^
Error: can't find file 'prelude' it ran fine on the 0.35.1 release tarball: Main thread: #<Thread:0x7fb540671f50>
Main > Waiting…
Thread > #<Thread:0x7fb540671af0>
Thread > Spawn #<Fiber:0x7fb5406729a0> on thread: #<Thread:0x7fb540671af0>
Ok
Main > Bye! |
Hmm then I was wrong about that piece of code I guess. I was thinking that spawning a thread manually using If it's not too much to ask, could you try building crystalline from source and try with the produced binary instead of using the prebuilt one? |
It took a long while due to issues with LLVM again, ended up building crystal from source and then compiling crystalline without shards as that forkbombed itself. The resulting binary works fine (yay!), so I assume the issue is with the build setup you are using. |
Sorry you had to go through this, it's a good thing that it worked in the end 👍. The build system uses an alpine linux docker image to build a static and supposedly portable binary, I will try my best to check why it is crashing on Fedora but without access to a linux machine it's going to be a bit complicated. |
Just FYI, I just got the exact same issue on my windows machine, using WSL2 |
Hi @tducasse, thanks for reporting! Out of curiosity, are you able to build it from sources and run it as well? |
Yeah I'll try that today or tomorrow, maybe even try to find a way to fix the dockerfile if I find the time :) |
okay so I've tried multiple things, but I basically did not succeed in compiling from sources, but I think WSL might be the issue here, since WSL has a tendency to look like it's working but actually it's not 😬 What I've tried though (in order to fix the Dockerfile that builds the static binary), is building from the official docker image ( docker run --rm -it -v $PWD:/app -w /app crystallang/crystal:0.35.1-alpine-build shards build crystalline --release --static --progress --no-debug -Dpreview_mt This yelled at me telling me that it could not find
This goes further, but still fails:
So now I'm not entirely sure what the problem is, but I think it might be related to this issue about multi threads. Happy to help and delve further into the issue, but keep in mind I'm way out of my league here, as I've not even written my first line of Crystal code yet 🤣 |
As far as I can tell, this is a known issue with the FROM crystallang/crystal:0.35.1-alpine-build
# not sure whether it's llvm10 or 9 here, depends on their Dockerfile
RUN g++ -c usr/share/crystal/src/llvm/ext/llvm_ext.cc -I/usr/lib/llvm10/include -o /usr/share/crystal/src/llvm/ext/llvm_ext.o Just FYI, I was able to manually compile a static binary using this Dockerfile (inspired by the PR I linked to): FROM alpine:3.12 as runtime
RUN \
apk add --update --no-cache --force-overwrite \
# core dependencies
gcc gmp-dev libevent-static musl-dev pcre-dev \
# stdlib dependencies
libxml2-dev openssl-dev openssl-libs-static tzdata yaml-dev yaml-static zlib-static \
# dev tools
make git patch autoconf automake libtool
ARG patch
COPY ${patch} /tmp/feature-thread-stackbottom-upstream.patch
ARG gc_version
ARG libatomic_ops_version
RUN git clone https://github.com/ivmai/bdwgc \
&& cd bdwgc \
&& git checkout ${gc_version} \
&& git clone https://github.com/ivmai/libatomic_ops \
&& (cd libatomic_ops && git checkout ${libatomic_ops_version}) \
\
&& patch -p1 < /tmp/feature-thread-stackbottom-upstream.patch \
\
&& ./autogen.sh \
&& ./configure --disable-debug --disable-shared --enable-large-config \
&& make -j$(nproc) CFLAGS=-DNO_GETCONTEXT \
&& make install
# Remove build tools from image now that libgc is built
RUN apk del -r --purge autoconf automake libtool
ARG crystal_targz
COPY ${crystal_targz} /tmp/crystal.tar.gz
RUN \
tar -xz -C /usr --strip-component=1 -f /tmp/crystal.tar.gz \
--exclude */lib/crystal/lib \
--exclude */share/crystal/src/llvm/ext/llvm_ext.o \
--exclude */share/crystal/src/ext/libcrystal.a && \
rm /tmp/crystal.tar.gz
# Build libcrystal
RUN \
cd /usr/share/crystal && \
cc -fPIC -c -o src/ext/sigfault.o src/ext/sigfault.c && \
ar -rcs src/ext/libcrystal.a src/ext/sigfault.o
CMD ["/bin/sh"]
FROM runtime as build
RUN \
apk add --update --no-cache --force-overwrite \
llvm10-dev llvm10-static g++
RUN g++ -c usr/share/crystal/src/llvm/ext/llvm_ext.cc -I/usr/lib/llvm10/include -o /usr/share/crystal/src/llvm/ext/llvm_ext.o
CMD ["/bin/sh"] And running: # build the image, in a folder containing the Dockerfile
# I downloaded the crystal tar from the official release channel
# and the patch from https://github.com/crystal-lang/distribution-scripts/blob/master/linux/files/feature-thread-stackbottom-upstream.patch
docker build \
--build-arg gc_version=v8.0.4 \
--build-arg libatomic_ops_version=v7.6.10 \
--build-arg patch=./feature-thread-stackbottom-upstream.patch \
--build-arg crystal_targz=crystal-0.35.1-1-linux-x86_64.tar.gz \
-t crystalbuilder .
# build crystalline, in the crystalline folder
docker run --rm -it -v $PWD:/app -w /app crystalbuilder crystal build src/crystalline.cr -o bin/crystalline --static --release --no-debug --progress -Dpreview_mt |
@tducasse Thanks a bunch for investigating, you've done an amazing work! I will rewrite the alpine Dockerfile to include the GC patch until the original pull request gets merged (and I also realized that I forgot the preview_mt flag 🤦). It should solve the issue hopefully. |
No worries, happy to help 🙂 |
This still happens on Solus Linux
I receive this:
Code: module Ll
VERSION = "0.1.0"
name = "something"
nickname = "astrolemonade"
handle = name + "@" + nickname
puts handle
print("ha")
end With the Github release it works. |
Hey @astrolemonade,
I am sorry to read this. I do not have access to a Linux environment so I am afraid I cannot do anything to fix this yet (and the
I guess using docker or similar to build crystalline should also work on any linux distro 🤞. |
I could confirm with openSUSE Tumbleweed as well. I am building it inside OBS and I was looking at this issue since I thought I was just paranoid. Well we can still keep this issue open until there is a solution right? |
I tested a non release build of crystalline 0.10.0 and got this errors.
|
Hi, I am using the crystal-language extension as mentioned in the README and set the path to the prebuilt crystalline version that I downloaded from the releases.
Once I start VSCode and hover something, it crashes:
I am using Fedora Linux 32 (x86_64) with Crystal 0.35.1 and VSCode 1.50.1, the Crystal Language extension version is 0.6.2
The text was updated successfully, but these errors were encountered: