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

File format not recognized when linking rmeta file for sparc-linux-unknown-gnu #126859

Open
glaubitz opened this issue Jun 23, 2024 · 8 comments
Open
Labels
A-codegen Area: Code generation A-linkage Area: linking into static, shared libraries and binaries O-SPARC Target: SPARC processors T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@glaubitz
Copy link
Contributor

I am currently trying to build rustc for the sparc-linux-unknown-gnu target which fails with the linker complaining about not recognizing the file format of the rmeta file on the command line:

error: linking with `sparc-linux-gnu-gcc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/glaubitz/.local/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games" VSLANG="1033" "sparc-linux-gnu-gcc" "-Wl,--version-script=/tmp/rustc9YiYtF/list" "-Wl,--no-undefined-version" "-mcpu=v9" "-m32" "-Wl,-melf32_sparc" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/std-41da709e9f6744d7.std.a946a352528c9d3a-cgu.00.rcgu.o" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/std-41da709e9f6744d7.std.a946a352528c9d3a-cgu.01.rcgu.o" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/std-41da709e9f6744d7.std.a946a352528c9d3a-cgu.02.rcgu.o" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/std-41da709e9f6744d7.std.a946a352528c9d3a-cgu.03.rcgu.o" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/std-41da709e9f6744d7.std.a946a352528c9d3a-cgu.04.rcgu.o" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/std-41da709e9f6744d7.std.a946a352528c9d3a-cgu.05.rcgu.o" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/std-41da709e9f6744d7.std.a946a352528c9d3a-cgu.06.rcgu.o" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/std-41da709e9f6744d7.std.a946a352528c9d3a-cgu.07.rcgu.o" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/std-41da709e9f6744d7.std.a946a352528c9d3a-cgu.08.rcgu.o" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/std-41da709e9f6744d7.std.a946a352528c9d3a-cgu.09.rcgu.o" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/std-41da709e9f6744d7.std.a946a352528c9d3a-cgu.10.rcgu.o" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/std-41da709e9f6744d7.std.a946a352528c9d3a-cgu.11.rcgu.o" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/std-41da709e9f6744d7.std.a946a352528c9d3a-cgu.12.rcgu.o" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/std-41da709e9f6744d7.std.a946a352528c9d3a-cgu.13.rcgu.o" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/std-41da709e9f6744d7.std.a946a352528c9d3a-cgu.14.rcgu.o" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/std-41da709e9f6744d7.std.a946a352528c9d3a-cgu.15.rcgu.o" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/std-41da709e9f6744d7.dn0tar95l4w690nusxeqr43d3.rcgu.rmeta" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/std-41da709e9f6744d7.040sn9hd3kpadxvyhdk75ycx5.rcgu.o" "-Wl,--as-needed" "-L" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps" "-L" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/release/deps" "-L" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/build/compiler_builtins-9cbe5026186c715b/out" "-L" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/sparc-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/libpanic_unwind-d6f3e19e347e8e30.rlib" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/libobject-96ad8f1969790b3e.rlib" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/libmemchr-7d65095888af1252.rlib" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/libaddr2line-bc5934419298e94f.rlib" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/libgimli-a550d13df8702836.rlib" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/librustc_demangle-3a3f56a767e453f8.rlib" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/libstd_detect-34ae8bef4a03fd18.rlib" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/libhashbrown-46ce46b7ff78718c.rlib" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/librustc_std_workspace_alloc-738616e97bd712d8.rlib" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/libminiz_oxide-1f2e9ed080496ac7.rlib" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/libadler-c646151839979ca7.rlib" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/libunwind-77b4a24e6c936276.rlib" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/libcfg_if-ca580308d22018b6.rlib" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/liblibc-721c91ee08a9ebc2.rlib" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/liballoc-5364848951c68550.rlib" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/librustc_std_workspace_core-2d05bd64c8bcabbb.rlib" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/libcore-e51655d4cadb2e75.rlib" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/libcompiler_builtins-494aac20c9cb2b3e.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/sparc-unknown-linux-gnu/lib" "-o" "/home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/libstd-41da709e9f6744d7.so" "-shared" "-Wl,-z,relro,-z,now" "-Wl,-O1" "-nodefaultlibs" "-Wl,-z,origin" "-Wl,-rpath,$ORIGIN/../lib"
  = note: /home/glaubitz/rust/build/x86_64-unknown-linux-gnu/stage1-std/sparc-unknown-linux-gnu/release/deps/std-41da709e9f6744d7.dn0tar95l4w690nusxeqr43d3.rcgu.rmeta: file not recognized: file format not recognized
          collect2: error: ld returned 1 exit status

I have already tried tuning the compiler and linker options in compiler/rustc_target/src/spec/targets/sparc_unknown_linux_gnu.rs, but I am still getting the same error. Since I have no clue what the rmeta file is supposed to contain, I don't know what might be wrong and needs to be fixed.

Thus, opening an issue in the hope that someone can explain what's in the rmeta file and what could be the reason for that file containing unexpected information, so I can come up with a possible fix.

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 23, 2024
@glaubitz
Copy link
Contributor Author

OK, this seems to be related about 32-bit SPARC missing an entry in compiler/rustc_codegen_ssa/src/back/metadata.rs.

But I have no clue where to find the source for the object crate.

@nikic Any suggestion?

@nikic
Copy link
Contributor

nikic commented Jun 23, 2024

@glaubitz The source for the object crate is at https://github.com/gimli-rs/object.

@glaubitz
Copy link
Contributor Author

Thanks, I just found that as well ;-). Guess we need to add support for Sparc there to fix this bug.

@glaubitz
Copy link
Contributor Author

glaubitz commented Jun 23, 2024

OK, I just did a quick and dirty hack to verify my theory:

diff --git a/compiler/rustc_codegen_ssa/src/back/metadata.rs b/compiler/rustc_codegen_ssa/src/back/metadata.rs
index 264a98844ad..8bbde747725 100644
--- a/compiler/rustc_codegen_ssa/src/back/metadata.rs
+++ b/compiler/rustc_codegen_ssa/src/back/metadata.rs
@@ -209,6 +209,7 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
         "powerpc64" => (Architecture::PowerPc64, None),
         "riscv32" => (Architecture::Riscv32, None),
         "riscv64" => (Architecture::Riscv64, None),
+        "sparc" => (Architecture::Sparc64, None),
         "sparc64" => (Architecture::Sparc64, None),
         "avr" => (Architecture::Avr, None),
         "msp430" => (Architecture::Msp430, None),

and indeed the rmeta file is now a 64-bit SPARC object file. Thus, adding 32-bit SPARC to the object crate will fix this bug.

@glaubitz
Copy link
Contributor Author

@nikic So, I tried editing the object crate that is being used to build rustc_codegen_ssa, but I cannot find that copy anywhere. In the past, it used to be in ~/.cargo/ but that doesn't seem to be the case anymore.

Can you tell me how I can edit the object crate for testing my patch?

@nikic
Copy link
Contributor

nikic commented Jun 23, 2024

You should be able to use [patch] to specify a local version of the crate (https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section).

@glaubitz
Copy link
Contributor Author

Thanks, that's very helpful! I didn't know about [patch].

@jieyouxu jieyouxu added A-codegen Area: Code generation O-SPARC Target: SPARC processors T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 5, 2024
@saethlin saethlin added A-linkage Area: linking into static, shared libraries and binaries and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Aug 12, 2024
@taiki-e
Copy link
Member

taiki-e commented Nov 14, 2024

I think this has been fixed by #128772 & #131222 & #132552.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation A-linkage Area: linking into static, shared libraries and binaries O-SPARC Target: SPARC processors 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

6 participants