Skip to content

Core build is broken when using build-std with custom cross-compile target #81516

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

Open
KernelFreeze opened this issue Jan 29, 2021 · 7 comments
Labels
-Zbuild-std Unstable Cargo option: Compile the standard library yourself. A-cross Area: Cross compilation A-target-feature Area: Enabling/disabling target features like AVX, Neon, etc. C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@KernelFreeze
Copy link

Hello. I'm using the nightly feature build-std to cross-compile core to a custom target. It always works as expected, however, today it suddenly stopped working and throws an error:

LLVM ERROR: EH registrations only live in functions using WinEH
error: could not compile `core`

I tried the same on Windows, and another error occurs:

Caused by:
process didn't exit successfully: `rustc --crate-name core --edition=2018 C:\Users\Kernel\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=f8246f0242b85744 -C extra-filename=-f8246f0242b85744 --out-dir C:\Users\Kernel\Documents\Proyectos\etheryal\kernel\target\x86_64\debug\deps --target \\?\C:\Users\Kernel\Documents\Proyectos\etheryal\kernel\targets\x86_64.json -Z force-unstable-if-unmarked -L dependency=C:\Users\Kernel\Documents\Proyectos\etheryal\kernel\target\x86_64\debug\deps -L dependency=C:\Users\Kernel\Documents\Proyectos\etheryal\kernel\target\debug\deps --cap-lints allow` (exit code: 0xc0000409, STATUS_STACK_BUFFER_OVERRUN)
warning: build failed, waiting for other jobs to finish...
error: build failed

Meta

rustc --version --verbose:

rustc --version --verbose
rustc 1.51.0-nightly (c0b64d97b 2021-01-28)
binary: rustc
commit-hash: c0b64d97beebb09325b5587abed39f4f1621026f
commit-date: 2021-01-28
host: x86_64-unknown-linux-gnu
release: 1.51.0-nightly
LLVM version: 11.0.1
Backtrace

   RUST_BACKTRACE=1 cargo build --verbose

   Compiling core v0.0.0 (/home/kernel/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
       Fresh autocfg v1.0.1
     Running `rustc --crate-name core --edition=2018 /home/kernel/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=6e4a9794a30e64e2 -C extra-filename=-6e4a9794a30e64e2 --out-dir /mnt/c/Users/Kernel/Documents/Proyectos/etheryal/kernel/target/x86_64/debug/deps --target /mnt/c/Users/Kernel/Documents/Proyectos/etheryal/kernel/targets/x86_64.json -Z force-unstable-if-unmarked -L dependency=/mnt/c/Users/Kernel/Documents/Proyectos/etheryal/kernel/target/x86_64/debug/deps -L dependency=/mnt/c/Users/Kernel/Documents/Proyectos/etheryal/kernel/target/debug/deps --cap-lints allow`
   Compiling rustc-std-workspace-core v1.99.0 (/home/kernel/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
     Running `rustc --crate-name rustc_std_workspace_core --edition=2018 /home/kernel/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=de6d357e632aa5bc -C extra-filename=-de6d357e632aa5bc --out-dir /mnt/c/Users/Kernel/Documents/Proyectos/etheryal/kernel/target/x86_64/debug/deps --target /mnt/c/Users/Kernel/Documents/Proyectos/etheryal/kernel/targets/x86_64.json -Z force-unstable-if-unmarked -L dependency=/mnt/c/Users/Kernel/Documents/Proyectos/etheryal/kernel/target/x86_64/debug/deps -L dependency=/mnt/c/Users/Kernel/Documents/Proyectos/etheryal/kernel/target/debug/deps --extern core=/mnt/c/Users/Kernel/Documents/Proyectos/etheryal/kernel/target/x86_64/debug/deps/libcore-6e4a9794a30e64e2.rmeta --cap-lints allow`
   Compiling compiler_builtins v0.1.39
     Running `rustc --crate-name compiler_builtins /home/kernel/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.39/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 --cfg 'feature="compiler-builtins"' --cfg 'feature="core"' --cfg 'feature="default"' --cfg 'feature="mem"' --cfg 'feature="rustc-dep-of-std"' -C metadata=97388e1919ba9c5c -C extra-filename=-97388e1919ba9c5c --out-dir /mnt/c/Users/Kernel/Documents/Proyectos/etheryal/kernel/target/x86_64/debug/deps --target /mnt/c/Users/Kernel/Documents/Proyectos/etheryal/kernel/targets/x86_64.json -Z force-unstable-if-unmarked -L dependency=/mnt/c/Users/Kernel/Documents/Proyectos/etheryal/kernel/target/x86_64/debug/deps -L dependency=/mnt/c/Users/Kernel/Documents/Proyectos/etheryal/kernel/target/debug/deps --extern core=/mnt/c/Users/Kernel/Documents/Proyectos/etheryal/kernel/target/x86_64/debug/deps/librustc_std_workspace_core-de6d357e632aa5bc.rmeta --cap-lints allow --cfg 'feature="unstable"'`
LLVM ERROR: EH registrations only live in functions using WinEH
error: could not compile `core`

Caused by:
  process didn't exit successfully: `rustc --crate-name core --edition=2018 /home/kernel/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=6e4a9794a30e64e2 -C extra-filename=-6e4a9794a30e64e2 --out-dir /mnt/c/Users/Kernel/Documents/Proyectos/etheryal/kernel/target/x86_64/debug/deps --target /mnt/c/Users/Kernel/Documents/Proyectos/etheryal/kernel/targets/x86_64.json -Z force-unstable-if-unmarked -L dependency=/mnt/c/Users/Kernel/Documents/Proyectos/etheryal/kernel/target/x86_64/debug/deps -L dependency=/mnt/c/Users/Kernel/Documents/Proyectos/etheryal/kernel/target/debug/deps --cap-lints allow` (exit code: 101)
warning: build failed, waiting for other jobs to finish...
error: build failed

config.toml:

[unstable]
build-std = ["core", "compiler_builtins", "alloc"]
build-std-features = ["compiler-builtins-mem"]

Thank you for your great work!

@KernelFreeze KernelFreeze added the C-bug Category: This is a bug. label Jan 29, 2021
@ehuss
Copy link
Contributor

ehuss commented Jan 29, 2021

Can you post a copy of your target spec? Are there any other details about the custom target that are needed to reproduce?

@KernelFreeze
Copy link
Author

My target spec is:

{
  "llvm-target": "x86_64-unknown-none",
  "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
  "arch": "x86_64",
  "target-endian": "little",
  "target-pointer-width": "64",
  "target-c-int-width": "32",
  "os": "none",
  "executables": true,
  "linker-flavor": "ld.lld",
  "linker": "rust-lld",
  "panic-strategy": "abort",
  "disable-redzone": true,
  "features": "-mmx,-sse,+soft-float"
}

If I enable SSE and MMX, the build fails again

@ehuss
Copy link
Contributor

ehuss commented Jan 29, 2021

Sorry, I'm a bit confused. Are you saying you see an error with "-mmx,-sse,+soft-float" or with "+mmx,+sse,+soft-float" or both?

I'm only able to reproduce with +sse,+soft-float, but I don't think that combination is really supported. See #36659, where one possibility is to have +soft-float imply -sse and friends.

@KernelFreeze
Copy link
Author

I get this error with just +mmx,+sse

@camelid camelid added the requires-nightly This issue requires a nightly compiler in some way. label Feb 1, 2021
@workingjubilee workingjubilee added A-target-feature Area: Enabling/disabling target features like AVX, Neon, etc. -Zbuild-std Unstable Cargo option: Compile the standard library yourself. labels Mar 11, 2023
@Enselic Enselic added the A-cross Area: Cross compilation label Nov 22, 2024
@Enselic Enselic changed the title Core build is broken when using build-std Core build is broken when using build-std with custom cross-compile target Nov 22, 2024
@Enselic Enselic added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Nov 22, 2024
@Enselic
Copy link
Member

Enselic commented Dec 3, 2024

Triage: I'm trying to reproduce this but I'm getting different errors now. I'm compiling hello world with your target JSON:

$ cargo +nightly build -Zbuild-std --target x86_64.json
   Compiling core v0.0.0 (/home/martin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
   Compiling compiler_builtins v0.1.138
   Compiling libc v0.2.162
   Compiling std v0.0.0 (/home/martin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std)
   Compiling rustc-std-workspace-core v1.99.0 (/home/martin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
error: data-layout for target `x86_64-1532950540624012415`, `e-m:e-i64:64-f80:128-n8:16:32:64-S128`, differs from LLVM target's `x86_64-unknown-none` default layout, `e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128`

error: could not compile `rustc-std-workspace-core` (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `libc` (lib) due to 1 previous error
error: could not compile `core` (lib) due to 1 previous error
error: could not compile `compiler_builtins` (lib) due to 1 previous error

Did you find a workaround for the problem?

Can we close this issue as obsolete?

@ehuss
Copy link
Contributor

ehuss commented Dec 3, 2024

@Enselic Over time the data-layout field has to be updated when new LLVM versions are introduced. The current target json reproduction is:

{
  "llvm-target": "x86_64-unknown-none",
  "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",
  "arch": "x86_64",
  "target-endian": "little",
  "target-pointer-width": "64",
  "target-c-int-width": "32",
  "os": "none",
  "executables": true,
  "linker-flavor": "ld.lld",
  "linker": "rust-lld",
  "panic-strategy": "abort",
  "disable-redzone": true,
  "features": "+sse,+soft-float"
}

And cargo build -Zbuild-std=core --target target.json

I would guess that SSE is incompatible with soft-float. And neither rustc or llvm are really validating that the given options are compatible with one another.

rustc 1.85.0-nightly (5e1440ae5 2024-12-01)
binary: rustc
commit-hash: 5e1440ae514d98ddfcbf1607acb64d41e07ef616
commit-date: 2024-12-01
host: aarch64-apple-darwin
release: 1.85.0-nightly
LLVM version: 19.1.4

@Enselic
Copy link
Member

Enselic commented Dec 4, 2024

I see, thanks. If SSE is incompatible with soft-float I suggest we close this as won't fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-Zbuild-std Unstable Cargo option: Compile the standard library yourself. A-cross Area: Cross compilation A-target-feature Area: Enabling/disabling target features like AVX, Neon, etc. C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. 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

5 participants