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

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

Open
kyasbal opened this issue Jul 13, 2021 · 1 comment
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. O-x86_64 Target: x86-64 processors (like x86_64-*) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kyasbal
Copy link

kyasbal commented Jul 13, 2021

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.

@kyasbal kyasbal added the C-bug Category: This is a bug. label Jul 13, 2021
@JohnTitor
Copy link
Member

Slightly minimized (removed unstable asm feature):

#![no_std]
#![no_main]

use core::panic::PanicInfo;

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

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

Note that the mentioned PR just reverted the changes by #81238 and the issue exists on older stable (at least I confirmed on 1.45).

@JohnTitor JohnTitor added A-linkage Area: linking into static, shared libraries and binaries O-x86_64 Target: x86-64 processors (like x86_64-*) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 13, 2021
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. O-x86_64 Target: x86-64 processors (like x86_64-*) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants