Skip to content

Commit

Permalink
Auto merge of #126534 - Rejyr:comment-section-migration, r=<try>
Browse files Browse the repository at this point in the history
Migrate `run-make/comment-section` to `rmake.rs`

Part of #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
  • Loading branch information
bors committed Jun 16, 2024
2 parents 55cac26 + 12d8ccf commit 7fa8271
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 24 deletions.
28 changes: 23 additions & 5 deletions src/tools/run-make-support/src/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::path::{Path, PathBuf};

use crate::{env_var, Command};

/// Construct a new `llvm-readobj` invocation. This assumes that `llvm-readobj` is available
/// at `$LLVM_BIN_DIR/llvm-readobj`.
/// Construct a new `llvm-readobj` invocation with the `GNU` output style.
/// This assumes that `llvm-readobj` is available at `$LLVM_BIN_DIR/llvm-readobj`.
pub fn llvm_readobj() -> LlvmReadobj {
LlvmReadobj::new()
}
Expand Down Expand Up @@ -53,12 +53,23 @@ pub fn llvm_bin_dir() -> PathBuf {
}

impl LlvmReadobj {
/// Construct a new `llvm-readobj` invocation. This assumes that `llvm-readobj` is available
/// at `$LLVM_BIN_DIR/llvm-readobj`.
/// Construct a new `llvm-readobj` invocation with the `GNU` output style.
/// This assumes that `llvm-readobj` is available at `$LLVM_BIN_DIR/llvm-readobj`.
pub fn new() -> Self {
let llvm_readobj = llvm_bin_dir().join("llvm-readobj");
let cmd = Command::new(llvm_readobj);
Self { cmd }
let mut readobj = Self { cmd };
readobj.elf_output_style("GNU");
readobj
}

/// Specify the format of the ELF information.
///
/// Valid options are `LLVM` (default), `GNU`, and `JSON`.
pub fn elf_output_style(&mut self, style: &str) -> &mut Self {
self.cmd.arg("--elf-output-style");
self.cmd.arg(style);
self
}

/// Provide an input file.
Expand All @@ -72,6 +83,13 @@ impl LlvmReadobj {
self.cmd.arg("--file-header");
self
}

/// Specify the section to display.
pub fn section(&mut self, section: &str) -> &mut Self {
self.cmd.arg("--string-dump");
self.cmd.arg(section);
self
}
}

impl LlvmProfdata {
Expand Down
1 change: 0 additions & 1 deletion src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ run-make/c-unwind-abi-catch-panic/Makefile
run-make/cat-and-grep-sanity-check/Makefile
run-make/cdylib-dylib-linkage/Makefile
run-make/cdylib-fewer-symbols/Makefile
run-make/comment-section/Makefile
run-make/compiler-lookup-paths-2/Makefile
run-make/compiler-lookup-paths/Makefile
run-make/compiler-rt-works-on-mingw/Makefile
Expand Down
18 changes: 0 additions & 18 deletions tests/run-make/comment-section/Makefile

This file was deleted.

45 changes: 45 additions & 0 deletions tests/run-make/comment-section/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Both GCC and Clang write by default a `.comment` section with compiler information.
// Rustc received a similar .comment section, so this tests checks that this section
// properly appears.
// See https://github.com/rust-lang/rust/commit/74b8d324eb77a8f337b35dc68ac91b0c2c06debc

//@ only-linux

use std::path::PathBuf;

use run_make_support::llvm_readobj;
use run_make_support::rustc;
use run_make_support::{cwd, env_var, read_dir, run_in_tmpdir};

fn main() {
let target = env_var("TARGET");

rustc()
.arg("-")
.stdin("fn main() {}")
.emit("link,obj")
.arg("-Csave-temps")
.target(&target)
.run();

// Check linked output has a `.comment` section with the expected content.
llvm_readobj()
.section(".comment")
.input("rust_out")
.run()
.assert_stdout_contains("rustc version 1.");

// Check all object files (including temporary outputs) have a `.comment`
// section with the expected content.
read_dir(cwd(), |f| {
if !f.extension().is_some_and(|ext| ext == "o") {
return;
}

llvm_readobj()
.section(".comment")
.input(&f)
.run()
.assert_stdout_contains("rustc version 1.");
});
}

0 comments on commit 7fa8271

Please sign in to comment.