Skip to content

Simple for statement can be broken with linker error since nightly-2021-06-10-x86_64-unknown-linux-gnu #87103

Open
@kyasbal

Description

@kyasbal

Minimal reproducible code:

.cargo/config.toml

[build]
target = "x86_64-unknown-linux-gnu"

[profile.release]
panic = "abort"

[profile.dev]
panic = "abort"

[target.x86_64-unknown-linux-gnu]
linker = "rust-lld"

rustflags = [
  "-C", "no-redzone=yes",
  "-C", "relocation-model=static",
  "-C", "link-arg=--entry=KernelMain",
  "-C", "link-arg=--image-base=0x100000",
]

main.rs

#![no_std]
#![no_main]
#![feature(asm)]

use core::panic::PanicInfo;

fn halt() -> ! {
    loop {
      unsafe {
        asm!("hlt");
      }
    }
  }  

#[panic_handler]
fn panic_handler(_: &PanicInfo) -> ! {
    halt()
}


#[no_mangle]
pub extern "C" fn KernelMain(){
    for i in 0..1{

    }
}

These code above would raise following rust-lld error.

error: linking with `rust-lld` failed: exit status: 1
  |
  = note: "rust-lld" "-flavor" "gnu" "/home/kyasbal/workspace/zeros/repro/target/x86_64-unknown-linux-gnu/debug/deps/repro-976c68a0178ccd5f.1npei1tygnhrczdx.rcgu.o" "/home/kyasbal/workspace/zeros/repro/target/x86_64-unknown-linux-gnu/debug/deps/repro-976c68a0178ccd5f.264jhsddzkoxgus6.rcgu.o" "/home/kyasbal/workspace/zeros/repro/target/x86_64-unknown-linux-gnu/debug/deps/repro-976c68a0178ccd5f.2ckrphx4pb0zehup.rcgu.o" "/home/kyasbal/workspace/zeros/repro/target/x86_64-unknown-linux-gnu/debug/deps/repro-976c68a0178ccd5f.2corlzyicc7qnnx6.rcgu.o" "/home/kyasbal/workspace/zeros/repro/target/x86_64-unknown-linux-gnu/debug/deps/repro-976c68a0178ccd5f.4asd3b1yzhfnq5ye.rcgu.o" "/home/kyasbal/workspace/zeros/repro/target/x86_64-unknown-linux-gnu/debug/deps/repro-976c68a0178ccd5f.4ookqi1igbeby3gm.rcgu.o" "/home/kyasbal/workspace/zeros/repro/target/x86_64-unknown-linux-gnu/debug/deps/repro-976c68a0178ccd5f.59t41yohqrdcppo8.rcgu.o" "/home/kyasbal/workspace/zeros/repro/target/x86_64-unknown-linux-gnu/debug/deps/repro-976c68a0178ccd5f.y7uqq33a38kyux3.rcgu.o" "--as-needed" "-L" "/home/kyasbal/workspace/zeros/repro/target/x86_64-unknown-linux-gnu/debug/deps" "-L" "/home/kyasbal/workspace/zeros/repro/target/debug/deps" "-L" "/home/kyasbal/.rustup/toolchains/nightly-2021-06-10-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Bstatic" "/home/kyasbal/.rustup/toolchains/nightly-2021-06-10-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-2588c44e3ecacf72.rlib" "/home/kyasbal/.rustup/toolchains/nightly-2021-06-10-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-c8ded1707ad10767.rlib" "/home/kyasbal/.rustup/toolchains/nightly-2021-06-10-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-d231748acf961207.rlib" "-Bdynamic" "--eh-frame-hdr" "-znoexecstack" "-L" "/home/kyasbal/.rustup/toolchains/nightly-2021-06-10-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/kyasbal/workspace/zeros/repro/target/x86_64-unknown-linux-gnu/debug/deps/repro-976c68a0178ccd5f" "--gc-sections" "-zrelro" "-znow" "--entry=KernelMain" "--image-base=0x100000"
  = note: rust-lld: error: undefined symbol: memcpy
          >>> referenced by intrinsics.rs:1861 (/rustc/eab201df7028ebb6812c0b1a01702ac6ecfcceed/library/core/src/intrinsics.rs:1861)
          >>>               /home/kyasbal/workspace/zeros/repro/target/x86_64-unknown-linux-gnu/debug/deps/repro-976c68a0178ccd5f.4ookqi1igbeby3gm.rcgu.o:(core::intrinsics::copy_nonoverlapping::hce92df80101a2bb6)
          

error: aborting due to previous error; 1 warning emitted

This linker error is not observed when I use nightly-2021-06-09-x86_64-unknown-linux-gnu or comment out the empty for statement in KernelMain. This issue was reproduced in the other environment also by my friend.

I assume #86003 is related to this problem but I'm not so much sure why these change can cause this problem. I would happy to provide further more investigation if it was needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.O-x86_64Target: x86-64 processors (like x86_64-*) (also known as amd64 and x64)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions