Skip to content

Latest nightly are failing to build non-toy projects at linking stage when using LTO optimization #108853

Closed
@dbachelot

Description

@dbachelot

After updating to the latest version of Rust, I found that many of my projects are failing to compile at linking stage when doing size-optimized builds (cf. https://github.com/johnthagen/min-sized-rust). I found the possible nightly-to-nightly regression to be from nightly-2023-02-27 to nightly-2023-02-28. This seems to be a real issue since min-sized builds are widely used. Also I failed to reproduce this in a toy project.

To trigger that "bug" I used these compiler flags:

OPTI_FLAGS="-C link-dead-code=n -C lto=fat -C opt-level=z -C embed-bitcode=yes -C panic=abort"
OPTI_ARGS="-Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort"

# for linux you might want to use -C panic=abort to overpass another bug

RUSTFLAGS=$OPTI_FLAGS cargo +nightly build --target x86_64-unknown-linux-gnu --release $OPTI_ARGS
RUSTFLAGS=$OPTI_FLAGS XWIN_ARCH="x86_64" XWIN_CACHE_DIR="/tmp/xwin_64" cargo +nightly xwin build --target x86_64-pc-windows-msvc --release $OPTI_ARGS

Possible linked issues:

I tried to build those projects with the latest working nightly (nightly-2023-02-27) and the first non-working nightly (nightly-2023-02-28):

I expected to see this happen: build succeed in both cases.

Instead, this happened: linker errors on the first non-working nightly (nightly-2023-02-28) and compile success with the latest working nightly (nightly-2023-02-27). This show a possible regression.

For RustHound (using nightly-2023-02-28):

Compile error

   Compiling rusthound v1.1.62 (/$USER/Projets/XXX/RustHound)
error: linking with `lld-link` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/$USER/.rustup/toolchains/nightly-2023-02-28-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/$USER/.vscode-server/bin/441438abd1ac652551dbe4d408dfcec8a499b8bf/bin/remote-cli:/$USER/.local/bin:/$USER/.cargo/bin:/$USER/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/tmp" VSLANG="1033" "lld-link" "-flavor" "link" "/NOLOGO" "/tmp/rustcAWOQqQ/symbols.o" "/$USER/Projets/XXX/RustHound/target/x86_64-pc-windows-msvc/release/deps/rusthound.rusthound.4bfd0cff-cgu.3.rcgu.o" "/LIBPATH:/$USER/Projets/XXX/RustHound/target/x86_64-pc-windows-msvc/release/deps" "/LIBPATH:/$USER/Projets/XXX/RustHound/target/release/deps" "/LIBPATH:/tmp/xwin_64/crt/lib/x86_64" "/LIBPATH:/tmp/xwin_64/sdk/lib/um/x86_64" "/LIBPATH:/tmp/xwin_64/sdk/lib/ucrt/x86_64" "/LIBPATH:/$USER/.cargo/registry/src/github.com-1ecc6299db9ec823/windows_x86_64_msvc-0.42.1/lib" "/LIBPATH:/$USER/.cargo/registry/src/github.com-1ecc6299db9ec823/windows_x86_64_msvc-0.34.0/lib" "/LIBPATH:/$USER/Projets/XXX/RustHound/target/x86_64-pc-windows-msvc/release/build/ring-175a80523169bc78/out" "/LIBPATH:/$USER/.rustup/toolchains/nightly-2023-02-28-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-msvc/lib" "/tmp/rustcAWOQqQ/libring-98a43d4a731d3bc1.rlib" "/$USER/Projets/XXX/RustHound/target/x86_64-pc-windows-msvc/release/deps/libcompiler_builtins-a57aa224b6747535.rlib" "windows.lib" "windows.lib" "iphlpapi.lib" "bcrypt.lib" "ntdll.lib" "windows.lib" "advapi32.lib" "cfgmgr32.lib" "credui.lib" "fwpuclnt.lib" "gdi32.lib" "kernel32.lib" "msimg32.lib" "ntdll.lib" "ole32.lib" "opengl32.lib" "runtimeobject.lib" "secur32.lib" "user32.lib" "winspool.lib" "ws2_32.lib" "kernel32.lib" "advapi32.lib" "userenv.lib" "kernel32.lib" "ws2_32.lib" "bcrypt.lib" "msvcrt.lib" "legacy_stdio_definitions.lib" "/NXCOMPAT" "/LIBPATH:/$USER/.rustup/toolchains/nightly-2023-02-28-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-msvc/lib" "/OUT:/$USER/Projets/XXX/RustHound/target/x86_64-pc-windows-msvc/release/deps/rusthound.exe" "/OPT:REF,ICF" "/DEBUG"
  = note: lld-link: error: undefined symbol: _$LT$T$u20$as$u20$core..convert..TryInto$LT$U$GT$$GT$::try_into::ha70d088502189c5c
          >>> referenced by libcompiler_builtins-a57aa224b6747535.rlib(compiler_builtins-a57aa224b6747535.compiler_builtins.08706f9d-cgu.3.rcgu.o):(_$LT$u8$u20$as$u20$compiler_builtins..int..Int$GT$::wrapping_shl::h75be24e30ae66717)
          >>> referenced by libcompiler_builtins-a57aa224b6747535.rlib(compiler_builtins-a57aa224b6747535.compiler_builtins.08706f9d-cgu.3.rcgu.o):(_$LT$u8$u20$as$u20$compiler_builtins..int..Int$GT$::logical_shr::h2923ea1dd2188a7b)
          
          lld-link: error: undefined symbol: _$LT$T$u20$as$u20$core..convert..TryInto$LT$U$GT$$GT$::try_into::h3facc516142b808f
          >>> referenced by libcompiler_builtins-a57aa224b6747535.rlib(compiler_builtins-a57aa224b6747535.compiler_builtins.08706f9d-cgu.3.rcgu.o):(_$LT$u16$u20$as$u20$compiler_builtins..int..Int$GT$::wrapping_shl::hc9f2c5447bea3c19)
          >>> referenced by libcompiler_builtins-a57aa224b6747535.rlib(compiler_builtins-a57aa224b6747535.compiler_builtins.08706f9d-cgu.3.rcgu.o):(_$LT$u16$u20$as$u20$compiler_builtins..int..Int$GT$::logical_shr::ha0c8059f27d2ee43)
          
          lld-link: error: undefined symbol: _$LT$T$u20$as$u20$core..convert..TryInto$LT$U$GT$$GT$::try_into::hc3c814c714409716
          >>> referenced by libcompiler_builtins-a57aa224b6747535.rlib(compiler_builtins-a57aa224b6747535.compiler_builtins.08706f9d-cgu.3.rcgu.o):(_$LT$u32$u20$as$u20$compiler_builtins..int..Int$GT$::wrapping_shl::h5da56a5404567510)
          >>> referenced by libcompiler_builtins-a57aa224b6747535.rlib(compiler_builtins-a57aa224b6747535.compiler_builtins.08706f9d-cgu.3.rcgu.o):(_$LT$u32$u20$as$u20$compiler_builtins..int..Int$GT$::logical_shr::he654838393c6dac6)
          >>> referenced by libcompiler_builtins-a57aa224b6747535.rlib(compiler_builtins-a57aa224b6747535.compiler_builtins.08706f9d-cgu.7.rcgu.o):(compiler_builtins::int::specialized_div_rem::u32_div_rem::hb22b2448b8f01ed2)
          

error: could not compile `rusthound` due to previous error

For RustScan (using nightly-2023-02-28):

Compile error

   Compiling rustscan v2.1.1 (/$USER/Projets/XXX/RustScan)
error: linking with `lld-link` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/$USER/.rustup/toolchains/nightly-2023-02-28-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/$USER/.vscode-server/bin/441438abd1ac652551dbe4d408dfcec8a499b8bf/bin/remote-cli:/$USER/.local/bin:/$USER/.cargo/bin:/$USER/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/tmp" VSLANG="1033" "lld-link" "-flavor" "link" "/NOLOGO" "/tmp/rustcMAAVJR/symbols.o" "/$USER/Projets/XXX/RustScan/target/x86_64-pc-windows-msvc/release/deps/rustscan.rustscan.2fa56812-cgu.0.rcgu.o" "/LIBPATH:/$USER/Projets/XXX/RustScan/target/x86_64-pc-windows-msvc/release/deps" "/LIBPATH:/$USER/Projets/XXX/RustScan/target/release/deps" "/LIBPATH:/tmp/xwin_64/crt/lib/x86_64" "/LIBPATH:/tmp/xwin_64/sdk/lib/um/x86_64" "/LIBPATH:/tmp/xwin_64/sdk/lib/ucrt/x86_64" "/LIBPATH:/$USER/Projets/XXX/RustScan/target/x86_64-pc-windows-msvc/release/build/wepoll-ffi-719df429f6c384f7/out" "/LIBPATH:/$USER/.cargo/registry/src/github.com-1ecc6299db9ec823/windows_x86_64_msvc-0.42.0/lib" "/LIBPATH:/$USER/Projets/XXX/RustScan/target/x86_64-pc-windows-msvc/release/build/ring-a690ee922a6572a9/out" "/LIBPATH:/$USER/.rustup/toolchains/nightly-2023-02-28-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-msvc/lib" "/tmp/rustcMAAVJR/libring-188f86f2fd8f068a.rlib" "/tmp/rustcMAAVJR/libwepoll_ffi-48d31142813b117f.rlib" "/$USER/Projets/XXX/RustScan/target/x86_64-pc-windows-msvc/release/deps/libcompiler_builtins-18ed03317118022b.rlib" "iphlpapi.lib" "bcrypt.lib" "ntdll.lib" "windows.lib" "advapi32.lib" "advapi32.lib" "cfgmgr32.lib" "credui.lib" "fwpuclnt.lib" "gdi32.lib" "kernel32.lib" "msimg32.lib" "ntdll.lib" "ole32.lib" "opengl32.lib" "secur32.lib" "shell32.lib" "synchronization.lib" "user32.lib" "winspool.lib" "ws2_32.lib" "kernel32.lib" "advapi32.lib" "userenv.lib" "kernel32.lib" "ws2_32.lib" "bcrypt.lib" "msvcrt.lib" "legacy_stdio_definitions.lib" "/NXCOMPAT" "/LIBPATH:/$USER/.rustup/toolchains/nightly-2023-02-28-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-msvc/lib" "/OUT:/$USER/Projets/XXX/RustScan/target/x86_64-pc-windows-msvc/release/deps/rustscan.exe" "/OPT:REF,ICF" "/DEBUG"
  = note: lld-link: error: undefined symbol: _$LT$T$u20$as$u20$core..convert..TryInto$LT$U$GT$$GT$::try_into::hf83a56f591ad91c2
          >>> referenced by libcompiler_builtins-18ed03317118022b.rlib(compiler_builtins-18ed03317118022b.compiler_builtins.c902bbf6-cgu.3.rcgu.o):(_$LT$u8$u20$as$u20$compiler_builtins..int..Int$GT$::wrapping_shl::he7ed35977b0d0fac)
          >>> referenced by libcompiler_builtins-18ed03317118022b.rlib(compiler_builtins-18ed03317118022b.compiler_builtins.c902bbf6-cgu.3.rcgu.o):(_$LT$u8$u20$as$u20$compiler_builtins..int..Int$GT$::logical_shr::h00538ae7c426f37f)
          
          lld-link: error: undefined symbol: _$LT$T$u20$as$u20$core..convert..TryInto$LT$U$GT$$GT$::try_into::hae711d779ec4e591
          >>> referenced by libcompiler_builtins-18ed03317118022b.rlib(compiler_builtins-18ed03317118022b.compiler_builtins.c902bbf6-cgu.3.rcgu.o):(_$LT$u16$u20$as$u20$compiler_builtins..int..Int$GT$::wrapping_shl::h659e210b754e206f)
          >>> referenced by libcompiler_builtins-18ed03317118022b.rlib(compiler_builtins-18ed03317118022b.compiler_builtins.c902bbf6-cgu.3.rcgu.o):(_$LT$u16$u20$as$u20$compiler_builtins..int..Int$GT$::logical_shr::h970afb9c096c3a26)
          
          lld-link: error: undefined symbol: _$LT$T$u20$as$u20$core..convert..TryInto$LT$U$GT$$GT$::try_into::h183171ab1b2751dc
          >>> referenced by libcompiler_builtins-18ed03317118022b.rlib(compiler_builtins-18ed03317118022b.compiler_builtins.c902bbf6-cgu.3.rcgu.o):(_$LT$u32$u20$as$u20$compiler_builtins..int..Int$GT$::wrapping_shl::h6c6b22f19a38a7e4)
          >>> referenced by libcompiler_builtins-18ed03317118022b.rlib(compiler_builtins-18ed03317118022b.compiler_builtins.c902bbf6-cgu.3.rcgu.o):(_$LT$u32$u20$as$u20$compiler_builtins..int..Int$GT$::logical_shr::hb512d2478bac3150)
          >>> referenced by libcompiler_builtins-18ed03317118022b.rlib(compiler_builtins-18ed03317118022b.compiler_builtins.c902bbf6-cgu.7.rcgu.o):(compiler_builtins::int::specialized_div_rem::u32_div_rem::h4103159706e15559)
          

error: could not compile `rustscan` due to previous error

For Helix (using nightly-2023-02-28):

Compile error

   Compiling helix-tui v0.6.0 (/$USER/Projets/XXX/Helix/helix-tui)
error: linking with `lld-link` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/$USER/.rustup/toolchains/nightly-2023-02-28-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/$USER/.vscode-server/bin/441438abd1ac652551dbe4d408dfcec8a499b8bf/bin/remote-cli:/$USER/.local/bin:/$USER/.cargo/bin:/$USER/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/tmp" VSLANG="1033" "lld-link" "-flavor" "link" "/NOLOGO" "/tmp/rustcIC5pT0/symbols.o" "/$USER/Projets/XXX/Helix/target/x86_64-pc-windows-msvc/release/deps/hx.hx.97f34d47-cgu.12.rcgu.o" "/LIBPATH:/$USER/Projets/XXX/Helix/target/x86_64-pc-windows-msvc/release/deps" "/LIBPATH:/$USER/Projets/XXX/Helix/target/release/deps" "/LIBPATH:/tmp/xwin_64/crt/lib/x86_64" "/LIBPATH:/tmp/xwin_64/sdk/lib/um/x86_64" "/LIBPATH:/tmp/xwin_64/sdk/lib/ucrt/x86_64" "/LIBPATH:/$USER/.cargo/registry/src/github.com-1ecc6299db9ec823/windows_x86_64_msvc-0.42.1/lib" "/LIBPATH:/$USER/Projets/XXX/Helix/target/x86_64-pc-windows-msvc/release/build/tree-sitter-2a9907837c51abd5/out" "/LIBPATH:/$USER/.rustup/toolchains/nightly-2023-02-28-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-msvc/lib" "/tmp/rustcIC5pT0/libtree_sitter-846e7dfbf9fccdfd.rlib" "/$USER/Projets/XXX/Helix/target/x86_64-pc-windows-msvc/release/deps/libcompiler_builtins-15b4049fca2c0d34.rlib" "windows.lib" "ntdll.lib" "legacy_stdio_definitions.lib" "windows.lib" "kernel32.lib" "advapi32.lib" "ole32.lib" "oleaut32.lib" "bcrypt.lib" "windows.lib" "advapi32.lib" "cfgmgr32.lib" "fwpuclnt.lib" "gdi32.lib" "kernel32.lib" "msimg32.lib" "ntdll.lib" "ole32.lib" "opengl32.lib" "runtimeobject.lib" "shell32.lib" "shlwapi.lib" "synchronization.lib" "user32.lib" "winspool.lib" "ws2_32.lib" "kernel32.lib" "advapi32.lib" "userenv.lib" "kernel32.lib" "ws2_32.lib" "bcrypt.lib" "msvcrt.lib" "legacy_stdio_definitions.lib" "/NXCOMPAT" "/LIBPATH:/$USER/.rustup/toolchains/nightly-2023-02-28-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-msvc/lib" "/OUT:/$USER/Projets/XXX/Helix/target/x86_64-pc-windows-msvc/release/deps/hx.exe" "/OPT:REF,ICF" "/DEBUG"
  = note: lld-link: error: undefined symbol: _$LT$T$u20$as$u20$core..convert..TryInto$LT$U$GT$$GT$::try_into::hc27fcf92225fa76d
          >>> referenced by libcompiler_builtins-15b4049fca2c0d34.rlib(compiler_builtins-15b4049fca2c0d34.compiler_builtins.b4f7fc22-cgu.3.rcgu.o):(_$LT$u8$u20$as$u20$compiler_builtins..int..Int$GT$::wrapping_shl::hde1da1a440758e53)
          >>> referenced by libcompiler_builtins-15b4049fca2c0d34.rlib(compiler_builtins-15b4049fca2c0d34.compiler_builtins.b4f7fc22-cgu.3.rcgu.o):(_$LT$u8$u20$as$u20$compiler_builtins..int..Int$GT$::logical_shr::h69f3e9a4cec906c3)
          
          lld-link: error: undefined symbol: _$LT$T$u20$as$u20$core..convert..TryInto$LT$U$GT$$GT$::try_into::hc09440a623908dd2
          >>> referenced by libcompiler_builtins-15b4049fca2c0d34.rlib(compiler_builtins-15b4049fca2c0d34.compiler_builtins.b4f7fc22-cgu.3.rcgu.o):(_$LT$u16$u20$as$u20$compiler_builtins..int..Int$GT$::wrapping_shl::h8fa431404ce61bc8)
          >>> referenced by libcompiler_builtins-15b4049fca2c0d34.rlib(compiler_builtins-15b4049fca2c0d34.compiler_builtins.b4f7fc22-cgu.3.rcgu.o):(_$LT$u16$u20$as$u20$compiler_builtins..int..Int$GT$::logical_shr::h66ae3ce6d28d7dc9)
          
          lld-link: error: undefined symbol: _$LT$T$u20$as$u20$core..convert..TryInto$LT$U$GT$$GT$::try_into::hcee917ca27ced0ac
          >>> referenced by libcompiler_builtins-15b4049fca2c0d34.rlib(compiler_builtins-15b4049fca2c0d34.compiler_builtins.b4f7fc22-cgu.3.rcgu.o):(_$LT$u32$u20$as$u20$compiler_builtins..int..Int$GT$::wrapping_shl::h51b6ed721278058c)
          >>> referenced by libcompiler_builtins-15b4049fca2c0d34.rlib(compiler_builtins-15b4049fca2c0d34.compiler_builtins.b4f7fc22-cgu.3.rcgu.o):(_$LT$u32$u20$as$u20$compiler_builtins..int..Int$GT$::logical_shr::h337b670af4036651)
          >>> referenced by libcompiler_builtins-15b4049fca2c0d34.rlib(compiler_builtins-15b4049fca2c0d34.compiler_builtins.b4f7fc22-cgu.7.rcgu.o):(compiler_builtins::int::specialized_div_rem::u32_div_rem::hc40953c0c14b372c)
          

error: could not compile `helix-term` due to previous error

Please note that I used windows cross compilation builds as an example, but same thing can happen with other targets (even when not cross-compiling). Also note that the linking errors can be different regarding the selected target.

After some more tests with Linux (and checking this issue), I found that we need to add -C panic=abort to overpass another linking issue (cf. #107016 (comment)). This doesn't resolve the issue for Windows cross-compilation however.

Activity

tmiasko

tmiasko commented on Mar 7, 2023

@tmiasko
Contributor

A few things you could try:

  1. Use -Csymbol-mangling-version=v0 (for more informative symbol names, not because it will fix the issue in itself).
  2. Build with -Ccodegen-units=1
  3. Add #[inline] annotation to the following function in the core (and then clean & rebuild)
    fn try_from(value: U) -> Result<Self, Self::Error> {
    Ok(U::into(value))
    }

If the last suggestion helps, please mention this in rust-lang/compiler-builtins#491.

dbachelot

dbachelot commented on Mar 7, 2023

@dbachelot
Author

I tested 1&2 and got:

Compile error

   Compiling rustscan v2.1.1 (/home/$USER/Projets/XXX/RustScan)
error: linking with `lld-link` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/home/$USER/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/$USER/.vscode-server/bin/441438abd1ac652551dbe4d408dfcec8a499b8bf/bin/remote-cli:/home/$USER/.local/bin:/home/$USER/.cargo/bin:/home/$USER/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/tmp" VSLANG="1033" "lld-link" "-flavor" "link" "/NOLOGO" "/tmp/rustc3sx4fq/symbols.o" "/home/$USER/Projets/XXX/RustScan/target/x86_64-pc-windows-msvc/release/deps/rustscan.rustscan.73ae6a84-cgu.0.rcgu.o" "/LIBPATH:/home/$USER/Projets/XXX/RustScan/target/x86_64-pc-windows-msvc/release/deps" "/LIBPATH:/home/$USER/Projets/XXX/RustScan/target/release/deps" "/LIBPATH:/tmp/xwin_64/crt/lib/x86_64" "/LIBPATH:/tmp/xwin_64/sdk/lib/um/x86_64" "/LIBPATH:/tmp/xwin_64/sdk/lib/ucrt/x86_64" "/LIBPATH:/home/$USER/Projets/XXX/RustScan/target/x86_64-pc-windows-msvc/release/build/wepoll-ffi-719df429f6c384f7/out" "/LIBPATH:/home/$USER/.cargo/registry/src/github.com-1ecc6299db9ec823/windows_x86_64_msvc-0.42.0/lib" "/LIBPATH:/home/$USER/Projets/XXX/RustScan/target/x86_64-pc-windows-msvc/release/build/ring-a690ee922a6572a9/out" "/LIBPATH:/home/$USER/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-msvc/lib" "/tmp/rustc3sx4fq/libring-7aca1892b1101c44.rlib" "/tmp/rustc3sx4fq/libwepoll_ffi-b138a1eba95895ba.rlib" "/home/$USER/Projets/XXX/RustScan/target/x86_64-pc-windows-msvc/release/deps/libcompiler_builtins-83400d04a98abbd8.rlib" "iphlpapi.lib" "bcrypt.lib" "ntdll.lib" "windows.lib" "advapi32.lib" "advapi32.lib" "cfgmgr32.lib" "credui.lib" "fwpuclnt.lib" "gdi32.lib" "kernel32.lib" "msimg32.lib" "ntdll.lib" "ole32.lib" "opengl32.lib" "secur32.lib" "shell32.lib" "synchronization.lib" "user32.lib" "winspool.lib" "ws2_32.lib" "kernel32.lib" "advapi32.lib" "userenv.lib" "kernel32.lib" "ws2_32.lib" "bcrypt.lib" "msvcrt.lib" "legacy_stdio_definitions.lib" "/NXCOMPAT" "/LIBPATH:/home/$USER/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-msvc/lib" "/OUT:/home/$USER/Projets/XXX/RustScan/target/x86_64-pc-windows-msvc/release/deps/rustscan.exe" "/OPT:REF,ICF" "/DEBUG"
  = note: lld-link: error: undefined symbol: <u32 as core::convert::TryInto<u32>>::try_into
          >>> referenced by libcompiler_builtins-83400d04a98abbd8.rlib(compiler_builtins-83400d04a98abbd8.compiler_builtins.2da580f8-cgu.0.rcgu.o):(compiler_builtins::int::specialized_div_rem::u32_div_rem)
          >>> referenced by libcompiler_builtins-83400d04a98abbd8.rlib(compiler_builtins-83400d04a98abbd8.compiler_builtins.2da580f8-cgu.0.rcgu.o):(<i32 as compiler_builtins::int::Int>::logical_shr)
          >>> referenced by libcompiler_builtins-83400d04a98abbd8.rlib(compiler_builtins-83400d04a98abbd8.compiler_builtins.2da580f8-cgu.0.rcgu.o):(<u32 as compiler_builtins::int::Int>::wrapping_shl)
          
          lld-link: error: undefined symbol: <u32 as core::convert::TryInto<u8>>::try_into
          >>> referenced by libcompiler_builtins-83400d04a98abbd8.rlib(compiler_builtins-83400d04a98abbd8.compiler_builtins.2da580f8-cgu.0.rcgu.o):(<i8 as compiler_builtins::int::Int>::logical_shr)
          >>> referenced by libcompiler_builtins-83400d04a98abbd8.rlib(compiler_builtins-83400d04a98abbd8.compiler_builtins.2da580f8-cgu.0.rcgu.o):(<u8 as compiler_builtins::int::Int>::wrapping_shl)
          
          lld-link: error: undefined symbol: <u32 as core::convert::TryInto<u16>>::try_into
          >>> referenced by libcompiler_builtins-83400d04a98abbd8.rlib(compiler_builtins-83400d04a98abbd8.compiler_builtins.2da580f8-cgu.0.rcgu.o):(<i16 as compiler_builtins::int::Int>::logical_shr)
          >>> referenced by libcompiler_builtins-83400d04a98abbd8.rlib(compiler_builtins-83400d04a98abbd8.compiler_builtins.2da580f8-cgu.0.rcgu.o):(<u16 as compiler_builtins::int::Int>::wrapping_shl)
          

error: could not compile `rustscan` due to previous error

(PS: I'm currently testing 3)

dbachelot

dbachelot commented on Mar 7, 2023

@dbachelot
Author

Adding #[inline] on the try_from implementation in core doesn't seem to change anything.

tmiasko

tmiasko commented on Mar 7, 2023

@tmiasko
Contributor

One more suggestion: ensure that -Zshare-generics=off is used when building compiler-builtins (-C opt-level=z implies -Zshare-generics=on, which looks like the root cause of the problem here):

cargo-features = ["profile-rustflags"]

[profile.release.package.compiler_builtins]
rustflags = ["-Zshare-generics=off"]

(Update the profile name as appropriate).

dbachelot

dbachelot commented on Mar 7, 2023

@dbachelot
Author

Thank you, this fix the issue! Is this considered a regression or can we close the issue?

pnkfelix

pnkfelix commented on Mar 7, 2023

@pnkfelix
Member

The fact that we need to use a -Z flag to work around the problem implies that we cannot close the issue. -Z flags aren't available to stable Rust users.

added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Mar 7, 2023
added
regression-untriagedUntriaged performance or correctness regression.
and removed
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Mar 7, 2023
added
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Mar 7, 2023
pnkfelix

pnkfelix commented on Mar 7, 2023

@pnkfelix
Member

Is there a variant of this that demonstrates the problem described here without using any -Z flags at all?

55 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    -Zbuild-stdUnstable Cargo option: Compile the standard library yourself.A-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleP-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-untriagedUntriaged performance or correctness regression.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @pnkfelix@gwilymk@wesleywiser@thomcc@estebank

      Issue actions

        Latest nightly are failing to build non-toy projects at linking stage when using LTO optimization · Issue #108853 · rust-lang/rust