Skip to content

Commit ff82e43

Browse files
committed
rewrite and rename issue-64153 to rmake.rs
1 parent f9515fd commit ff82e43

File tree

7 files changed

+69
-72
lines changed

7 files changed

+69
-72
lines changed

src/tools/run-make-support/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc};
3030
pub use clang::{clang, Clang};
3131
pub use diff::{diff, Diff};
3232
pub use llvm::{
33-
llvm_filecheck, llvm_profdata, llvm_readobj, LlvmFilecheck, LlvmProfdata, LlvmReadobj,
33+
llvm_filecheck, llvm_objdump, llvm_profdata, llvm_readobj, LlvmFilecheck, LlvmObjdump,
34+
LlvmProfdata, LlvmReadobj,
3435
};
3536
pub use run::{cmd, run, run_fail, run_with_args};
3637
pub use rustc::{aux_build, rustc, Rustc};

src/tools/run-make-support/src/llvm.rs

+30
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ pub fn llvm_filecheck() -> LlvmFilecheck {
2020
LlvmFilecheck::new()
2121
}
2222

23+
/// Construct a new `llvm-objdump` invocation. This assumes that `llvm-objdump` is available
24+
/// at `$LLVM_BIN_DIR/llvm-objdump`.
25+
pub fn llvm_objdump() -> LlvmObjdump {
26+
LlvmObjdump::new()
27+
}
28+
2329
/// A `llvm-readobj` invocation builder.
2430
#[derive(Debug)]
2531
#[must_use]
@@ -41,9 +47,17 @@ pub struct LlvmFilecheck {
4147
cmd: Command,
4248
}
4349

50+
/// A `llvm-objdump` invocation builder.
51+
#[derive(Debug)]
52+
#[must_use]
53+
pub struct LlvmObjdump {
54+
cmd: Command,
55+
}
56+
4457
crate::impl_common_helpers!(LlvmReadobj);
4558
crate::impl_common_helpers!(LlvmProfdata);
4659
crate::impl_common_helpers!(LlvmFilecheck);
60+
crate::impl_common_helpers!(LlvmObjdump);
4761

4862
/// Generate the path to the bin directory of LLVM.
4963
#[must_use]
@@ -125,3 +139,19 @@ impl LlvmFilecheck {
125139
self
126140
}
127141
}
142+
143+
impl LlvmObjdump {
144+
/// Construct a new `llvm-objdump` invocation. This assumes that `llvm-objdump` is available
145+
/// at `$LLVM_BIN_DIR/llvm-objdump`.
146+
pub fn new() -> Self {
147+
let llvm_objdump = llvm_bin_dir().join("llvm-objdump");
148+
let cmd = Command::new(llvm_objdump);
149+
Self { cmd }
150+
}
151+
152+
/// Provide an input file.
153+
pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
154+
self.cmd.arg(path.as_ref());
155+
self
156+
}
157+
}

src/tools/run-make-support/src/llvm_readobj.rs

-45
This file was deleted.

tests/run-make/issue-64153/Makefile

-26
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Staticlibs don't include Rust object files from upstream crates if the same
2+
// code was already pulled into the lib via LTO. However, the bug described in
3+
// https://github.com/rust-lang/rust/issues/64153 lead to this exclusion not
4+
// working properly if the upstream crate was compiled with an explicit filename
5+
// (via `-o`).
6+
7+
// This test makes sure that functions defined in the upstream crates do not
8+
// appear twice in the final staticlib when listing all the symbols from it.
9+
10+
//@ ignore-windows
11+
// Reason: `llvm-objdump`'s output looks different on windows than on other platforms.
12+
// Only checking on Unix platforms should suffice.
13+
14+
use run_make_support::{llvm_objdump, regex, rust_lib_name, rustc, static_lib_name};
15+
16+
fn main() {
17+
rustc()
18+
.crate_type("rlib")
19+
.input("upstream.rs")
20+
.output(rust_lib_name("upstream"))
21+
.codegen_units(1)
22+
.run();
23+
rustc()
24+
.crate_type("staticlib")
25+
.input("downstream.rs")
26+
.arg("-Clto")
27+
.output(static_lib_name("downstream"))
28+
.codegen_units(1)
29+
.run();
30+
let syms = llvm_objdump().arg("-t").input(static_lib_name("downstream")).run().stdout_utf8();
31+
let re = regex::Regex::new(r#"(?m)\s*g\s*F\s.*issue64153_test_function"#).unwrap();
32+
// Count the global instances of `issue64153_test_function`. There'll be 2
33+
// if the `upstream` object file got erroneously included twice.
34+
// The line we are testing for with the regex looks something like:
35+
// 0000000000000000 g F .text.issue64153_test_function 00000023 issue64153_test_function
36+
assert_eq!(re.find_iter(syms.as_str()).count(), 1);
37+
}

0 commit comments

Comments
 (0)