From 4c7c97a2087fc66e6a6d105b01877b5407a8a7cd Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Mon, 30 Aug 2021 16:10:19 -0400 Subject: [PATCH 1/2] 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. --- Cargo.lock | 4 +- compiler/rustc_codegen_ssa/Cargo.toml | 2 +- .../run-make/issue-88351-large-rlib/Makefile | 7 ++ .../run-make/issue-88351-large-rlib/bar.rs | 5 ++ .../run-make/issue-88351-large-rlib/main.rs | 64 +++++++++++++++++++ 5 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 src/test/run-make/issue-88351-large-rlib/Makefile create mode 100644 src/test/run-make/issue-88351-large-rlib/bar.rs create mode 100644 src/test/run-make/issue-88351-large-rlib/main.rs diff --git a/Cargo.lock b/Cargo.lock index cef4f11da80..a586cfc1082 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2297,9 +2297,9 @@ dependencies = [ [[package]] name = "object" -version = "0.26.1" +version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee2766204889d09937d00bfbb7fec56bb2a199e2ade963cab19185d8a6104c7c" +checksum = "39f37e50073ccad23b6d09bcb5b263f4e76d3bb6038e4a3c08e52162ffa8abc2" dependencies = [ "compiler_builtins", "crc32fast", diff --git a/compiler/rustc_codegen_ssa/Cargo.toml b/compiler/rustc_codegen_ssa/Cargo.toml index 930b4dc4d41..1446624b881 100644 --- a/compiler/rustc_codegen_ssa/Cargo.toml +++ b/compiler/rustc_codegen_ssa/Cargo.toml @@ -36,6 +36,6 @@ rustc_target = { path = "../rustc_target" } rustc_session = { path = "../rustc_session" } [dependencies.object] -version = "0.26.1" +version = "0.26.2" default-features = false features = ["read_core", "elf", "macho", "pe", "unaligned", "archive", "write"] diff --git a/src/test/run-make/issue-88351-large-rlib/Makefile b/src/test/run-make/issue-88351-large-rlib/Makefile new file mode 100644 index 00000000000..98938e5ebc4 --- /dev/null +++ b/src/test/run-make/issue-88351-large-rlib/Makefile @@ -0,0 +1,7 @@ +-include ../../run-make-fulldeps/tools.mk + +all: + $(RUSTC) main.rs + $(TMPDIR)/main $(TMPDIR) + $(RUSTC) $(TMPDIR)/foo.rs --crate-type=rlib -l static=foo -L$(TMPDIR) + RUSTC_LOG=rustc_metadata=debug $(RUSTC) bar.rs --extern foo=$(TMPDIR)/libfoo.rlib --edition=2018 diff --git a/src/test/run-make/issue-88351-large-rlib/bar.rs b/src/test/run-make/issue-88351-large-rlib/bar.rs new file mode 100644 index 00000000000..1b600036490 --- /dev/null +++ b/src/test/run-make/issue-88351-large-rlib/bar.rs @@ -0,0 +1,5 @@ +fn main() { + unsafe { + println!("{}", foo::FOO_11_49[0]); + } +} diff --git a/src/test/run-make/issue-88351-large-rlib/main.rs b/src/test/run-make/issue-88351-large-rlib/main.rs new file mode 100644 index 00000000000..f97830f3d86 --- /dev/null +++ b/src/test/run-make/issue-88351-large-rlib/main.rs @@ -0,0 +1,64 @@ +//! Large archive example. +//! +//! This creates several C files with a bunch of global arrays. The goal is to +//! create an rlib that is over 4GB in size so that the LLVM archiver creates +//! a /SYM64/ entry instead of /. +//! +//! It compiles the C files to .o files, and then uses `ar` to collect them +//! into a static library. It creates `foo.rs` with references to all the C +//! arrays, and then uses `rustc` to build an rlib with that static +//! information. It then creates `bar.rs` which links the giant libfoo.rlib, +//! which should fail since it can't read the large libfoo.rlib file. + +use std::env; +use std::fs::File; +use std::io::{BufWriter, Write}; +use std::process::Command; + +// Number of object files to create. +const NOBJ: u32 = 12; +// Make the filename longer than 16 characters to force names to be placed in // +const PREFIX: &str = "abcdefghijklmnopqrstuvwxyz"; + +fn main() { + let tmpdir = std::path::PathBuf::from(env::args_os().nth(1).unwrap()); + let mut foo_rs = File::create(tmpdir.join("foo.rs")).unwrap(); + write!(foo_rs, "extern \"C\" {{\n").unwrap(); + for obj in 0..NOBJ { + let filename = tmpdir.join(&format!("{}{}.c", PREFIX, obj)); + let f = File::create(&filename).unwrap(); + let mut buf = BufWriter::new(f); + write!(buf, "#include\n").unwrap(); + for n in 0..50 { + write!(buf, "int64_t FOO_{}_{}[] = {{\n", obj, n).unwrap(); + for x in 0..1024 { + for y in 0..1024 { + write!(buf, "{},", (obj + n + x + y) % 10).unwrap(); + } + write!(buf, "\n").unwrap(); + } + write!(buf, "}};\n").unwrap(); + write!(foo_rs, " pub static FOO_{}_{}: [i64; 1024*1024];\n", obj, n).unwrap(); + } + drop(buf); + println!("compile {:?}", filename); + let status = + Command::new("cc").current_dir(&tmpdir).arg("-c").arg(&filename).status().unwrap(); + if !status.success() { + panic!("failed: {:?}", status); + } + } + write!(foo_rs, "}}\n").unwrap(); + drop(foo_rs); + let mut cmd = Command::new("ar"); + cmd.arg("-crs"); + cmd.arg(tmpdir.join("libfoo.a")); + for obj in 0..NOBJ { + cmd.arg(tmpdir.join(&format!("{}{}.o", PREFIX, obj))); + } + println!("archiving: {:?}", cmd); + let status = cmd.status().unwrap(); + if !status.success() { + panic!("failed: {:?}", status); + } +} From 84df1edad3f7fd7e410869616c68f4b5f8f882fb Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Tue, 31 Aug 2021 10:20:49 -0400 Subject: [PATCH 2/2] Delete long-running large rlibs test This is kept to a separate commit so that the test itself is preserved in the commit history. --- .../run-make/issue-88351-large-rlib/Makefile | 7 -- .../run-make/issue-88351-large-rlib/bar.rs | 5 -- .../run-make/issue-88351-large-rlib/main.rs | 64 ------------------- 3 files changed, 76 deletions(-) delete mode 100644 src/test/run-make/issue-88351-large-rlib/Makefile delete mode 100644 src/test/run-make/issue-88351-large-rlib/bar.rs delete mode 100644 src/test/run-make/issue-88351-large-rlib/main.rs diff --git a/src/test/run-make/issue-88351-large-rlib/Makefile b/src/test/run-make/issue-88351-large-rlib/Makefile deleted file mode 100644 index 98938e5ebc4..00000000000 --- a/src/test/run-make/issue-88351-large-rlib/Makefile +++ /dev/null @@ -1,7 +0,0 @@ --include ../../run-make-fulldeps/tools.mk - -all: - $(RUSTC) main.rs - $(TMPDIR)/main $(TMPDIR) - $(RUSTC) $(TMPDIR)/foo.rs --crate-type=rlib -l static=foo -L$(TMPDIR) - RUSTC_LOG=rustc_metadata=debug $(RUSTC) bar.rs --extern foo=$(TMPDIR)/libfoo.rlib --edition=2018 diff --git a/src/test/run-make/issue-88351-large-rlib/bar.rs b/src/test/run-make/issue-88351-large-rlib/bar.rs deleted file mode 100644 index 1b600036490..00000000000 --- a/src/test/run-make/issue-88351-large-rlib/bar.rs +++ /dev/null @@ -1,5 +0,0 @@ -fn main() { - unsafe { - println!("{}", foo::FOO_11_49[0]); - } -} diff --git a/src/test/run-make/issue-88351-large-rlib/main.rs b/src/test/run-make/issue-88351-large-rlib/main.rs deleted file mode 100644 index f97830f3d86..00000000000 --- a/src/test/run-make/issue-88351-large-rlib/main.rs +++ /dev/null @@ -1,64 +0,0 @@ -//! Large archive example. -//! -//! This creates several C files with a bunch of global arrays. The goal is to -//! create an rlib that is over 4GB in size so that the LLVM archiver creates -//! a /SYM64/ entry instead of /. -//! -//! It compiles the C files to .o files, and then uses `ar` to collect them -//! into a static library. It creates `foo.rs` with references to all the C -//! arrays, and then uses `rustc` to build an rlib with that static -//! information. It then creates `bar.rs` which links the giant libfoo.rlib, -//! which should fail since it can't read the large libfoo.rlib file. - -use std::env; -use std::fs::File; -use std::io::{BufWriter, Write}; -use std::process::Command; - -// Number of object files to create. -const NOBJ: u32 = 12; -// Make the filename longer than 16 characters to force names to be placed in // -const PREFIX: &str = "abcdefghijklmnopqrstuvwxyz"; - -fn main() { - let tmpdir = std::path::PathBuf::from(env::args_os().nth(1).unwrap()); - let mut foo_rs = File::create(tmpdir.join("foo.rs")).unwrap(); - write!(foo_rs, "extern \"C\" {{\n").unwrap(); - for obj in 0..NOBJ { - let filename = tmpdir.join(&format!("{}{}.c", PREFIX, obj)); - let f = File::create(&filename).unwrap(); - let mut buf = BufWriter::new(f); - write!(buf, "#include\n").unwrap(); - for n in 0..50 { - write!(buf, "int64_t FOO_{}_{}[] = {{\n", obj, n).unwrap(); - for x in 0..1024 { - for y in 0..1024 { - write!(buf, "{},", (obj + n + x + y) % 10).unwrap(); - } - write!(buf, "\n").unwrap(); - } - write!(buf, "}};\n").unwrap(); - write!(foo_rs, " pub static FOO_{}_{}: [i64; 1024*1024];\n", obj, n).unwrap(); - } - drop(buf); - println!("compile {:?}", filename); - let status = - Command::new("cc").current_dir(&tmpdir).arg("-c").arg(&filename).status().unwrap(); - if !status.success() { - panic!("failed: {:?}", status); - } - } - write!(foo_rs, "}}\n").unwrap(); - drop(foo_rs); - let mut cmd = Command::new("ar"); - cmd.arg("-crs"); - cmd.arg(tmpdir.join("libfoo.a")); - for obj in 0..NOBJ { - cmd.arg(tmpdir.join(&format!("{}{}.o", PREFIX, obj))); - } - println!("archiving: {:?}", cmd); - let status = cmd.status().unwrap(); - if !status.success() { - panic!("failed: {:?}", status); - } -}