rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
99.01k stars 12.79k forks source link

Linking failed with `f16`: `undefined symbol: __floatuntihf` on Ubuntu 20.04 #132614

Open zhassan-aws opened 3 weeks ago

zhassan-aws commented 3 weeks ago

Problem

I'm getting a linking failure on the following program on an Ubuntu 20.04 with x86_64:

#![feature(f16)]

fn main() {
    let _f = (256u128 + 0) as f16;
}
$ cargo +nightly-2024-11-03 --version --verbose
cargo 1.84.0-nightly (031049782 2024-11-01)
release: 1.84.0-nightly
commit-hash: 0310497822a7a673a330a5dd068b7aaa579a265e
commit-date: 2024-11-01
host: x86_64-unknown-linux-gnu
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.9.0-DEV (sys:0.4.74+curl-8.9.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Ubuntu 20.4.0 (focal) [64-bit]
$ cargo +nightly-2024-11-03 build
   Compiling float_ex v0.1.0 (/home/ubuntu/examples/tmp/float_ex)
error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/home/ubuntu/.rustup/toolchains/nightly-2024-11-03-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/ubuntu/.rustup/toolchains/nightly-2024-11-03-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/self-contained:/home/ubuntu/.vscode-server/cli/servers/Stable-65edc4939843c90c34d61f4ce11704f09d3e5cb6/server/bin/remote-cli:/home/ubuntu/.elan/bin:/home/ubuntu/.opam/4.13.1+options/bin:/home/ubuntu/.local/bin:/home/ubuntu/bin:/home/ubuntu/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/ubuntu/.dotnet/tools:/home/ubuntu/git/aws-viewer-for-cbmc:/home/ubuntu/git/kani/scripts:/home/ubuntu/git/kissat/build:/home/ubuntu/git/cadical/build:/home/ubuntu/git/cryptominisat/build:/home/ubuntu/git/smack-deps/corral:/home/ubuntu/sources/dafny:/home/ubuntu/git/aeneas/charon/bin:/home/ubuntu/git/aeneas/bin:/home/ubuntu/git/aws-viewer-for-cbmc:/home/ubuntu/git/kani/scripts:/home/ubuntu/git/kissat/build:/home/ubuntu/git/cadical/build:/home/ubuntu/git/cryptominisat/build:/home/ubuntu/git/smack-deps/corral:/home/ubuntu/sources/dafny:/home/ubuntu/git/aeneas/charon/bin:/home/ubuntu/git/aeneas/bin" VSLANG="1033" "cc" "-m64" "/tmp/rustcRMryV9/symbols.o" "/home/ubuntu/examples/tmp/float_ex/target/debug/deps/float_ex-554be11968b54f52.1upxk7wgb5be1ozir5i3pcti1.rcgu.o" "/home/ubuntu/examples/tmp/float_ex/target/debug/deps/float_ex-554be11968b54f52.54olmofqxnpy7pq9qy9o2t30g.rcgu.o" "/home/ubuntu/examples/tmp/float_ex/target/debug/deps/float_ex-554be11968b54f52.ch6aaog2yzci5htmyt918ewsf.rcgu.o" "/home/ubuntu/examples/tmp/float_ex/target/debug/deps/float_ex-554be11968b54f52.ci5nx2nl5wy1uyl56j4qhrd42.rcgu.o" "/home/ubuntu/examples/tmp/float_ex/target/debug/deps/float_ex-554be11968b54f52.cs3lb7ej2s3cvd9jn4tnp3blj.rcgu.o" "/home/ubuntu/examples/tmp/float_ex/target/debug/deps/float_ex-554be11968b54f52.626egnrzk7ba7cgmeqeckoth3.rcgu.o" "-Wl,--as-needed" "-Wl,-Bstatic" "/home/ubuntu/.rustup/toolchains/nightly-2024-11-03-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-af54019eb310b9f4.rlib" "/home/ubuntu/.rustup/toolchains/nightly-2024-11-03-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-e370a2465b65d07c.rlib" "/home/ubuntu/.rustup/toolchains/nightly-2024-11-03-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-8f87839a255517a7.rlib" "/home/ubuntu/.rustup/toolchains/nightly-2024-11-03-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-16ad4ab169e45609.rlib" "/home/ubuntu/.rustup/toolchains/nightly-2024-11-03-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-28d1468ba8d7b07b.rlib" "/home/ubuntu/.rustup/toolchains/nightly-2024-11-03-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-fa4f9f6976fb516c.rlib" "/home/ubuntu/.rustup/toolchains/nightly-2024-11-03-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-cbd1d7b1bf5aede2.rlib" "/home/ubuntu/.rustup/toolchains/nightly-2024-11-03-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-f1683a071fd1db0a.rlib" "/home/ubuntu/.rustup/toolchains/nightly-2024-11-03-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-9972421ad1fb0fa7.rlib" "/home/ubuntu/.rustup/toolchains/nightly-2024-11-03-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-dc54626494bdf80e.rlib" "/home/ubuntu/.rustup/toolchains/nightly-2024-11-03-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-b64145080abdbf70.rlib" "/home/ubuntu/.rustup/toolchains/nightly-2024-11-03-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-6b915e9383d4c977.rlib" "/home/ubuntu/.rustup/toolchains/nightly-2024-11-03-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-32ca42ea576f8b75.rlib" "/home/ubuntu/.rustup/toolchains/nightly-2024-11-03-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-1fa702f5e51b232e.rlib" "/home/ubuntu/.rustup/toolchains/nightly-2024-11-03-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-799d520624f8b2e0.rlib" "/home/ubuntu/.rustup/toolchains/nightly-2024-11-03-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-1af26327f6fe922d.rlib" "/home/ubuntu/.rustup/toolchains/nightly-2024-11-03-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-395a38b8e0851c9b.rlib" "/home/ubuntu/.rustup/toolchains/nightly-2024-11-03-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-d453bab70303062c.rlib" "/home/ubuntu/.rustup/toolchains/nightly-2024-11-03-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-9ec1a83853f387f8.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-B/home/ubuntu/.rustup/toolchains/nightly-2024-11-03-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/gcc-ld" "-fuse-ld=lld" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/home/ubuntu/.rustup/toolchains/nightly-2024-11-03-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/ubuntu/examples/tmp/float_ex/target/debug/deps/float_ex-554be11968b54f52" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs"
  = note: rust-lld: error: undefined symbol: __floatuntihf
          >>> referenced by main.rs:0 (src/main.rs:0)
          >>>               /home/ubuntu/examples/tmp/float_ex/target/debug/deps/float_ex-554be11968b54f52.ch6aaog2yzci5htmyt918ewsf.rcgu.o:(float_ex::main::hdd9d458336af3037)
          >>> did you mean: __floatuntidf
          >>> defined in: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libgcc_s.so.1
          collect2: error: ld returned 1 exit status

error: could not compile `float_ex` (bin "float_ex") due to 1 previous error

Steps

No response

Possible Solution(s)

No response

Notes

No response

Version

No response

ehuss commented 3 weeks ago

Transferred to rust-lang/rust, since this is a compiler issue.

tgross35 commented 3 weeks ago

I didn't realize LLVM ever used these symbols, usually it seems to convert to a f32 first then do f32 to f16. This just needs another symbol in compiler-builtins.

tgross35 commented 3 weeks ago

I guess on x86 it will emit assembly for u32 and u64 but u128 gets a libcall https://rust.godbolt.org/z/Yoqzn9o3j. It looks like this symbol is provided by libgcc since https://github.com/gcc-mirror/gcc/commit/5823ef233578d8f6e3770bf92e72c1c977067d13 and this links fine on the playground, maybe Ubuntu 20.04 just didn't enable the symbols.

We should make them available anyway, WIP https://github.com/rust-lang/compiler-builtins/pull/729

tgross35 commented 3 weeks ago

Also just checked the other way, looks like LLVM always does f16 -> f32 conversions and then f32 -> int https://rust.godbolt.org/z/bMTMW3ocT