Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Using binary_to_float/1 results in undefined symbol when linking #480

Open
KronicDeth opened this issue Aug 9, 2020 · 0 comments
Open
Assignees
Labels
compiler Issues pertaining to the compiler with no specific tag help wanted We'd love your help getting this one done! runtime/bifs runtime
Milestone

Comments

@KronicDeth
Copy link
Collaborator

When trying to use binary_to_float/1 in compiled Erlang code, a Rust core::fmt symbol cannot be found during linking.

init.erl

-module(init).
-export([start/0]).
-import(erlang, [binary_to_float/1, display/1]).

start() ->
  display(binary_to_float(<<"-1.2">>)),
  display(binary_to_float(<<"0.0">>)),
  display(binary_to_float(<<"3.4">>)).

init.llvm.mlir



module @init {
  llvm.mlir.global internal constant @f23a602910dc8852626969ed2cab4934b4ae5d5b("3.4")
  llvm.mlir.global internal constant @binary_f23a602910dc8852626969ed2cab4934b4ae5d5b() : !llvm<"%binary = type { i64, i64, i8* }"> {
    %0 = llvm.mlir.addressof @f23a602910dc8852626969ed2cab4934b4ae5d5b : !llvm<"[3 x i8]*">
    %1 = llvm.mlir.constant(0 : i64) : !llvm.i64
    %2 = llvm.mlir.constant(1829587348619264 : i64) : !llvm.i64
    %3 = llvm.mlir.constant(26 : i64) : !llvm.i64
    %4 = llvm.mlir.undef : !llvm<"%binary = type { i64, i64, i8* }">
    %5 = llvm.getelementptr %0[%1, %1] : (!llvm<"[3 x i8]*">, !llvm.i64, !llvm.i64) -> !llvm<"i8*">
    %6 = llvm.insertvalue %2, %4[0] : !llvm<"%binary = type { i64, i64, i8* }">
    %7 = llvm.insertvalue %3, %6[1] : !llvm<"%binary = type { i64, i64, i8* }">
    %8 = llvm.insertvalue %5, %7[2] : !llvm<"%binary = type { i64, i64, i8* }">
    llvm.return %8 : !llvm<"%binary = type { i64, i64, i8* }">
  }
  llvm.mlir.global internal constant @"38f6d7875e3195bdaee448d2cb6917f3ae4994af"("0.0")
  llvm.mlir.global internal constant @binary_38f6d7875e3195bdaee448d2cb6917f3ae4994af() : !llvm<"%binary = type { i64, i64, i8* }"> {
    %0 = llvm.mlir.addressof @"38f6d7875e3195bdaee448d2cb6917f3ae4994af" : !llvm<"[3 x i8]*">
    %1 = llvm.mlir.constant(0 : i64) : !llvm.i64
    %2 = llvm.mlir.constant(1829587348619264 : i64) : !llvm.i64
    %3 = llvm.mlir.constant(26 : i64) : !llvm.i64
    %4 = llvm.mlir.undef : !llvm<"%binary = type { i64, i64, i8* }">
    %5 = llvm.getelementptr %0[%1, %1] : (!llvm<"[3 x i8]*">, !llvm.i64, !llvm.i64) -> !llvm<"i8*">
    %6 = llvm.insertvalue %2, %4[0] : !llvm<"%binary = type { i64, i64, i8* }">
    %7 = llvm.insertvalue %3, %6[1] : !llvm<"%binary = type { i64, i64, i8* }">
    %8 = llvm.insertvalue %5, %7[2] : !llvm<"%binary = type { i64, i64, i8* }">
    llvm.return %8 : !llvm<"%binary = type { i64, i64, i8* }">
  }
  llvm.func @"erlang:display/1"(!llvm.i64) -> !llvm.i64
  llvm.func @"erlang:binary_to_float/1"(!llvm.i64) -> !llvm.i64
  llvm.mlir.global internal constant @"39b03021ccec2f1082b7882268c947992ddeb310"("-1.2")
  llvm.mlir.global internal constant @binary_39b03021ccec2f1082b7882268c947992ddeb310() : !llvm<"%binary = type { i64, i64, i8* }"> {
    %0 = llvm.mlir.addressof @"39b03021ccec2f1082b7882268c947992ddeb310" : !llvm<"[4 x i8]*">
    %1 = llvm.mlir.constant(0 : i64) : !llvm.i64
    %2 = llvm.mlir.constant(1829587348619264 : i64) : !llvm.i64
    %3 = llvm.mlir.constant(34 : i64) : !llvm.i64
    %4 = llvm.mlir.undef : !llvm<"%binary = type { i64, i64, i8* }">
    %5 = llvm.getelementptr %0[%1, %1] : (!llvm<"[4 x i8]*">, !llvm.i64, !llvm.i64) -> !llvm<"i8*">
    %6 = llvm.insertvalue %2, %4[0] : !llvm<"%binary = type { i64, i64, i8* }">
    %7 = llvm.insertvalue %3, %6[1] : !llvm<"%binary = type { i64, i64, i8* }">
    %8 = llvm.insertvalue %5, %7[2] : !llvm<"%binary = type { i64, i64, i8* }">
    llvm.return %8 : !llvm<"%binary = type { i64, i64, i8* }">
  }
  llvm.func @__lumen_builtin_yield()
  llvm.mlir.global external local_exec @CURRENT_REDUCTION_COUNT() : !llvm.i32
  llvm.func @lumen_eh_personality(...) -> !llvm.i32
  llvm.func @"init:start/0"() -> !llvm.i64 attributes {personality = @lumen_eh_personality} {
    %0 = llvm.mlir.constant(20 : i32) : !llvm.i32
    %1 = llvm.mlir.addressof @CURRENT_REDUCTION_COUNT : !llvm<"i32*">
    %2 = llvm.load %1 : !llvm<"i32*">
    %3 = llvm.icmp "uge" %2, %0 : !llvm.i32
    llvm.cond_br %3, ^bb1, ^bb2
  ^bb1:  // pred: ^bb0
    llvm.call @__lumen_builtin_yield() : () -> ()
    llvm.br ^bb2
  ^bb2:  // 2 preds: ^bb0, ^bb1
    %4 = llvm.mlir.addressof @binary_39b03021ccec2f1082b7882268c947992ddeb310 : !llvm<"%binary*">
    %5 = llvm.ptrtoint %4 : !llvm<"%binary*"> to !llvm.i64
    %6 = llvm.mlir.constant(1 : i64) : !llvm.i64
    %7 = llvm.or %5, %6 : !llvm.i64
    %8 = llvm.mlir.addressof @CURRENT_REDUCTION_COUNT : !llvm<"i32*">
    %9 = llvm.mlir.constant(1 : i32) : !llvm.i32
    %10 = llvm.atomicrmw add %8, %9 monotonic  : !llvm.i32
    %11 = llvm.call @"erlang:binary_to_float/1"(%7) {tail} : (!llvm.i64) -> !llvm.i64
    %12 = llvm.mlir.addressof @CURRENT_REDUCTION_COUNT : !llvm<"i32*">
    %13 = llvm.atomicrmw add %12, %9 monotonic  : !llvm.i32
    %14 = llvm.call @"erlang:display/1"(%11) {tail} : (!llvm.i64) -> !llvm.i64
    %15 = llvm.mlir.addressof @binary_38f6d7875e3195bdaee448d2cb6917f3ae4994af : !llvm<"%binary*">
    %16 = llvm.ptrtoint %15 : !llvm<"%binary*"> to !llvm.i64
    %17 = llvm.or %16, %6 : !llvm.i64
    %18 = llvm.mlir.addressof @CURRENT_REDUCTION_COUNT : !llvm<"i32*">
    %19 = llvm.atomicrmw add %18, %9 monotonic  : !llvm.i32
    %20 = llvm.call @"erlang:binary_to_float/1"(%17) {tail} : (!llvm.i64) -> !llvm.i64
    %21 = llvm.mlir.addressof @CURRENT_REDUCTION_COUNT : !llvm<"i32*">
    %22 = llvm.atomicrmw add %21, %9 monotonic  : !llvm.i32
    %23 = llvm.call @"erlang:display/1"(%20) {tail} : (!llvm.i64) -> !llvm.i64
    %24 = llvm.mlir.addressof @binary_f23a602910dc8852626969ed2cab4934b4ae5d5b : !llvm<"%binary*">
    %25 = llvm.ptrtoint %24 : !llvm<"%binary*"> to !llvm.i64
    %26 = llvm.or %25, %6 : !llvm.i64
    %27 = llvm.mlir.addressof @CURRENT_REDUCTION_COUNT : !llvm<"i32*">
    %28 = llvm.atomicrmw add %27, %9 monotonic  : !llvm.i32
    %29 = llvm.call @"erlang:binary_to_float/1"(%26) {tail} : (!llvm.i64) -> !llvm.i64
    %30 = llvm.mlir.addressof @CURRENT_REDUCTION_COUNT : !llvm<"i32*">
    %31 = llvm.atomicrmw add %30, %9 monotonic  : !llvm.i32
    %32 = llvm.call @"erlang:display/1"(%29) {tail} : (!llvm.i64) -> !llvm.i64
    llvm.return %32 : !llvm.i64
  }
}

STDERR

---- erlang::binary_to_float_1::with_binary_with_f64_returns_float stdout ----
thread 'erlang::binary_to_float_1::with_binary_with_f64_returns_float' panicked at 'stdout = 
stderr =    Compiling tests/lib/erlang/binary_to_float_1/with_binary_with_f64_returns_float/init.erl
debug: optimization pass sdagisel (missed) in init:start/0 (5:1 @ /Users/luke.imhoff/github/lumen/lumen/native_implemented/otp/tests/lib/erlang/binary_to_float_1/with_binary_with_f64_returns_float/init.erl)
debug: optimization pass sdagisel (missed) in init:start/0 (8:3 @ /Users/luke.imhoff/github/lumen/lumen/native_implemented/otp/tests/lib/erlang/binary_to_float_1/with_binary_with_f64_returns_float/init.erl)
debug: optimization pass sdagisel (missed) in init:start/0 (8:3 @ /Users/luke.imhoff/github/lumen/lumen/native_implemented/otp/tests/lib/erlang/binary_to_float_1/with_binary_with_f64_returns_float/init.erl)
debug: optimization pass asm-printer (missed) in init:start/0 (5:0 @ /Users/luke.imhoff/github/lumen/lumen/native_implemented/otp/tests/lib/erlang/binary_to_float_1/with_binary_with_f64_returns_float/init.erl)
debug: optimization pass sdagisel (missed) in init:start/0 (5:1 @ /Users/luke.imhoff/github/lumen/lumen/native_implemented/otp/tests/lib/erlang/binary_to_float_1/with_binary_with_f64_returns_float/init.erl)
debug: optimization pass sdagisel (missed) in init:start/0 (8:3 @ /Users/luke.imhoff/github/lumen/lumen/native_implemented/otp/tests/lib/erlang/binary_to_float_1/with_binary_with_f64_returns_float/init.erl)
debug: optimization pass sdagisel (missed) in init:start/0 (8:3 @ /Users/luke.imhoff/github/lumen/lumen/native_implemented/otp/tests/lib/erlang/binary_to_float_1/with_binary_with_f64_returns_float/init.erl)
debug: optimization pass asm-printer (missed) in init:start/0 (5:0 @ /Users/luke.imhoff/github/lumen/lumen/native_implemented/otp/tests/lib/erlang/binary_to_float_1/with_binary_with_f64_returns_float/init.erl)
    Compiled tests/lib/erlang/binary_to_float_1/with_binary_with_f64_returns_float/init.erl
debug: optimization pass sdagisel (missed) in __lumen_lang_start_internal (0:0 @ <unknown file>)
debug: optimization pass asm-printer (missed) in __lumen_lang_start_internal (0:0 @ <unknown file>)
debug: optimization pass sdagisel (missed) in __lumen_trap_exceptions (0:0 @ <unknown file>)
debug: optimization pass sdagisel (missed) in __lumen_trap_exceptions (0:0 @ <unknown file>)
debug: optimization pass sdagisel (missed) in __lumen_trap_exceptions (0:0 @ <unknown file>)
debug: optimization pass asm-printer (missed) in __lumen_trap_exceptions (0:0 @ <unknown file>)
error: linking failed: exit code: 1

"cc" "-m64" "-arch" "x86_64" "-L" "/Users/luke.imhoff/github/lumen/lumen/bin/x86_64-apple-macosx10.7.0/lib/lumenlib/x86_64-apple-macosx10.7.0/lib" "tests/lib/erlang/binary_to_float_1/with_binary_with_f64_returns_float/_build/init.o" "tests/lib/erlang/binary_to_float_1/with_binary_with_f64_returns_float/_build/liblumen_crt_atoms.o" "tests/lib/erlang/binary_to_float_1/with_binary_with_f64_returns_float/_build/liblumen_crt_dispatch.o" "tests/lib/erlang/binary_to_float_1/with_binary_with_f64_returns_float/_build/liblumen_crt_exceptions.o" "-o" "tests/lib/erlang/binary_to_float_1/with_binary_with_f64_returns_float/bin/with_binary_with_f64_returns_float" "-Wl,-dead_strip" "-nodefaultlibs" "-L" "/Users/luke.imhoff/github/lumen/lumen/bin/x86_64-apple-macosx10.7.0/lib/lumenlib/x86_64-apple-macosx10.7.0/lib" "-Wl,-force_load" "-Wl,/var/folders/kz/_y_vgl6505v0hgx16pt1vdsr0000gn/T/lumenjlWdJh/libpanic_unwind.rlib" "-Wl,-force_load" "-Wl,/Users/luke.imhoff/github/lumen/lumen/bin/x86_64-apple-macosx10.7.0/lib/lumenlib/x86_64-apple-macosx10.7.0/lib/liblumen_rt_minimal.a" "-Wl,-force_load" "-Wl,/var/folders/kz/_y_vgl6505v0hgx16pt1vdsr0000gn/T/lumenjlWdJh/libliblumen_otp.rlib" "-lc" "-lSystem" "-lresolv"

Undefined symbols for architecture x86_64:
  "core::fmt::ArgumentV1::new::h54434a16422be1f8", referenced from:
      core::num::dec2flt::rawfp::fp_to_float::hcfcb4eee27eb90e9 in libliblumen_otp.rlib(liblumen_otp-f72099be146a6d2f.4gu3hlkyr18n6nui.rcgu.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
@KronicDeth KronicDeth added compiler Issues pertaining to the compiler with no specific tag runtime runtime/bifs labels Aug 9, 2020
@KronicDeth KronicDeth added this to the ElixirConf 2020 milestone Aug 9, 2020
@KronicDeth KronicDeth modified the milestones: ElixirConf 2020, In 2020 Sep 3, 2020
@bcardarella bcardarella modified the milestones: In 2020, In 2021 Dec 9, 2020
@bcardarella bcardarella added the help wanted We'd love your help getting this one done! label Apr 7, 2021
@bitwalker bitwalker modified the milestones: In 2021, 2023 Mar 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler Issues pertaining to the compiler with no specific tag help wanted We'd love your help getting this one done! runtime/bifs runtime
Projects
None yet
Development

No branches or pull requests

3 participants