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

Can't build any programs on 32-bit ARM #11497

Closed
straight-shoota opened this issue Nov 25, 2021 · 0 comments · Fixed by #11499
Closed

Can't build any programs on 32-bit ARM #11497

straight-shoota opened this issue Nov 25, 2021 · 0 comments · Fixed by #11499
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. kind:regression Something that used to correctly work but no longer works platform:arm topic:stdlib:numeric

Comments

@straight-shoota
Copy link
Member

straight-shoota commented Nov 25, 2021

Linking any Crystal program (even an empty one) on an arm architecture fails with the following error:

$ cc .build/crystal.o -o .build/crystal  -rdynamic -L/usr/bin/../lib/crystal src/llvm/ext/llvm_ext.o `"/usr/bin/llvm-config-12" --libs --system-libs --ldflags 2> /dev/null` -lstdc++ -lpcre -lm -lgc -lpthread -levent -lrt -ldl
/usr/bin/ld: .build/crystal.o: in function `__muloti4':
/home/thesseyren/Masaüstü/crystal-arm/crystal/src/crystal/compiler_rt/mul.cr:42: undefined reference to `__multi3'
/usr/bin/ld: .build/crystal.o: in function `//':
/home/thesseyren/Masaüstü/crystal-arm/crystal/src/int.cr:105: undefined reference to `__multi3'
/usr/bin/ld: /home/thesseyren/Masaüstü/crystal-arm/crystal/src/int.cr:105: undefined reference to `__multi3'
/usr/bin/ld: .build/crystal.o: in function `_carrying_mul':
/home/thesseyren/Masaüstü/crystal-arm/crystal/src/crystal/compiler_rt/divmod128.cr:45: undefined reference to `__multi3'
/usr/bin/ld: .build/crystal.o: in function `_carrying_mul_add':
/home/thesseyren/Masaüstü/crystal-arm/crystal/src/crystal/compiler_rt/divmod128.cr:56: undefined reference to `__multi3'
/usr/bin/ld: .build/crystal.o:/home/thesseyren/Masaüstü/crystal-arm/crystal/src/crystal/compiler_rt/divmod128.cr:161: more undefined references to `__multi3' follow
collect2: error: ld returned 1 exit status

The function __multi3 is undefined in compiler-rt on 32-bit ARM.

There should be no implicit 128-bit arithmetics in Crystal program, unless you explicitly use those data types. Even the compiler has not yet support for parsing 128-bit integer literals.

#11206 added __muloti4 etc. which do 128-bit arithmetics and are defined as a fun. So they' always get compiled, even when never called.

A quick temporary workaround is this patch, which disables the troublesome functions on arm. They're currently not necessary unless you actually use 128-bit arithmetics.

--- i/src/crystal/compiler_rt/divmod128.cr
+++ w/src/crystal/compiler_rt/divmod128.cr
@@ -1,4 +1,5 @@
 # This file includes an implementation of (U)Int128 modulo/division operations
+{% skip_file if flag?(:arm) %}

 # :nodoc:
 fun __divti3(a : Int128, b : Int128) : Int128
diff --git i/src/crystal/compiler_rt/mul.cr w/src/crystal/compiler_rt/mul.cr
index affe2f2f8..6f90b3346 100644
--- i/src/crystal/compiler_rt/mul.cr
+++ w/src/crystal/compiler_rt/mul.cr
@@ -39,4 +39,3 @@ end

 __mul_impl(__mulosi4, Int32, 32)
 __mul_impl(__mulodi4, Int64, 64)
-__mul_impl(__muloti4, Int128, 128)
+{% unless flag?(:arm) %}
+  __mul_impl(__muloti4, Int128, 128)
+{% end %}

Of course, this is not a real solution because we want to support 128-bit arithmetics on all platforms. Implementing the compiler-rt functions ourselves is actually a step to enable that for 32-bit architectures. It seems we need to implement __multi3 as well. At least for arm.

This was originally reported in https://forum.crystal-lang.org/t/cant-compile-crystal-1-2-2-on-32-bit-arm-armv7l-device-undefined-reference-to-multi3/4077/7

i386 seems to be unaffected, so apparently __multi3 is available.

@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:numeric kind:regression Something that used to correctly work but no longer works platform:arm labels Nov 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. kind:regression Something that used to correctly work but no longer works platform:arm topic:stdlib:numeric
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant