rust-lang / rust-lang/rust

`compiler_builtins` `string.h` functions are not available when using `std` targets with `#![no_std]`

Open
#137,833 15 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-linkage C-bug E-needs-investigation regression-untriaged
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code

The basm-rs project which uses no-std with mem feature for compiler-builtins fails to build on recent nightly. It can be reproduced on nightly-2025-02-28 on Windows x64 and Linux x64 by the following:

git clone https://github.com/boj-rs/basm-rs.git
cd basm-rs
git reset --hard 2e3799d
cargo run

The following PR seems relevant: https://github.com/rust-lang/rust/pull/135501 (Inject compiler_builtins during postprocessing and ensure it is made private)

Although not sure, I suspect this might be due to the internal changes by the above PR making the mem feature ignored on the compiler-builtins crate.

Adding/removing compiler-builtins with mem feature enabled (on Cargo.toml) doesn't alleviate the issue.

I expected to see this happen: build should succeed

Instead, this happened: build fails with linker error (unresolved external symbols, LNK2001 and LNK2019 on memcpy, memset, strlen, etc.)

Linker error on Windows x64
error: linking with `link.exe` failed: exit code: 1120
  |
  = note: \"C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Tools\\MSVC\\14.43.34808\\bin\\HostX64\\x64\\link.exe\" \"/DEF:C:\\Users\\UNNER~1\\AppData\\Local\\Temp\\ustcw0AdYp\\lib.def\" \"/NOLOGO\" \"C:\\Users\\UNNER~1\\AppData\\Local\\Temp\\ustcw0AdYp\\symbols.o\" \"<20 object files omitted>\" \"D:\\a\\basm-rs\\basm-rs\\target\\x86_64-pc-windows-msvc\\debug\\deps/{libbasm_std-e50feab6cac5330a.rlib,libryu-2d7a27dd94711b38.rlib,liblibm-fe7c82a0dfd00cea.rlib}.rlib\" \"<sysroot>\\lib\\ustlib\\x86_64-pc-windows-msvc\\lib/{liballoc-*,librustc_std_workspace_core-*,libcore-*,libcompiler_builtins-*}.rlib\" \"kernel32.lib\" \"/defaultlib:msvcrt\" \"/NXCOMPAT\" \"/OUT:D:\\a\\basm-rs\\basm-rs\\target\\x86_64-pc-windows-msvc\\debug\\deps\\basm.exe\" \"/OPT:NOREF,NOICF\" \"/DEBUG\" \"/PDBALTPATH:%_PDB%\" \"/NATVIS:<sysroot>\\lib\\ustlib\\etc\\intrinsic.natvis\" \"/NATVIS:<sysroot>\\lib\\ustlib\\etc\\liballoc.natvis\" \"/NATVIS:<sysroot>\\lib\\ustlib\\etc\\libcore.natvis\" \"/NATVIS:<sysroot>\\lib\\ustlib\\etc\\libstd.natvis\" \"/SUBSYSTEM:CONSOLE\" \"/NODEFAULTLIB\" \"/DYNAMICBASE\" \"/ENTRY:_basm_start\" \"/NXCOMPAT:NO\" \"/STACK:268435456\" \"/EMITTOOLVERSIONINFO:NO\" \"/EMITPOGOPHASEINFO\"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: LINK : warning LNK4216: Exported entry point _basm_start
             Creating library D:\a\basm-rs\basm-rs\target\x86_64-pc-windows-msvc\debug\deps\basm.lib and object D:\a\basm-rs\basm-rs\target\x86_64-pc-windows-msvc\debug\deps\basm.exp
          libbasm_std-e50feab6cac5330a.rlib(basm_std-e50feab6cac5330a.2d78w7yq39aio618eu29n502q.rcgu.o) : error LNK2001: unresolved external symbol memset
          libbasm_std-e50feab6cac5330a.rlib(basm_std-e50feab6cac5330a.8mxgkpuy6eljjccapmv5glh9y.rcgu.o) : error LNK2001: unresolved external symbol memset
          libbasm_std-e50feab6cac5330a.rlib(basm_std-e50feab6cac5330a.2e9hbj5zjzej5yoo4fu21vxtv.rcgu.o) : error LNK2001: unresolved external symbol memset
          libcore-b522dd968c06714e.rlib(core-b522dd968c06714e.core.edc02a3bf6895602-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol memset
          basm.9g5xzwdjyxd5pguzsqqvp1u28.rcgu.o : error LNK2001: unresolved external symbol memset
          basm.ej25b0acf8kdeqne13ab4e3tg.rcgu.o : error LNK2001: unresolved external symbol memset
          libbasm_std-e50feab6cac5330a.rlib(basm_std-e50feab6cac5330a.21coi540lkxfaa98dxwpief3l.rcgu.o) : error LNK2001: unresolved external symbol memset
          libbasm_std-e50feab6cac5330a.rlib(basm_std-e50feab6cac5330a.6hgz425wf1ayywi5fv5zoeppv.rcgu.o) : error LNK2001: unresolved external symbol memset
          liballoc-e4bc1996f9879934.rlib(alloc-e4bc1996f9879934.alloc.e6877761d14c58d1-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol memcpy
          libcore-b522dd968c06714e.rlib(core-b522dd968c06714e.core.edc02a3bf6895602-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol memcpy
          libbasm_std-e50feab6cac5330a.rlib(basm_std-e50feab6cac5330a.5zm4u3b7fw5pph8duhnwpp6sy.rcgu.o) : error LNK2001: unresolved external symbol memcpy
          libbasm_std-e50feab6cac5330a.rlib(basm_std-e50feab6cac5330a.2e9hbj5zjzej5yoo4fu21vxtv.rcgu.o) : error LNK2001: unresolved external symbol memcpy
          libbasm_std-e50feab6cac5330a.rlib(basm_std-e50feab6cac5330a.clqiejq8kje9m36l2phy1w3p7.rcgu.o) : error LNK2001: unresolved external symbol memcpy
          libbasm_std-e50feab6cac5330a.rlib(basm_std-e50feab6cac5330a.3vz9srzewsp7rhgzgwnlscjyp.rcgu.o) : error LNK2001: unresolved external symbol memcpy
          libbasm_std-e50feab6cac5330a.rlib(basm_std-e50feab6cac5330a.4a4k385dn4e64jekc5mql1bvs.rcgu.o) : error LNK2001: unresolved external symbol memcpy
          libbasm_std-e50feab6cac5330a.rlib(basm_std-e50feab6cac5330a.1bhgywgafx4gek4bizurc869q.rcgu.o) : error LNK2001: unresolved external symbol memcpy
          libbasm_std-e50feab6cac5330a.rlib(basm_std-e50feab6cac5330a.8mxgkpuy6eljjccapmv5glh9y.rcgu.o) : error LNK2001: unresolved external symbol memcpy
          libbasm_std-e50feab6cac5330a.rlib(basm_std-e50feab6cac5330a.4mpf37xghynf3g95v9jum0jua.rcgu.o) : error LNK2001: unresolved external symbol memcpy
          libbasm_std-e50feab6cac5330a.rlib(basm_std-e50feab6cac5330a.2d78w7yq39aio618eu29n502q.rcgu.o) : error LNK2001: unresolved external symbol memcpy
          libbasm_std-e50feab6cac5330a.rlib(basm_std-e50feab6cac5330a.bxi98gwkuewj2h7gu80p7ilhj.rcgu.o) : error LNK2001: unresolved external symbol memcpy
          libbasm_std-e50feab6cac5330a.rlib(basm_std-e50feab6cac5330a.13w32kxokxkxyhh2n5kpvrakm.rcgu.o) : error LNK2001: unresolved external symbol memcpy
          libbasm_std-e50feab6cac5330a.rlib(basm_std-e50feab6cac5330a.1jxwkrjvpwz2q2r6atshltkax.rcgu.o) : error LNK2001: unresolved external symbol memcpy
          libbasm_std-e50feab6cac5330a.rlib(basm_std-e50feab6cac5330a.21coi540lkxfaa98dxwpief3l.rcgu.o) : error LNK2001: unresolved external symbol memcpy
          libbasm_std-e50feab6cac5330a.rlib(basm_std-e50feab6cac5330a.7w49ql5si9b0bo5czy3vd3fp6.rcgu.o) : error LNK2001: unresolved external symbol memcpy
          libbasm_std-e50feab6cac5330a.rlib(basm_std-e50feab6cac5330a.05gcffme57m7trw63ywnai9vp.rcgu.o) : error LNK2001: unresolved external symbol memcpy
          libbasm_std-e50feab6cac5330a.rlib(basm_std-e50feab6cac5330a.6hgz425wf1ayywi5fv5zoeppv.rcgu.o) : error LNK2001: unresolved external symbol memcpy
          basm.9g5xzwdjyxd5pguzsqqvp1u28.rcgu.o : error LNK2001: unresolved external symbol memcpy
          basm.cmnxgaonqn55yzn8blh7dmqx0.rcgu.o : error LNK2001: unresolved external symbol memcpy
          basm.ej25b0acf8kdeqne13ab4e3tg.rcgu.o : error LNK2001: unresolved external symbol memcpy
          libbasm_std-e50feab6cac5330a.rlib(basm_std-e50feab6cac5330a.d039nxxqg81e8ll6x542f66xx.rcgu.o) : error LNK2001: unresolved external symbol memcpy
          libbasm_std-e50feab6cac5330a.rlib(basm_std-e50feab6cac5330a.4a4k385dn4e64jekc5mql1bvs.rcgu.o) : error LNK2019: unresolved external symbol memmove referenced in function _ZN5alloc11collections9vec_deque21VecDeque$LT$T$C$A$GT$24handle_capacity_increase17h8b4f648ad63441e0E
          liballoc-e4bc1996f9879934.rlib(alloc-e4bc1996f9879934.alloc.e6877761d14c58d1-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol memmove
          liballoc-e4bc1996f9879934.rlib(alloc-e4bc1996f9879934.alloc.e6877761d14c58d1-cgu.0.rcgu.o) : error LNK2019: unresolved external symbol strlen referenced in function _ZN5alloc3ffi5c_str7CString8from_raw17h6b22e763d8c0a09cE
          libcore-b522dd968c06714e.rlib(core-b522dd968c06714e.core.edc02a3bf6895602-cgu.0.rcgu.o) : error LNK2019: unresolved external symbol memcmp referenced in function _ZN4core3str7pattern11StrSearcher3new17h9aededd987e99d14E
          D:\a\basm-rs\basm-rs\target\x86_64-pc-windows-msvc\debug\deps\basm.exe : fatal error LNK1120: 5 unresolved externals
Linker error on Linux x64
error: linking with `cc` failed: exit status: 1
  |
  = note:  \"cc\" \"-Wl,--version-script=/tmp/rustclFz4Fk/list\" \"-Wl,--no-undefined-version\" \"-m64\" \"/tmp/rustclFz4Fk/symbols.o\" \"<20 object files omitted>\" \"-Wl,--as-needed\" \"-Wl,-Bstatic\" \"/home/runner/work/basm-rs/basm-rs/target/x86_64-unknown-linux-gnu/debug/deps/{libbasm_std-1acb57257a97f135.rlib,libryu-bd5489fc747e1497.rlib,liblibm-5e8cfbe847b175e2.rlib}.rlib\" \"<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib/{liballoc-*,librustc_std_workspace_core-*,libcore-*,libcompiler_builtins-*}.rlib\" \"-Wl,-Bdynamic\" \"-B<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/bin/gcc-ld\" \"-fuse-ld=lld\" \"-Wl,--eh-frame-hdr\" \"-Wl,-z,noexecstack\" \"-L\" \"<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib\" \"-o\" \"/home/runner/work/basm-rs/basm-rs/target/x86_64-unknown-linux-gnu/debug/deps/basm-65a3de73172c3759\" \"-Wl,--no-gc-sections\" \"-pie\" \"-Wl,-z,relro,-z,now\" \"-nodefaultlibs\" \"-nostartfiles\" \"-nostdlib\" \"-static-pie\" \"-fno-exceptions\" \"-fno-asynchronous-unwind-tables\" \"-fno-unwind-tables\" \"-fno-stack-protector\" \"-fno-plt\" \"-Wl,--entry=_basm_start,--build-id=none,--gc-sections,--export-dynamic,--no-eh-frame-hdr,-z,norelro\"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: rust-lld: error: undefined symbol: memset
          >>> referenced by writer.rs:116 (basm-std/src/platform/io/writer.rs:116)
          >>>               /home/runner/work/basm-rs/basm-rs/target/x86_64-unknown-linux-gnu/debug/deps/basm-65a3de73172c3759.6h36ab66ebuo091kns7g1lspd.rcgu.o:(basm_std::platform::io::writer::Writer$LT$_$GT$::new::h5e1d045719356f57)
          >>> referenced by writer.rs:302 (basm-std/src/platform/io/writer.rs:302)
          >>>               /home/runner/work/basm-rs/basm-rs/target/x86_64-unknown-linux-gnu/debug/deps/basm-65a3de73172c3759.6h36ab66ebuo091kns7g1lspd.rcgu.o:(basm_std::platform::io::writer::Writer$LT$_$GT$::u64::h40db478c2d0af0ea)
          >>> referenced by writer.rs:303 (basm-std/src/platform/io/writer.rs:303)
          >>>               /home/runner/work/basm-rs/basm-rs/target/x86_64-unknown-linux-gnu/debug/deps/basm-65a3de73172c3759.6h36ab66ebuo091kns7g1lspd.rcgu.o:(basm_std::platform::io::writer::Writer$LT$_$GT$::u64::h40db478c2d0af0ea)
          >>> referenced 5 more times
          
          rust-lld: error: undefined symbol: memcpy
          >>> referenced by writer.rs:115 (basm-std/src/platform/io/writer.rs:115)
          >>>               /home/runner/work/basm-rs/basm-rs/target/x86_64-unknown-linux-gnu/debug/deps/basm-65a3de73172c3759.6h36ab66ebuo091kns7g1lspd.rcgu.o:(basm_std::platform::io::writer::Writer$LT$_$GT$::new::h5e1d045719356f57)
          >>> referenced by mod.rs:3594 (/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/intrinsics/mod.rs:3594)
          >>>               basm_std-1acb57257a97f135.5gkonddl664c9rz6m85dkzhrb.rcgu.o:(alloc::vec::Vec$LT$T$C$A$GT$::append_elements::h074461469b673f76) in archive /home/runner/work/basm-rs/basm-rs/target/x86_64-unknown-linux-gnu/debug/deps/libbasm_std-1acb57257a97f135.rlib
          >>> referenced by mod.rs:3594 (/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/intrinsics/mod.rs:3594)
          >>>               basm_std-1acb57257a97f135.8ju6k4gh4r2sxl5p2ta3jlwdn.rcgu.o:(alloc::alloc::Global::grow_impl::h17fbfe5bd8679995) in archive /home/runner/work/basm-rs/basm-rs/target/x86_64-unknown-linux-gnu/debug/deps/libbasm_std-1acb57257a97f135.rlib
          >>> referenced 13 more times
          collect2: error: ld returned 1 exit status
Version it worked on

It most recently worked on: nightly-2025-02-23

Version with regression

rustc --version --verbose:

rustc 1.87.0-nightly (287487624 2025-02-28)
binary: rustc
commit-hash: 287487624357c19b22d27aa3ed584b8ccd080b4d
commit-date: 2025-02-28
host: x86_64-pc-windows-msvc
release: 1.87.0-nightly
LLVM version: 20.1.0
Output of cargo-bisect-rustc

searched nightlies: from nightly-2025-02-20 to nightly-2025-02-28
regressed nightly: nightly-2025-02-24
searched commit range: https://github.com/rust-lang/rust/compare/46420c96070b4c4bd8242f16d5806b8f26a57016...f8a913b1381e90379c7ca63ac2b88b9518936628
regressed commit: https://github.com/rust-lang/rust/commit/bca5f37cbded0db8d37414bb08c4b101a5f26d36

bisected with cargo-bisect-rustc v0.6.7

Host triple: x86_64-pc-windows-msvc
Reproduce with:

cargo bisect-rustc --end=2025-02-28

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with the basm-rs commit 2e3799d using nightly-2025-02-28 and cargo run on a std target with #![no_std]. Start by reviewing PR 135501 and the compiler_builtins postprocessing and mem-feature behavior. Done means the example links successfully on the reported Linux and Windows targets with the string functions available.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.