Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/bin/cargo-readelf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const EXAMPLES: &str = "

EXAMPLES

`cargo readelf --bin app -- -t` - Display the section details
`cargo readelf --bin app -- -s` - Display the symbol table";

fn main() {
cargo_binutils::Tool::Readelf.cargo_exec(Some(EXAMPLES))
}
3 changes: 3 additions & 0 deletions src/bin/rust-readelf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
cargo_binutils::Tool::Readelf.rust_exec()
}
29 changes: 14 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ pub fn run(tool: Tool, matches: &ArgMatches) -> Result<i32> {
// make the artifact path relative. This makes the path that the
// tool will print easier to read. eg. `libfoo.rlib` instead of
// `/home/user/rust/project/target/$T/debug/libfoo.rlib`.
Tool::Objdump | Tool::Nm | Tool::Readobj | Tool::Size => {
Tool::Objdump | Tool::Nm | Tool::Readobj | Tool::Readelf | Tool::Size => {
lltool
.current_dir(file.parent().unwrap())
.arg(file.file_name().unwrap());
Expand Down Expand Up @@ -409,7 +409,9 @@ pub fn run(tool: Tool, matches: &ArgMatches) -> Result<i32> {
| Tool::Objcopy
| Tool::Profdata
| Tool::Strip => output.stdout.into(),
Tool::Nm | Tool::Objdump | Tool::Readobj => postprocess::demangle(&output.stdout),
Tool::Nm | Tool::Objdump | Tool::Readobj | Tool::Readelf => {
postprocess::demangle(&output.stdout)
}
Tool::Size => postprocess::size(&output.stdout),
};

Expand Down Expand Up @@ -448,22 +450,19 @@ fn cargo_build(matches: &ArgMatches, metadata: &Metadata) -> Result<Option<Artif
let mut target_artifact: Option<Artifact> = None;
for message in messages {
match message? {
Message::CompilerArtifact(artifact) => {
Message::CompilerArtifact(artifact)
if metadata.workspace_members.contains(&artifact.package_id)
&& build_type.matches(&artifact)
{
if target_artifact.is_some() {
bail!("Can only have one matching artifact but found several");
}

target_artifact = Some(artifact);
&& build_type.matches(&artifact) =>
{
if target_artifact.is_some() {
bail!("Can only have one matching artifact but found several");
}

target_artifact = Some(artifact);
}
Message::CompilerMessage(msg) => {
if !quiet || verbose > 1 {
if let Some(rendered) = msg.message.rendered {
eprint!("{rendered}");
}
Message::CompilerMessage(msg) if (!quiet || verbose > 1) => {
if let Some(rendered) = msg.message.rendered {
eprint!("{rendered}");
}
}
_ => (),
Expand Down
12 changes: 9 additions & 3 deletions src/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub enum Tool {
Objdump,
Profdata,
Readobj,
Readelf,
Size,
Strip,
}
Expand All @@ -35,6 +36,7 @@ impl Tool {
Self::Objdump => "objdump",
Self::Profdata => "profdata",
Self::Readobj => "readobj",
Self::Readelf => "readelf",
Self::Size => "size",
Self::Strip => "strip",
}
Expand Down Expand Up @@ -112,9 +114,13 @@ impl Tool {
pub const fn needs_build(self) -> bool {
match self {
Self::Ar | Self::As | Self::Cov | Self::Lld | Self::Profdata => false,
Self::Nm | Self::Objcopy | Self::Objdump | Self::Readobj | Self::Size | Self::Strip => {
true
}
Self::Nm
| Self::Objcopy
| Self::Objdump
| Self::Readobj
| Self::Readelf
| Self::Size
| Self::Strip => true,
}
}
}