Change:
Building the mozjs crate for any Windows target stopped working after mozjs has a build script that compiles the C++ library SpiderMonkey into , which is then . Before , these builds worked successfully. Since that PR was merged, CI using nightly and beta toolsets targeting MSVC x8664 and UWP x86_64 now fail to build with the following error: This was first reported in and 2022-12-03 nightly Rust 1.66 beta 2022-12-04 nightly Rust 1.67 beta If you know when this regression occurred, please add a line like below, replacing with one of stable, beta, or nightly. modify labels: +regression-from-stable-to-beta -regression-untriaged
cc
As workaround adding windows to should revert back to the old archive writer. Luckily it was preserved for wasm. Could you post a hex dump of the first 16 or so bytes of the archive to see the magic bytes of this file.
Here is hexdump: Here is GitHub action of working one: and here is GitHub action of defect one: Artifact contains .lib file, that is produced in job.
Yeah, that is indeed very much not a valid archive. It does look like (which is a valid header for thin archives) except with every pair of bytes swapped. Rustc also shouldn't be producing thin archives.
Well hex-editor in vscode shows it right (but is showing reversed bits on same file): !
Do you know if this affects all Windows targets or just MSVC based? I couldn't get it to build at all with :
Ideally we would want to find another case for regression, because mozjs is complicated. Do you have MozillaBuild 3.4 installed as error is in and MozBuild comes packaged with python? I suggest looking at GitHub Workflows to correctly setup for compiling.
No, I had checked first step in the readme but the link is dead:
Well, those instruction would not be relevant anymore as we are still few SM versions behind if they would be available. Following GitHub Workflows is currently the best way.
WG-prioritization assigning priority (). label -I-prioritize +P-high
label: -P-high +P-critical (Upgrading priority because, until we better understand the scope of this bug, it strikes me as something that might motivate a fast-tracked point release for 1.67.)
I wonder if we have another case of this issue in
You linked this issue itself.
Could be
Oh, I completely misunderstood what the issue was. I thought this was about rustc producing a malformed archive, but it is actually about rustc not being able to read thin archives produced by an external build system. Object indeed doesn't support parsing thin archives and even if it did, it would likely need to be wired up in rustc separately. I think the best course of action is to change to always take the branch. This will restore the old behavior for cg_llvm. will probably also need to be reverted partially or as a whole because it removed macOS fat archive reading for the LLVM archive writer. (This would have been so much more painful to revert if I hadn't needed to keep the old LLVM archive writer for wasm.)
And yes is very likely a duplicate of this.
I believe I may be encountering a similar, or related, regression between 1.67 and 1.66 when attempting to build and link against shaderc on MSVC:
I know it's a little late for clarification now, but still. (GitHub Actions) build has the same header as non-working build; and that .lib file is built by SM build scripts not Rust ( dir is SM out directory). The main misunderstanding comes from weird behavior:
Opened to revert back to LlvmArchiveWriter, which would fix this issue for now I think.
label: E-needs-test
(and any such test should probably be beta-backported; see discussion from )
Downgrading to as we've shipped a point release with this fix. Leaving open as we would love a regression test to be .
Untagging as a regression, since this has been fixed on beta + stable + nightly at this point as far as I can tell.

Discussion:
impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder { fn new_archive_builder<'a>(&self, sess: &'a Session) -> Box<dyn ArchiveBuilder + 'a> { <del> // FIXME use ArArchiveBuilder on most targets again once reading thin archives is // implemented if true { </del> <ins> // Keeping LlvmArchiveBuilder around in case of a regression caused by using // ArArchiveBuilder. // FIXME(#128955) remove a couple of months after #128936 gets merged in case // no regression is found. if false { </ins> Box::new(LlvmArchiveBuilder { sess, additions: Vec::new() }) } else { Box::new(ArArchiveBuilder::new(sess, &LLVM_OBJECT_READER))

get_xcoff_member_alignment: DEFAULT_OBJECT_READER.get_xcoff_member_alignment, }; <del> fn should_use_llvm_reader(buf: &[u8]) -> bool { let is_bitcode = unsafe { llvm::LLVMRustIsBitcode(buf.as_ptr(), buf.len()) }; // COFF bigobj file, msvc LTO file or import library. See // https://github.com/llvm/llvm-project/blob/453f27bc9/llvm/lib/BinaryFormat/Magic.cpp#L38-L51 let is_unsupported_windows_obj_file = buf.get(0..4) == Some(b"00xFFxFF"); is_bitcode || is_unsupported_windows_obj_file } </del> #[deny(unsafe_op_in_unsafe_fn)] fn get_llvm_object_symbols( buf: &[u8], f: &mut dyn FnMut(&[u8]) -> io::Result<()>, ) -> io::Result<bool> { <del> if !should_use_llvm_reader(buf) { return (DEFAULT_OBJECT_READER.get_symbols)(buf, f); } </del> let mut state = Box::new(f); let err = unsafe {

} fn llvm_is_64_bit_object_file(buf: &[u8]) -> bool { <del> if !should_use_llvm_reader(buf) { return (DEFAULT_OBJECT_READER.is_64_bit_object_file)(buf); } </del> unsafe { llvm::LLVMRustIs64BitSymbolicFile(buf.as_ptr(), buf.len()) } } fn llvm_is_ec_object_file(buf: &[u8]) -> bool { <del> if !should_use_llvm_reader(buf) { return (DEFAULT_OBJECT_READER.is_ec_object_file)(buf); } </del> unsafe { llvm::LLVMRustIsECObject(buf.as_ptr(), buf.len()) } }

let file_name = String::from_utf8(entry.name().to_vec()) .map_err(|err| io::Error::new(io::ErrorKind::InvalidData, err))?; if !skip(&file_name) { <del> self.entries.push(( file_name.into_bytes(), ArchiveEntry::FromArchive { archive_index, file_range: entry.file_range() }, )); </del> <ins> if entry.is_thin() { let member_path = archive_path.parent().unwrap().join(Path::new(&file_name)); self.entries.push((file_name.into_bytes(), ArchiveEntry::File(member_path))); } else { self.entries.push(( file_name.into_bytes(), ArchiveEntry::FromArchive { archive_index, file_range: entry.file_range() }, )); } </ins> } }

Expected<std::unique_ptr<object::SymbolicFile>> ObjOrErr = getSymbolicFile(Buf->getMemBufferRef(), Context); if (!ObjOrErr) { <del> Error E = ObjOrErr.takeError(); SmallString<0> ErrorBuf; auto Error = raw_svector_ostream(ErrorBuf); Error << E << '0'; return ErrorCallback(Error.str().data()); </del> <ins> return ErrorCallback(toString(ObjOrErr.takeError()).c_str()); </ins> } std::unique_ptr<object::SymbolicFile> Obj = std::move(*ObjOrErr); <ins> if (Obj == nullptr) { return 0; } </ins> for (const object::BasicSymbolRef &S : Obj->symbols()) { if (!isArchiveSymbol(S)) continue; if (Error E = S.printName(SymName)) { <del> SmallString<0> ErrorBuf; auto Error = raw_svector_ostream(ErrorBuf); Error << E << '0'; return ErrorCallback(Error.str().data()); </del> <ins> return ErrorCallback(toString(std::move(E)).c_str()); </ins> } SymName << '0'; if (void *E = Callback(State, SymNameBuf.str().data())) {

self } <ins> /// Like `obj_to_ar` except creating a thin archive. pub fn obj_to_thin_ar(&mut self) -> &mut Self { self.cmd.arg("rcus").arg("--thin"); self } </ins> /// Extract archive members back to files. pub fn extract(&mut self) -> &mut Self { self.cmd.arg("x");

<ins> fn main() { unsafe { rust_lib::simple_fn(); } } </ins>

<ins> // Regression test for https://github.com/rust-lang/rust/issues/107407 which // checks that rustc can read thin archive. Before the object crate added thin // archive support rustc would add emit object files to the staticlib and after // the object crate added thin archive support it would previously crash the // compiler due to a missing special case for thin archive members. use run_make_support::{llvm_ar, path, rfs, rust_lib_name, rustc, static_lib_name}; fn main() { rfs::create_dir("archive"); // Build a thin archive rustc().input("simple_obj.rs").emit("obj").output("archive/simple_obj.o").run(); llvm_ar() .obj_to_thin_ar() .output_input(path("archive").join(static_lib_name("thin_archive")), "archive/simple_obj.o") .run(); // Build an rlib which includes the members of this thin archive rustc().input("rust_lib.rs").library_search_path("archive").run(); // Build a binary which requires a symbol from the thin archive rustc().input("bin.rs").extern_("rust_lib", rust_lib_name("rust_lib")).run(); } </ins>

<ins> #![crate_type = "rlib"] #[link(name = "thin_archive", kind = "static")] extern "C" { pub fn simple_fn(); } </ins>

<ins> #![crate_type = "staticlib"] #[no_mangle] extern "C" fn simple_fn() {} </ins>