Skip to content

Failed rlib archive processing with rustc 1.17 compiled against LLVM 4.0 #42857

@copumpkin

Description

@copumpkin

I apologize that this isn't the best bug description, but after several hours on this, I still haven't been able to reduce it to get a small repro that would fit the template, so I'll describe what I know so far and hope that someone has hints for how to debug further so I can improve this issue report (or close it if it turns out to be unrelated to rustc!)

I'm running on macOS with rustc 1.17.0 compiled against a mostly vanilla LLVM 4.0, under the Nix package manager (which doesn't have 1.18.0 yet or I'd try that; it doesn't look like the relevant code has changed much so I haven't put much effort on that front yet).

When I try to build https://github.com/pantsbuild/pants/tree/master/src/rust/engine in that environment (it's a Python module written in rust), I get most of the way through compilation but then rustc barfs with the following message:

error: failed to build archive: bad archive: truncated or malformed archive (offset to next archive member past the end of the archive after member collections-ef2067477795e5ee.9.bytecode.deflate)

(the failure is consistent but not always on the collections library; I've seen it happen on libstd too)

The strings in that error message tell me that it's likely coming from https://github.com/rust-lang/rust/blob/1.17.0/src/librustc_trans/back/archive.rs#L228 and one of the two iterator loops over archive children below there (due to the "bad archive" error snippet that's added to each child).

Looking at the relevant rlibs, I can get pure LLVM to spit out exactly the same error message just by running llvm-nm (which is conveniently bundled with the macOS developer kit) against it:

$ nm /nix/store/kwn3vvcbl7rwxlz8j3vppdwwqjkkl3mz-rustc-1.17.0/lib/rustlib/x86_64-apple-darwin/lib/libcollections-ef2067477795e5ee.rlib

[lots of reasonable symbols]

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/nm: /nix/store/kwn3vvcbl7rwxlz8j3vppdwwqjkkl3mz-rustc-1.17.0/lib/rustlib/x86_64-apple-darwin/lib/libcollections-ef2067477795e5ee.rlib(rust.metadata.bin) The end of the file was unexpectedly encountered

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/nm: /nix/store/kwn3vvcbl7rwxlz8j3vppdwwqjkkl3mz-rustc-1.17.0/lib/rustlib/x86_64-apple-darwin/lib/libcollections-ef2067477795e5ee.rlib truncated or malformed archive (offset to next archive member past the end of the archive after member collections-ef2067477795e5ee.9.bytecode.deflate)

I think the warning on rust.metadata.bin is expected since it's not something that nm understands, but the final error message about the truncated or malformed archive is identical to what rustc spits out.

What I've been able to make of this is that something between rustc, LLVM 4, or my weird Nix build of the two of them together is either producing invalid rlib/.a archives or producing valid archives that the LLVM archive iterator then doesn't know how to handle when it consumes them again later.

As an additional data point, Nix allows us to run almost exactly the same build on multiple platforms (almost same combination of flags, dependencies, etc.) and I can run the exact same build just fine on Linux. So this seems to be some unhappiness with Darwin in particular...

Anyway, I'm not expecting anyone to be able to figure out the issue based on the weird situation I describe above, but would appreciate any debugging hints anyone has to help me track this down; if this turns out to be a real issue in rustc or LLVM, I'll file new issues or update this one as I learn more, but right now I'm getting kind of stumped. My best debugging approach so far is creating (sloow) custom rustc builds with prints sprinked across relevant code to see what's going on, so I'd welcome anything less painful than that.

cc @alexcrichton who is seemingly deeply involved in archive.rs and friends

Verbose version

/nix/store/kwn3vvcbl7rwxlz8j3vppdwwqjkkl3mz-rustc-1.17.0/bin/rustc --version --verbose
rustc 1.17.0
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-apple-darwin
release: 1.17.0
LLVM version: 4.0

Edit: I've tried various -Z options that sound potentially helpful but none of them told me anything around the point of the crash. Here are some of the ones I tried to no avail: print-llvm-passes, debug-llvm, verbose, print-link-args

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions