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

rustc: Store metadata-in-rlibs in object files #84449

Merged
merged 1 commit into from
Jun 4, 2021

Commits on Jun 4, 2021

  1. rustc: Store metadata-in-rlibs in object files

    This commit updates how rustc compiler metadata is stored in rlibs.
    Previously metadata was stored as a raw file that has the same format as
    `--emit metadata`. After this commit, however, the metadata is encoded
    into a small object file which has one section which is the contents of
    the metadata.
    
    The motivation for this commit is to fix a common case where rust-lang#83730
    arises. The problem is that when rustc crates a `dylib` crate type it
    needs to include entire rlib files into the dylib, so it passes
    `--whole-archive` (or the equivalent) to the linker. The problem with
    this, though, is that the linker will attempt to read all files in the
    archive. If the metadata file were left as-is (today) then the linker
    would generate an error saying it can't read the file. The previous
    solution was to alter the rlib just before linking, creating a new
    archive in a temporary directory which has the metadata file removed.
    
    This problem from before this commit is now removed if the metadata file
    is stored in an object file that the linker can read. The only caveat we
    have to take care of is to ensure that the linker never actually
    includes the contents of the object file into the final output. We apply
    similar tricks as the `.llvmbc` bytecode sections to do this.
    
    This involved changing the metadata loading code a bit, namely updating
    some of the LLVM C APIs used to use non-deprecated ones and fiddling
    with the lifetimes a bit to get everything to work out. Otherwise though
    this isn't intended to be a functional change really, only that metadata
    is stored differently in archives now.
    
    This should end up fixing rust-lang#83730 because by default dylibs will no
    longer have their rlib dependencies "altered" meaning that
    split-debuginfo will continue to have valid paths pointing at the
    original rlibs. (note that we still "alter" rlibs if LTO is enabled to
    remove Rust object files and we also "alter" for the #[link(cfg)]
    feature, but that's rarely used).
    
    Closes rust-lang#83730
    alexcrichton committed Jun 4, 2021
    Configuration menu
    Copy the full SHA
    0e03387 View commit details
    Browse the repository at this point in the history