Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse rlib #253

Closed
wants to merge 11 commits into from
Closed
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
256 changes: 128 additions & 128 deletions .github/workflows/check-and-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,134 +32,7 @@ jobs:
run: cargo fmt --all --check

- name: Native version of cargo-show-asm (Intel ASM)
run: cargo run -- --manifest-path sample/Cargo.toml --intel sample::main --rust

- name: Native version of cargo-show-asm (Intel ASM) + native CPU
run: cargo run -- --manifest-path sample/Cargo.toml --native --intel sample::main --rust

- name: Native version of cargo-show-asm (Intel ASM) + native CPU + no default features
run: cargo run -- -vvv --manifest-path sample/Cargo.toml --native --intel sample::main --rust --no-default-features

- name: Native version of cargo-show-asm (Intel ASM) + atom
run: cargo run -- --manifest-path sample/Cargo.toml --target-cpu atom --intel sample::main --rust

- name: Native version of cargo-show-asm with symbol mangling (Intel ASM)
run: cargo run -- --manifest-path sample/Cargo.toml --intel sample::main --rust --keep-mangled

- name: Native version of cargo-show-asm (LLVM)
run: cargo run -- --manifest-path sample/Cargo.toml --llvm sample::main

- name: Native version of cargo-show-asm with symbol mangling (LLVM)
run: cargo run -- --manifest-path sample/Cargo.toml --llvm --keep-mangled sample::main

- name: Native version of cargo-show-asm (LLVM Input)
run: cargo run -- --manifest-path sample/Cargo.toml --llvm-input sample::main

- name: Native version of cargo-show-asm (MIR)
run: cargo run -- --manifest-path sample/Cargo.toml --mir "main()"

- name: Crosscompiled version of cargo-show-asm (Intel ASM)
run: cargo run -- --manifest-path sample/Cargo.toml --intel sample::main --target armv7-unknown-linux-gnueabihf

- name: Rlib project, AT&T asm
run: cargo run -- --manifest-path sample_rlib/Cargo.toml --att

- name: cdylib project
run: cargo run -- --manifest-path sample_cdylib/Cargo.toml add

- name: cdylib project, underscore prefix
run: cargo run -- --manifest-path sample_cdylib/Cargo.toml _mul

windows:
runs-on: windows-latest
name: Tests on windows
steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Install rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
components: rustfmt clippy rust-src
targets: armv7-unknown-linux-gnueabihf

- name: Build all the things
run: cargo build --tests

- name: Run unit tests
run: cargo test --all-features

- name: Clippy
run: cargo clippy -- -D clippy::disallowed_macros

- name: Check formatting
run: cargo fmt --all --check

- name: Native version of cargo-show-asm (Intel ASM)
run: cargo run -- --manifest-path sample/Cargo.toml --intel sample::main --rust

- name: Native version of cargo-show-asm (Intel ASM) + native CPU
run: cargo run -- --manifest-path sample/Cargo.toml --native --intel sample::main --rust

- name: Native version of cargo-show-asm (Intel ASM) + native CPU + no default features
run: cargo run -- -vvv --manifest-path sample/Cargo.toml --native --intel sample::main --rust --no-default-features

- name: Native version of cargo-show-asm (Intel ASM) + atom
run: cargo run -- --manifest-path sample/Cargo.toml --target-cpu atom --intel sample::main --rust

- name: Native version of cargo-show-asm with symbol mangling (Intel ASM)
run: cargo run -- --manifest-path sample/Cargo.toml --intel sample::main --rust --keep-mangled

- name: Native version of cargo-show-asm (LLVM)
run: cargo run -- --manifest-path sample/Cargo.toml --llvm sample::main

- name: Native version of cargo-show-asm with symbol mangling (LLVM)
run: cargo run -- --manifest-path sample/Cargo.toml --llvm --keep-mangled sample::main

- name: Native version of cargo-show-asm (LLVM Input)
run: cargo run -- --manifest-path sample/Cargo.toml --llvm-input sample::main

- name: Native version of cargo-show-asm (MIR)
run: cargo run -- --manifest-path sample/Cargo.toml --mir "main()"

- name: Crosscompiled version of cargo-show-asm (Intel ASM)
run: cargo run -- --manifest-path sample/Cargo.toml --intel sample::main --target armv7-unknown-linux-gnueabihf

- name: Rlib project, AT&T asm
run: cargo run -- --manifest-path sample_rlib/Cargo.toml --att

- name: cdylib project
run: cargo run -- --manifest-path sample_cdylib/Cargo.toml --everything

macos:
runs-on: macos-latest
name: Tests on MacOS
steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Install rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
components: rustfmt clippy rust-src
targets: armv7-unknown-linux-gnueabihf

- name: Build all the things
run: cargo build --tests

- name: Run unit tests
run: cargo test --all-features

- name: Clippy
run: cargo clippy -- -D clippy::disallowed_macros

- name: Check formatting
run: cargo fmt --all --check

- name: Native version of cargo-show-asm (Intel ASM)
run: cargo run -- --manifest-path sample/Cargo.toml --intel sample::main --rust
run: cargo run -- -vvv --manifest-path sample/Cargo.toml --intel sample::main --rust

- name: Native version of cargo-show-asm (Intel ASM) + native CPU
run: cargo run -- --manifest-path sample/Cargo.toml --native --intel sample::main --rust
Expand Down Expand Up @@ -196,3 +69,130 @@ jobs:

- name: cdylib project, underscore prefix
run: cargo run -- --manifest-path sample_cdylib/Cargo.toml _mul
#
# windows:
# runs-on: windows-latest
# name: Tests on windows
# steps:
# - name: Checkout repo
# uses: actions/checkout@v3
#
# - name: Install rust toolchain
# uses: dtolnay/rust-toolchain@stable
# with:
# toolchain: stable
# components: rustfmt clippy rust-src
# targets: armv7-unknown-linux-gnueabihf
#
# - name: Build all the things
# run: cargo build --tests
#
# - name: Run unit tests
# run: cargo test --all-features
#
# - name: Clippy
# run: cargo clippy -- -D clippy::disallowed_macros
#
# - name: Check formatting
# run: cargo fmt --all --check
#
# - name: Native version of cargo-show-asm (Intel ASM)
# run: cargo run -- --manifest-path sample/Cargo.toml --intel sample::main --rust
#
# - name: Native version of cargo-show-asm (Intel ASM) + native CPU
# run: cargo run -- --manifest-path sample/Cargo.toml --native --intel sample::main --rust
#
# - name: Native version of cargo-show-asm (Intel ASM) + native CPU + no default features
# run: cargo run -- -vvv --manifest-path sample/Cargo.toml --native --intel sample::main --rust --no-default-features
#
# - name: Native version of cargo-show-asm (Intel ASM) + atom
# run: cargo run -- --manifest-path sample/Cargo.toml --target-cpu atom --intel sample::main --rust
#
# - name: Native version of cargo-show-asm with symbol mangling (Intel ASM)
# run: cargo run -- --manifest-path sample/Cargo.toml --intel sample::main --rust --keep-mangled
#
# - name: Native version of cargo-show-asm (LLVM)
# run: cargo run -- --manifest-path sample/Cargo.toml --llvm sample::main
#
# - name: Native version of cargo-show-asm with symbol mangling (LLVM)
# run: cargo run -- --manifest-path sample/Cargo.toml --llvm --keep-mangled sample::main
#
# - name: Native version of cargo-show-asm (LLVM Input)
# run: cargo run -- --manifest-path sample/Cargo.toml --llvm-input sample::main
#
# - name: Native version of cargo-show-asm (MIR)
# run: cargo run -- --manifest-path sample/Cargo.toml --mir "main()"
#
# - name: Crosscompiled version of cargo-show-asm (Intel ASM)
# run: cargo run -- --manifest-path sample/Cargo.toml --intel sample::main --target armv7-unknown-linux-gnueabihf
#
# - name: Rlib project, AT&T asm
# run: cargo run -- --manifest-path sample_rlib/Cargo.toml --att
#
# - name: cdylib project
# run: cargo run -- --manifest-path sample_cdylib/Cargo.toml --everything
#
# macos:
# runs-on: macos-latest
# name: Tests on MacOS
# steps:
# - name: Checkout repo
# uses: actions/checkout@v3
#
# - name: Install rust toolchain
# uses: dtolnay/rust-toolchain@stable
# with:
# toolchain: stable
# components: rustfmt clippy rust-src
# targets: armv7-unknown-linux-gnueabihf
#
# - name: Build all the things
# run: cargo build --tests
#
# - name: Run unit tests
# run: cargo test --all-features
#
# - name: Clippy
# run: cargo clippy -- -D clippy::disallowed_macros
#
# - name: Check formatting
# run: cargo fmt --all --check
#
# - name: Native version of cargo-show-asm (Intel ASM)
# run: cargo run -- --manifest-path sample/Cargo.toml --intel sample::main --rust
#
# - name: Native version of cargo-show-asm (Intel ASM) + native CPU
# run: cargo run -- --manifest-path sample/Cargo.toml --native --intel sample::main --rust
#
# - name: Native version of cargo-show-asm (Intel ASM) + native CPU + no default features
# run: cargo run -- -vvv --manifest-path sample/Cargo.toml --native --intel sample::main --rust --no-default-features
#
# - name: Native version of cargo-show-asm (Intel ASM) + atom
# run: cargo run -- --manifest-path sample/Cargo.toml --target-cpu atom --intel sample::main --rust
#
# - name: Native version of cargo-show-asm with symbol mangling (Intel ASM)
# run: cargo run -- --manifest-path sample/Cargo.toml --intel sample::main --rust --keep-mangled
#
# - name: Native version of cargo-show-asm (LLVM)
# run: cargo run -- --manifest-path sample/Cargo.toml --llvm sample::main
#
# - name: Native version of cargo-show-asm with symbol mangling (LLVM)
# run: cargo run -- --manifest-path sample/Cargo.toml --llvm --keep-mangled sample::main
#
# - name: Native version of cargo-show-asm (LLVM Input)
# run: cargo run -- --manifest-path sample/Cargo.toml --llvm-input sample::main
#
# - name: Native version of cargo-show-asm (MIR)
# run: cargo run -- --manifest-path sample/Cargo.toml --mir "main()"
#
# - name: Crosscompiled version of cargo-show-asm (Intel ASM)
# run: cargo run -- --manifest-path sample/Cargo.toml --intel sample::main --target armv7-unknown-linux-gnueabihf
#
# - name: Rlib project, AT&T asm
# run: cargo run -- --manifest-path sample_rlib/Cargo.toml --att
#
# - name: cdylib project
# run: cargo run -- --manifest-path sample_cdylib/Cargo.toml add
#
# - name: cdylib project, underscore prefix
# run: cargo run -- --manifest-path sample_cdylib/Cargo.toml _mul
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ rustc-demangle = "0.1"
same-file = "1.0.6"
supports-color = "3.0"
serde = "=1.0.195"
ar = "0.9.0"

[dev-dependencies]
bpaf = { version = "0.9.8", features = ["bpaf_derive", "autocomplete", "docgen"] }
Expand Down
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

## [0.2.31] - unreleased
- replace RPITIT with more consevative implementation

## [0.2.30] - 2024-02-11
- Add an option `-c` / `--context` to recursively include functions called from target as
additional context
Expand Down
4 changes: 1 addition & 3 deletions src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ impl RawLines for Statement<'_> {
/// try to print `goal` from `path`, collect available items otherwise
pub fn dump_function(
goal: ToDump,
path: &Path,
contents: String,
workspace: &Path,
sysroot: &Path,
fmt: &Format,
Expand All @@ -483,8 +483,6 @@ pub fn dump_function(
}

// For some reason llvm/rustc can produce non utf8 files...
let payload = std::fs::read(path)?;
let contents = String::from_utf8_lossy(&payload).into_owned();

let statements = parse_file(&contents)?;
let functions = find_items(&statements);
Expand Down
11 changes: 6 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::{

use crate::cached_lines::CachedLines;
use opts::{Format, NameDisplay, ToDump};
use std::path::Path;

pub mod asm;
pub mod cached_lines;
Expand All @@ -16,6 +15,7 @@ pub mod llvm;
pub mod mca;
pub mod mir;
pub mod opts;
pub mod rlib;

#[macro_export]
macro_rules! color {
Expand Down Expand Up @@ -265,10 +265,11 @@ pub trait Dumpable {
///
/// # Errors
/// Reports file IO errors
pub fn dump_function<T: Dumpable>(goal: ToDump, path: &Path, fmt: &Format) -> anyhow::Result<()> {
// For some reason llvm/rustc can produce non utf8 files...
let payload = std::fs::read(path)?;
let contents = String::from_utf8_lossy(&payload).into_owned();
pub fn dump_function<T: Dumpable>(
goal: ToDump,
contents: String,
fmt: &Format,
) -> anyhow::Result<()> {
let lines = CachedLines::without_ending(contents);
let items = T::find_items(&lines);
let strs = lines.iter().collect::<Vec<_>>();
Expand Down
Loading
Loading