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

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

Open
zhassan-aws opened this issue Nov 4, 2024 · 4 comments
Open
Assignees
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. F-f16_and_f128 `#![feature(f16)]`, `#![feature(f128)]` requires-nightly This issue requires a nightly compiler in some way. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@zhassan-aws
Copy link

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

@zhassan-aws zhassan-aws added the C-bug Category: This is a bug. label Nov 4, 2024
@ehuss ehuss transferred this issue from rust-lang/cargo Nov 4, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 4, 2024
@ehuss
Copy link
Contributor

ehuss commented Nov 4, 2024

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

@saethlin saethlin added A-linkage Area: linking into static, shared libraries and binaries F-f16_and_f128 `#![feature(f16)]`, `#![feature(f128)]` labels Nov 4, 2024
@tgross35
Copy link
Contributor

tgross35 commented Nov 4, 2024

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 tgross35 self-assigned this Nov 4, 2024
@saethlin saethlin added T-libs Relevant to the library team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Nov 4, 2024
tgross35 added a commit to tgross35/compiler-builtins that referenced this issue Nov 5, 2024
These are not present in LLVM's `compiler-rt` but LLVM does emit them in
some cases [1].

[1]: rust-lang/rust#132614 (comment)
@tgross35
Copy link
Contributor

tgross35 commented Nov 5, 2024

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 gcc-mirror/gcc@5823ef2 and this links fine on the playground, maybe Ubuntu 20.04 just didn't enable the symbols.

We should make them available anyway, WIP rust-lang/compiler-builtins#729

tgross35 added a commit to tgross35/compiler-builtins that referenced this issue Nov 5, 2024
These are not present in LLVM's `compiler-rt` but LLVM does emit them in
some cases [1].

[1]: rust-lang/rust#132614 (comment)
tgross35 added a commit to tgross35/compiler-builtins that referenced this issue Nov 5, 2024
These are not present in LLVM's `compiler-rt` but LLVM does emit them in
some cases [1].

[1]: rust-lang/rust#132614 (comment)
tgross35 added a commit to tgross35/compiler-builtins that referenced this issue Nov 5, 2024
These are not present in LLVM's `compiler-rt` but LLVM does emit them in
some cases [1].

[1]: rust-lang/rust#132614 (comment)
tgross35 added a commit to tgross35/compiler-builtins that referenced this issue Nov 5, 2024
These are not present in LLVM's `compiler-rt` but LLVM does emit them in
some cases [1].

[1]: rust-lang/rust#132614 (comment)
@tgross35
Copy link
Contributor

tgross35 commented Nov 5, 2024

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

tgross35 added a commit to tgross35/compiler-builtins that referenced this issue Nov 5, 2024
These are not present in LLVM's `compiler-rt` but LLVM does emit them in
some cases [1].

[1]: rust-lang/rust#132614 (comment)
tgross35 added a commit to tgross35/compiler-builtins that referenced this issue Nov 5, 2024
These are not present in LLVM's `compiler-rt` but LLVM does emit them in
some cases [1].

[1]: rust-lang/rust#132614 (comment)
tgross35 added a commit to tgross35/compiler-builtins that referenced this issue Nov 5, 2024
These are not present in LLVM's `compiler-rt` but LLVM does emit them in
some cases [1].

[1]: rust-lang/rust#132614 (comment)
@tgross35 tgross35 added the requires-nightly This issue requires a nightly compiler in some way. label Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. F-f16_and_f128 `#![feature(f16)]`, `#![feature(f128)]` requires-nightly This issue requires a nightly compiler in some way. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants