Skip to content

Commit db68a19

Browse files
committed
Fix review comments and other improvements
1 parent d63a067 commit db68a19

File tree

6 files changed

+34
-24
lines changed

6 files changed

+34
-24
lines changed

compiler/rustc_codegen_llvm/src/back/archive.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
108108
fn new_archive_builder<'a>(&self, sess: &'a Session) -> Box<dyn ArchiveBuilder + 'a> {
109109
// Keeping LlvmArchiveBuilder around in case of a regression caused by using
110110
// ArArchiveBuilder.
111-
// FIXME remove a couple of months after #128936 gets merged in case no
112-
// regression is found.
111+
// FIXME(#128955) remove a couple of months after #128936 gets merged in case
112+
// no regression is found.
113113
if false {
114114
Box::new(LlvmArchiveBuilder { sess, additions: Vec::new() })
115115
} else {

compiler/rustc_codegen_ssa/src/back/archive.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,8 @@ impl<'a> ArchiveBuilder for ArArchiveBuilder<'a> {
308308
.map_err(|err| io::Error::new(io::ErrorKind::InvalidData, err))?;
309309
if !skip(&file_name) {
310310
if entry.is_thin() {
311-
self.entries.push((
312-
file_name.clone().into_bytes(),
313-
ArchiveEntry::File(PathBuf::from(file_name)),
314-
));
311+
let member_path = archive_path.parent().unwrap().join(Path::new(&file_name));
312+
self.entries.push((file_name.into_bytes(), ArchiveEntry::File(member_path)));
315313
} else {
316314
self.entries.push((
317315
file_name.into_bytes(),
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
#[link(name = "rust_archive", kind = "static")]
2-
extern "C" {
3-
fn simple_fn();
4-
}
5-
61
fn main() {
72
unsafe {
8-
simple_fn();
3+
rust_lib::simple_fn();
94
}
105
}
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
1-
// Regression test for https://github.com/rust-lang/rust/issues/107407
1+
// Regression test for https://github.com/rust-lang/rust/issues/107407 which
2+
// checks that rustc can read thin archive. Before the object crate added thin
3+
// archive support rustc would add emit object files to the staticlib and after
4+
// the object crate added thin archive support it would previously crash the
5+
// compiler due to a missing special case for thin archive members.
6+
use std::path::Path;
27

3-
use run_make_support::{llvm_ar, rustc, static_lib_name};
8+
use run_make_support::{llvm_ar, rust_lib_name, rustc, static_lib_name};
49

510
fn main() {
6-
rustc().input("simple_obj.rs").emit("obj").run();
7-
llvm_ar().obj_to_thin_ar().output_input(static_lib_name("thin_archive"), "simple_obj.o").run();
8-
rustc().input("rust_archive.rs").run();
9-
// Disable lld as it ignores the symbol table in the archive file.
10-
rustc()
11-
.input("bin.rs") /*.arg("-Zlinker-features=-lld")*/
11+
std::fs::create_dir("archive").unwrap();
12+
13+
// Build a thin archive
14+
rustc().input("simple_obj.rs").emit("obj").output("archive/simple_obj.o").run();
15+
llvm_ar()
16+
.obj_to_thin_ar()
17+
.output_input(
18+
Path::new("archive").join(static_lib_name("thin_archive")),
19+
"archive/simple_obj.o",
20+
)
1221
.run();
22+
23+
// Build an rlib which includes the members of this thin archive
24+
rustc().input("rust_lib.rs").library_search_path("archive").run();
25+
26+
// Build a binary which requires a symbol from the thin archive
27+
rustc().input("bin.rs").extern_("rust_lib", rust_lib_name("rust_lib")).run();
1328
}

tests/run-make/staticlib-thin-archive/rust_archive.rs

-4
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![crate_type = "rlib"]
2+
3+
#[link(name = "thin_archive", kind = "static")]
4+
extern "C" {
5+
pub fn simple_fn();
6+
}

0 commit comments

Comments
 (0)