rust-lang / rust-lang/rustc_codegen_gcc

Targeting a specific MIPS arch: internal compiler error on building `compiler_builtins` stemming from ABI troubles.

Open
#546 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
1.2k
Forks
105
Avg merge
8h 20m
Merged PRs (30d)
14

Description

target.json in question:

{
  "arch": "mips64r5",
  "data-layout": "e-m:m-p:64:32-i8:8:32-i16:16:32-i64:64-n32-S64",
  "dynamic-linking": false,
  "executables": true,
  "linker": "mipsel-none-elf-ld",
  "linker-flavor": "ld",
  "llvm-target": "mipsel-none-elf",
  "llvm-args": "-mxgot",
  "max-atomic-width": 32,
  "features": "+soft_float",
  "os": "none",
  "panic-strategy": "abort",
  "position-independent-executables": false,
  "relro-level": "full",
  "target-c-int-width": "32",
  "target-endian": "little",
  "target-pointer-width": "64",
  "vendor": "unknown"
}

which, after some wrangling, can build core, but not compiler_builtins:


error: internal compiler error: src/context.rs:605:21: `fn_abi_of_instance(conv::__floatunsisf, [])` failed: AdjustForForeignAbi(Unsupported { arch: "mips64r5", abi: C { unwind: false } })
   --> /home/gabca/.cargo/registry/src/index.crates.io-6f17d22bba15001f/compiler_builtins-0.1.109/src/macros.rs:491:9
    |
491 |           pub extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
    |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
   ::: /home/gabca/.cargo/registry/src/index.crates.io-6f17d22bba15001f/compiler_builtins-0.1.109/src/float/conv.rs:74:1
    |
74  | / intrinsics! {
75  | |     #[arm_aeabi_alias = __aeabi_ui2f]
76  | |     pub extern "C" fn __floatunsisf(i: u32) -> f32 {
77  | |         f32::from_bits(int_to_float::u32_to_f32_bits(i))
...   |
103 | |     }
104 | | }
    | |_- in this macro invocation
    |
    = note: this error: internal compiler error originates in the macro `intrinsics` (in Nightly builds, run with -Z macro-backtrace for more info)

thread 'rustc' panicked at src/context.rs:605:21:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   2: rustc_errors::DiagCtxtHandle::span_bug
   3: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
   4: rustc_middle::ty::context::tls::with_opt::{{closure}}
   5: rustc_middle::ty::context::tls::with_context_opt
   6: rustc_middle::util::bug::span_bug_fmt
   7: <rustc_codegen_gcc::context::CodegenCx as rustc_middle::ty::layout::FnAbiOfHelpers>::handle_fn_abi_err
   8: rustc_middle::ty::layout::FnAbiOf::fn_abi_of_instance::{{closure}}
   9: rustc_middle::ty::layout::FnAbiOf::fn_abi_of_instance
  10: rustc_codegen_gcc::mono_item::<impl rustc_codegen_ssa::traits::declare::PreDefineMethods for rustc_codegen_gcc::context::CodegenCx>::predefine_fn
  11: rustc_codegen_gcc::base::compile_codegen_unit::module_codegen
  12: rustc_codegen_gcc::base::compile_codegen_unit
  13: rustc_codegen_ssa::base::codegen_crate
  14: <rustc_codegen_gcc::GccCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  15: <rustc_interface::queries::Queries>::codegen_and_build_linker
  16: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

note: using internal features is not supported and expected to cause internal compiler errors when used incorrectly

note: please attach the file at `/home/gabca/.cargo/registry/src/index.crates.io-6f17d22bba15001f/compiler_builtins-0.1.109/rustc-ice-2024-07-28T15_04_39-617670.txt` to your bug report

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -Z force-unstable-if-unmarked -Z codegen-backend=/home/gabca/rustc_codegen_gcc/target/release/librustc_codegen_gcc.so

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
warning: `compiler_builtins` (lib) generated 1 warning
error: could not compile `compiler_builtins` (lib); 1 warning emitted
warning: build failed, waiting for other jobs to finish...
error: internal compiler error: src/context.rs:605:21: `fn_abi_of_instance(CString::from_raw::strlen, [])` failed: AdjustForForeignAbi(Unsupported { arch: "mips64r5", abi: C { unwind: false } })
   --> /home/gabca/.rustup/toolchains/nightly-2024-07-02-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/ffi/c_str.rs:409:17
    |
409 |                 fn strlen(s: *const c_char) -> usize;
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at src/context.rs:605:21:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   2: rustc_errors::DiagCtxtHandle::span_bug
   3: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
   4: rustc_middle::ty::context::tls::with_opt::{{closure}}
   5: rustc_middle::ty::context::tls::with_context_opt
   6: rustc_middle::util::bug::span_bug_fmt
   7: <rustc_codegen_gcc::context::CodegenCx as rustc_middle::ty::layout::FnAbiOfHelpers>::handle_fn_abi_err
   8: <rustc_codegen_gcc::builder::Builder as rustc_middle::ty::layout::FnAbiOfHelpers>::handle_fn_abi_err
   9: rustc_middle::ty::layout::FnAbiOf::fn_abi_of_instance::{{closure}}
  10: rustc_codegen_ssa::mir::block::<impl rustc_codegen_ssa::mir::FunctionCx<Bx>>::codegen_terminator
  11: rustc_codegen_ssa::mir::codegen_mir
  12: rustc_codegen_ssa::base::codegen_instance
  13: <rustc_middle::mir::mono::MonoItem as rustc_codegen_ssa::mono_item::MonoItemExt>::define
  14: rustc_codegen_gcc::base::compile_codegen_unit::module_codegen
  15: rustc_codegen_gcc::base::compile_codegen_unit
  16: rustc_codegen_ssa::base::codegen_crate
  17: <rustc_codegen_gcc::GccCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  18: <rustc_interface::queries::Queries>::codegen_and_build_linker
  19: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}

https://gcc.gnu.org/onlinedocs/gcc/MIPS-Options.html documents a from-abi value that could fix this hopefully. No idea how to go about getting rustc_codegen_gcc to emit that though.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the compiler_builtins build with the provided target.json and inspect src/context.rs where fn_abi_of_instance errors are handled. Compare the failures from compiler_builtins/src/float/conv.rs and library/alloc/src/ffi/c_str.rs, then determine what support is needed for the mips64r5 C ABI. Done means the target builds without an internal compiler error.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.