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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2159,9 +2159,9 @@ dependencies = [

[[package]]
name = "memchr"
version = "2.3.3"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc"

[[package]]
name = "memmap2"
Expand Down Expand Up @@ -2364,6 +2364,17 @@ dependencies = [
"rustc-std-workspace-core",
]

[[package]]
name = "object"
version = "0.25.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8bc1d42047cf336f0f939c99e97183cf31551bf0f2865a2ec9c8d91fd4ffb5e"
dependencies = [
"crc32fast",
"indexmap",
"memchr",
]

[[package]]
name = "once_cell"
version = "1.7.2"
Expand Down Expand Up @@ -3706,7 +3717,7 @@ dependencies = [
"itertools 0.9.0",
"jobserver",
"libc",
"object",
"object 0.25.2",
"pathdiff",
"rustc_apfloat",
"rustc_ast",
Expand Down Expand Up @@ -4923,7 +4934,7 @@ dependencies = [
"hermit-abi",
"libc",
"miniz_oxide",
"object",
nagisa marked this conversation as resolved.
Show resolved Hide resolved
"object 0.22.0",
"panic_abort",
"panic_unwind",
"profiler_builtins",
Expand Down
40 changes: 0 additions & 40 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,11 +582,6 @@ pub struct PassManager<'a>(InvariantOpaque<'a>);
extern "C" {
pub type PassManagerBuilder;
}
extern "C" {
pub type ObjectFile;
}
#[repr(C)]
pub struct SectionIterator<'a>(InvariantOpaque<'a>);
extern "C" {
pub type Pass;
}
Expand Down Expand Up @@ -1703,35 +1698,6 @@ extern "C" {

pub fn LLVMDisposeMessage(message: *mut c_char);

// Stuff that's in llvm-wrapper/ because it's not upstream yet.

/// Opens an object file.
pub fn LLVMCreateObjectFile(
MemBuf: &'static mut MemoryBuffer,
) -> Option<&'static mut ObjectFile>;
/// Closes an object file.
pub fn LLVMDisposeObjectFile(ObjFile: &'static mut ObjectFile);

/// Enumerates the sections in an object file.
pub fn LLVMGetSections(ObjFile: &'a ObjectFile) -> &'a mut SectionIterator<'a>;
/// Destroys a section iterator.
pub fn LLVMDisposeSectionIterator(SI: &'a mut SectionIterator<'a>);
/// Returns `true` if the section iterator is at the end of the section
/// list:
pub fn LLVMIsSectionIteratorAtEnd(ObjFile: &'a ObjectFile, SI: &SectionIterator<'a>) -> Bool;
/// Moves the section iterator to point to the next section.
pub fn LLVMMoveToNextSection(SI: &SectionIterator<'_>);
/// Returns the current section size.
pub fn LLVMGetSectionSize(SI: &SectionIterator<'_>) -> c_ulonglong;
/// Returns the current section contents as a string buffer.
pub fn LLVMGetSectionContents(SI: &SectionIterator<'_>) -> *const c_char;

/// Reads the given file and returns it as a memory buffer. Use
/// LLVMDisposeMemoryBuffer() to get rid of it.
pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(
Path: *const c_char,
) -> Option<&'static mut MemoryBuffer>;

pub fn LLVMStartMultithreaded() -> Bool;

/// Returns a string describing the last error caused by an LLVMRust* call.
Expand Down Expand Up @@ -2236,12 +2202,6 @@ extern "C" {
pub fn LLVMRustArchiveIteratorFree(AIR: &'a mut ArchiveIterator<'a>);
pub fn LLVMRustDestroyArchive(AR: &'static mut Archive);

#[allow(improper_ctypes)]
pub fn LLVMRustGetSectionName(
SI: &SectionIterator<'_>,
data: &mut Option<std::ptr::NonNull<c_char>>,
) -> size_t;

#[allow(improper_ctypes)]
pub fn LLVMRustWriteTwineToString(T: &Twine, s: &RustString);

Expand Down
44 changes: 0 additions & 44 deletions compiler/rustc_codegen_llvm/src/llvm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,50 +150,6 @@ impl Attribute {
}
}

// Memory-managed interface to object files.

pub struct ObjectFile {
pub llof: &'static mut ffi::ObjectFile,
}

unsafe impl Send for ObjectFile {}

impl ObjectFile {
// This will take ownership of llmb
pub fn new(llmb: &'static mut MemoryBuffer) -> Option<ObjectFile> {
unsafe {
let llof = LLVMCreateObjectFile(llmb)?;
Some(ObjectFile { llof })
}
}
}

impl Drop for ObjectFile {
fn drop(&mut self) {
unsafe {
LLVMDisposeObjectFile(&mut *(self.llof as *mut _));
}
}
}

// Memory-managed interface to section iterators.

pub struct SectionIter<'a> {
pub llsi: &'a mut SectionIterator<'a>,
}

impl Drop for SectionIter<'a> {
fn drop(&mut self) {
unsafe {
LLVMDisposeSectionIterator(&mut *(self.llsi as *mut _));
}
}
}

pub fn mk_section_iter(llof: &ffi::ObjectFile) -> SectionIter<'_> {
unsafe { SectionIter { llsi: LLVMGetSections(llof) } }
}

pub fn set_section(llglobal: &Value, section_name: &str) {
let section_name_cstr = CString::new(section_name).expect("unexpected CString error");
unsafe {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_ssa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ rustc_target = { path = "../rustc_target" }
rustc_session = { path = "../rustc_session" }

[dependencies.object]
version = "0.22.0"
version = "0.25.2"
default-features = false
features = ["read_core", "elf", "macho", "pe", "unaligned", "archive"]
features = ["read_core", "elf", "macho", "pe", "unaligned", "archive", "write"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the object dependency of backtrace is updated, this new feature will become unified with libstd resulting in binary bloat. Should we switch rustc to the version 2 resolver already?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No libstd and rustc have separate builds, so they get separate feature sets. This won't affect libstd. Changing the resolver for Cargo also won't affect anything here.

Loading