Skip to content

Commit bdf490b

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 d5290a3 commit bdf490b

File tree

5 files changed

+82
-6
lines changed

5 files changed

+82
-6
lines changed

Cargo.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,9 +2141,9 @@ dependencies = [
21412141

21422142
[[package]]
21432143
name = "memchr"
2144-
version = "2.4.0"
2144+
version = "2.4.1"
21452145
source = "registry+https://github.com/rust-lang/crates.io-index"
2146-
checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc"
2146+
checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
21472147

21482148
[[package]]
21492149
name = "memmap2"
@@ -2304,9 +2304,9 @@ dependencies = [
23042304

23052305
[[package]]
23062306
name = "object"
2307-
version = "0.25.2"
2307+
version = "0.26.2"
23082308
source = "registry+https://github.com/rust-lang/crates.io-index"
2309-
checksum = "f8bc1d42047cf336f0f939c99e97183cf31551bf0f2865a2ec9c8d91fd4ffb5e"
2309+
checksum = "39f37e50073ccad23b6d09bcb5b263f4e76d3bb6038e4a3c08e52162ffa8abc2"
23102310
dependencies = [
23112311
"crc32fast",
23122312
"indexmap",
@@ -3647,7 +3647,7 @@ dependencies = [
36473647
"itertools 0.9.0",
36483648
"jobserver",
36493649
"libc",
3650-
"object 0.25.2",
3650+
"object 0.26.2",
36513651
"pathdiff",
36523652
"rustc_apfloat",
36533653
"rustc_ast",

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.25.2"
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)