Skip to content

Commit

Permalink
use llvm_readobj in run-make test instead of nm
Browse files Browse the repository at this point in the history
  • Loading branch information
Oneirical committed Jun 18, 2024
1 parent c1597f9 commit 977d3f6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 63 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`.
#[track_caller]
pub fn llvm_readobj() -> LlvmReadobj {
LlvmReadobj::new()
Expand Down Expand Up @@ -70,13 +70,24 @@ 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`.
#[track_caller]
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 @@ -90,6 +101,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
50 changes: 0 additions & 50 deletions src/tools/run-make-support/src/nm/mod.rs

This file was deleted.

13 changes: 5 additions & 8 deletions tests/run-make/bin-emit-no-symbols/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
// emitted inside the object files.
// See https://github.com/rust-lang/rust/issues/51671

use run_make_support::{nm, rustc, tmp_dir};
use run_make_support::{llvm_readobj, rustc};

fn main() {
rustc().emit("obj").input("app.rs").run();
//FIXME(Oneirical): This should eventually be rmake_out_path
let nm = nm(tmp_dir().join("app.o"));
assert!(
nm.contains("rust_begin_unwind")
&& nm.contains("rust_eh_personality")
&& nm.contains("__rg_oom")
);
let out = llvm_readobj().input("app.o").arg("--symbols").run();
out.assert_stdout_contains("rust_begin_unwind");
out.assert_stdout_contains("rust_eh_personality");
out.assert_stdout_contains("__rg_oom");
}

0 comments on commit 977d3f6

Please sign in to comment.