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.

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

    Development

    No branches or pull requests

    Issue actions