Skip to content

Commit 739577d

Browse files
authored
Rollup merge of rust-lang#126534 - Rejyr:comment-section-migration, r=jieyouxu
Migrate `run-make/comment-section` to `rmake.rs` Part of rust-lang#121876. r? `@jieyouxu` try-job: dist-aarch64-linux try-job: dist-armhf-linux try-job: x86_64-gnu-llvm-18 try-job: test-various try-job: dist-various-1
2 parents 7f5442e + e601c8d commit 739577d

File tree

4 files changed

+68
-24
lines changed

4 files changed

+68
-24
lines changed

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

+23-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use std::path::{Path, PathBuf};
22

33
use crate::{env_var, Command};
44

5-
/// Construct a new `llvm-readobj` invocation. This assumes that `llvm-readobj` is available
6-
/// at `$LLVM_BIN_DIR/llvm-readobj`.
5+
/// Construct a new `llvm-readobj` invocation with the `GNU` output style.
6+
/// This assumes that `llvm-readobj` is available at `$LLVM_BIN_DIR/llvm-readobj`.
77
#[track_caller]
88
pub fn llvm_readobj() -> LlvmReadobj {
99
LlvmReadobj::new()
@@ -70,13 +70,24 @@ pub fn llvm_bin_dir() -> PathBuf {
7070
}
7171

7272
impl LlvmReadobj {
73-
/// Construct a new `llvm-readobj` invocation. This assumes that `llvm-readobj` is available
74-
/// at `$LLVM_BIN_DIR/llvm-readobj`.
73+
/// Construct a new `llvm-readobj` invocation with the `GNU` output style.
74+
/// This assumes that `llvm-readobj` is available at `$LLVM_BIN_DIR/llvm-readobj`.
7575
#[track_caller]
7676
pub fn new() -> Self {
7777
let llvm_readobj = llvm_bin_dir().join("llvm-readobj");
7878
let cmd = Command::new(llvm_readobj);
79-
Self { cmd }
79+
let mut readobj = Self { cmd };
80+
readobj.elf_output_style("GNU");
81+
readobj
82+
}
83+
84+
/// Specify the format of the ELF information.
85+
///
86+
/// Valid options are `LLVM` (default), `GNU`, and `JSON`.
87+
pub fn elf_output_style(&mut self, style: &str) -> &mut Self {
88+
self.cmd.arg("--elf-output-style");
89+
self.cmd.arg(style);
90+
self
8091
}
8192

8293
/// Provide an input file.
@@ -90,6 +101,13 @@ impl LlvmReadobj {
90101
self.cmd.arg("--file-header");
91102
self
92103
}
104+
105+
/// Specify the section to display.
106+
pub fn section(&mut self, section: &str) -> &mut Self {
107+
self.cmd.arg("--string-dump");
108+
self.cmd.arg(section);
109+
self
110+
}
93111
}
94112

95113
impl LlvmProfdata {

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ run-make/c-unwind-abi-catch-panic/Makefile
1111
run-make/cat-and-grep-sanity-check/Makefile
1212
run-make/cdylib-dylib-linkage/Makefile
1313
run-make/cdylib-fewer-symbols/Makefile
14-
run-make/comment-section/Makefile
1514
run-make/compiler-lookup-paths-2/Makefile
1615
run-make/compiler-lookup-paths/Makefile
1716
run-make/compiler-rt-works-on-mingw/Makefile

tests/run-make/comment-section/Makefile

-18
This file was deleted.
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Both GCC and Clang write by default a `.comment` section with compiler information.
2+
// Rustc received a similar .comment section, so this tests checks that this section
3+
// properly appears.
4+
// See https://github.com/rust-lang/rust/commit/74b8d324eb77a8f337b35dc68ac91b0c2c06debc
5+
6+
//@ only-linux
7+
8+
use std::path::PathBuf;
9+
10+
use run_make_support::llvm_readobj;
11+
use run_make_support::rustc;
12+
use run_make_support::{cwd, env_var, read_dir, run_in_tmpdir};
13+
14+
fn main() {
15+
let target = env_var("TARGET");
16+
17+
rustc()
18+
.arg("-")
19+
.stdin("fn main() {}")
20+
.emit("link,obj")
21+
.arg("-Csave-temps")
22+
.target(&target)
23+
.run();
24+
25+
// Check linked output has a `.comment` section with the expected content.
26+
llvm_readobj()
27+
.section(".comment")
28+
.input("rust_out")
29+
.run()
30+
.assert_stdout_contains("rustc version 1.");
31+
32+
// Check all object files (including temporary outputs) have a `.comment`
33+
// section with the expected content.
34+
read_dir(cwd(), |f| {
35+
if !f.extension().is_some_and(|ext| ext == "o") {
36+
return;
37+
}
38+
39+
llvm_readobj()
40+
.section(".comment")
41+
.input(&f)
42+
.run()
43+
.assert_stdout_contains("rustc version 1.");
44+
});
45+
}

0 commit comments

Comments
 (0)