Skip to content

Commit 4c7c97a

Browse files
Fix loading large rlibs
Bumps object crate to permit parsing archives with 64-bit table entries. These are primarily encountered when there's more than 4GB of archive data.
1 parent 4a6547c commit 4c7c97a

File tree

5 files changed

+79
-3
lines changed

5 files changed

+79
-3
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2297,9 +2297,9 @@ dependencies = [
22972297

22982298
[[package]]
22992299
name = "object"
2300-
version = "0.26.1"
2300+
version = "0.26.2"
23012301
source = "registry+https://github.com/rust-lang/crates.io-index"
2302-
checksum = "ee2766204889d09937d00bfbb7fec56bb2a199e2ade963cab19185d8a6104c7c"
2302+
checksum = "39f37e50073ccad23b6d09bcb5b263f4e76d3bb6038e4a3c08e52162ffa8abc2"
23032303
dependencies = [
23042304
"compiler_builtins",
23052305
"crc32fast",

compiler/rustc_codegen_ssa/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ rustc_target = { path = "../rustc_target" }
3636
rustc_session = { path = "../rustc_session" }
3737

3838
[dependencies.object]
39-
version = "0.26.1"
39+
version = "0.26.2"
4040
default-features = false
4141
features = ["read_core", "elf", "macho", "pe", "unaligned", "archive", "write"]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-include ../../run-make-fulldeps/tools.mk
2+
3+
all:
4+
$(RUSTC) main.rs
5+
$(TMPDIR)/main $(TMPDIR)
6+
$(RUSTC) $(TMPDIR)/foo.rs --crate-type=rlib -l static=foo -L$(TMPDIR)
7+
RUSTC_LOG=rustc_metadata=debug $(RUSTC) bar.rs --extern foo=$(TMPDIR)/libfoo.rlib --edition=2018
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn main() {
2+
unsafe {
3+
println!("{}", foo::FOO_11_49[0]);
4+
}
5+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//! Large archive example.
2+
//!
3+
//! This creates several C files with a bunch of global arrays. The goal is to
4+
//! create an rlib that is over 4GB in size so that the LLVM archiver creates
5+
//! a /SYM64/ entry instead of /.
6+
//!
7+
//! It compiles the C files to .o files, and then uses `ar` to collect them
8+
//! into a static library. It creates `foo.rs` with references to all the C
9+
//! arrays, and then uses `rustc` to build an rlib with that static
10+
//! information. It then creates `bar.rs` which links the giant libfoo.rlib,
11+
//! which should fail since it can't read the large libfoo.rlib file.
12+
13+
use std::env;
14+
use std::fs::File;
15+
use std::io::{BufWriter, Write};
16+
use std::process::Command;
17+
18+
// Number of object files to create.
19+
const NOBJ: u32 = 12;
20+
// Make the filename longer than 16 characters to force names to be placed in //
21+
const PREFIX: &str = "abcdefghijklmnopqrstuvwxyz";
22+
23+
fn main() {
24+
let tmpdir = std::path::PathBuf::from(env::args_os().nth(1).unwrap());
25+
let mut foo_rs = File::create(tmpdir.join("foo.rs")).unwrap();
26+
write!(foo_rs, "extern \"C\" {{\n").unwrap();
27+
for obj in 0..NOBJ {
28+
let filename = tmpdir.join(&format!("{}{}.c", PREFIX, obj));
29+
let f = File::create(&filename).unwrap();
30+
let mut buf = BufWriter::new(f);
31+
write!(buf, "#include<stdint.h>\n").unwrap();
32+
for n in 0..50 {
33+
write!(buf, "int64_t FOO_{}_{}[] = {{\n", obj, n).unwrap();
34+
for x in 0..1024 {
35+
for y in 0..1024 {
36+
write!(buf, "{},", (obj + n + x + y) % 10).unwrap();
37+
}
38+
write!(buf, "\n").unwrap();
39+
}
40+
write!(buf, "}};\n").unwrap();
41+
write!(foo_rs, " pub static FOO_{}_{}: [i64; 1024*1024];\n", obj, n).unwrap();
42+
}
43+
drop(buf);
44+
println!("compile {:?}", filename);
45+
let status =
46+
Command::new("cc").current_dir(&tmpdir).arg("-c").arg(&filename).status().unwrap();
47+
if !status.success() {
48+
panic!("failed: {:?}", status);
49+
}
50+
}
51+
write!(foo_rs, "}}\n").unwrap();
52+
drop(foo_rs);
53+
let mut cmd = Command::new("ar");
54+
cmd.arg("-crs");
55+
cmd.arg(tmpdir.join("libfoo.a"));
56+
for obj in 0..NOBJ {
57+
cmd.arg(tmpdir.join(&format!("{}{}.o", PREFIX, obj)));
58+
}
59+
println!("archiving: {:?}", cmd);
60+
let status = cmd.status().unwrap();
61+
if !status.success() {
62+
panic!("failed: {:?}", status);
63+
}
64+
}

0 commit comments

Comments
 (0)