cargo-binutils-0.3.5/.cargo_vcs_info.json0000644000000001360000000000100137630ustar { "git": { "sha1": "4f79341b5f86af1cac983b3823c19c32a2361453" }, "path_in_vcs": "" }cargo-binutils-0.3.5/.github/CODEOWNERS000064400000000000000000000000260072674642500155340ustar 00000000000000* @rust-embedded/toolscargo-binutils-0.3.5/.github/bors.toml000064400000000000000000000005620072674642500160100ustar 00000000000000block_labels = ["needs-decision"] delete_merged_branches = true required_approvals = 1 status = [ "ci (1.46.0, ubuntu-latest, false)", "ci (1.46.0, macos-latest, false)", "ci (1.46.0, windows-latest, false)", "ci (stable, ubuntu-latest, false)", "ci (stable, macos-latest, false)", "ci (stable, windows-latest, false)", ] cargo-binutils-0.3.5/.github/workflows/ci.yml000064400000000000000000000033300072674642500173150ustar 00000000000000on: push: branches: [ staging, trying, master ] pull_request: name: Continuous integration jobs: ci: runs-on: ${{ matrix.os }} continue-on-error: ${{ matrix.experimental }} strategy: fail-fast: false matrix: rust: # MSRV - 1.46.0 - stable os: [ubuntu-latest, macos-latest, windows-latest] experimental: [false] include: - rust: nightly os: ubuntu-latest experimental: true steps: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: ${{ matrix.rust }} override: true components: llvm-tools-preview - name: Build and install cargo-binutils uses: actions-rs/cargo@v1 with: command: install args: --path . -f - name: Run cargo-nm uses: actions-rs/cargo@v1 with: command: nm args: --bin cargo-nm -- --undefined-only - name: Run cargo-objdump uses: actions-rs/cargo@v1 with: command: objdump args: --bin cargo-objdump -- -h - name: Run cargo-objcopy (on Linux only) if: matrix.os == 'ubuntu-latest' uses: actions-rs/cargo@v1 with: command: objcopy args: --bin cargo-objdump -v -- -O binary objdump.bin - name: Run cargo-size uses: actions-rs/cargo@v1 with: command: size args: --bin cargo-size -v - name: Run cargo-strip (on Linux only) if: matrix.os == 'ubuntu-latest' uses: actions-rs/cargo@v1 with: command: strip args: --bin cargo-strip -v cargo-binutils-0.3.5/.github/workflows/clippy.yml000064400000000000000000000006750072674642500202330ustar 00000000000000on: push: branches: [ staging, trying, master ] pull_request: name: Clippy check jobs: clippy_check: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: stable override: true components: clippy - uses: actions-rs/clippy-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }} cargo-binutils-0.3.5/.github/workflows/rustfmt.yml000064400000000000000000000007250072674642500204330ustar 00000000000000on: push: branches: [ staging, trying, master ] pull_request: name: Code formatting check jobs: fmt: name: Rustfmt runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: stable override: true components: rustfmt - uses: actions-rs/cargo@v1 with: command: fmt args: --all -- --check cargo-binutils-0.3.5/.gitignore000064400000000000000000000000420072674642500145670ustar 00000000000000**/*.rs.bk .#* /target Cargo.lock cargo-binutils-0.3.5/CHANGELOG.md000064400000000000000000000142460072674642500144230ustar 00000000000000# Change Log All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] ## [v0.3.5] - 2022-02-12 ### Added - Detect when llvm-binutils haven't been installed and suggest installing them (#116) ### Changed - Fix syntax of some examples to use two dashes for arguments to binutils (#114, #115) ## [v0.3.4] - 2021-11-16 ### Fixed - Fix arch-name argument which now uses an equals sign (#108) ### Changed - MSRV bumped to 1.46 ## [v0.3.3] - 2020-11-17 ### Added - rust-cov / `cargo cov` - proxy for `llvm-cov` used in combination with `profdata` for Rust LLVM InstrProf-based source code coverage analysis. ## [v0.3.2] - 2020-10-13 ### Fixed - Pass options to LLVM tools with 2 hyphens to stay compatible with latest Rust versions ### Changed - Squelch compiler warnings when `--quiet` is specified ## [v0.3.1] - 2020-07-30 ### Fixed - Fixed confusion caused by `build.rs` in the project generating an virtual artifact resulting in `error: Can only have one matching artifact but found several` ### Changed - Allow the combination of `--features` `--no-default-features` and `--all-features` flags ## [v0.3.0] - 2020-05-28 ### Added - Added `--quiet` and `--color` arguments to be passed to `cargo build` - Added `--test` and `--bench` build arguments to allow targeting testing artifacts - Added `--package` argument so its possible to specify a target package in a workspace - Added `--no-default-features` cargo argument support - Added `--profile` argument to allow specifying the profile to build the target package with - Added `--frozen`, `--locked`, `--offline` cargo argument support - Added `-Z` argument to allow use of unstable cargo features ### Fixed - Fixed handling of `--lib` argument to reflect how its used with `cargo build` - Fixed `--` argument handling to ensure argument validation - Fixed `--lib` to be able to support `lib`, `rlib`, `dylib`, `cdylib`, etc. - Fixed panic due to broken pipe, caused by `bail!` while `cargo build` is running. Additionally fixes broken output format due to interrupted stderr output from `cargo build` - Fixed `rust-*` binaries exiting with exit code 0 if the tool was not found - Fixed `cargo build` running for `cargo profdata` when its not required - Fixed `--features` not allowing multiple ### Changed - Changed help output to more closely reflect the help command of `cargo` subcommands - Removed `walkdir` dependency by using expected path to tool executable - Updated `cargo_metadata 0.9 -> 0.10` - Replaced `failure` dependency with [`anyhow`](https://github.com/dtolnay/anyhow) - Allowed multiple levels of verbosity and verbose cargo output via `-vv` and `-vvv` ## [v0.2.0] - 2020-04-11 ### Added - Implement the typical cargo behaviour to determine an artifact to use if none was explictly specified ### Changed - Use edition 2018 and bump some dependencies - Compare artifact against the requested artifact instead of package name - Use `cargo-metadata` instead of `cargo-project` (potentially a **breaking change**) ## [v0.1.7] - 2019-11-15 ### Added - Add rust-* direct aliases to the llvm tools (e.g. rust-ar, rust-ld, rust-lld etc). ### Fixed - Fixed detection of workspaces (via cargo-project dependency) ## [v0.1.6] - 2018-12-18 ### Added - All the `cargo-$tool` subcommands that include a build step now accept the flags: `--features` and `--all-features`. These flags are passed as is to the `cargo build` command that these subcommands invoke. - This project now produces binary artifacts for each new release. You can find the binaries in the [releases] page. [releases]: https://github.com/rust-embedded/cargo-binutils/releases ## [v0.1.5] - 2018-10-28 ### Added - Path inference support for WASM binaries ### Fixed - Path inference on windows hosts ## [v0.1.4] - 2018-09-09 ### Fixed - `cargo-objdump` now produces appropriate output when disassembling for Thumb and PowerPC targets. - Cargo now respects the `build.target-dir` setting in `.cargo/config`. ## [v0.1.3] - 2018-09-01 ### Added - A `cargo-readobj` subcommand that proxies the `llvm-readobj` tool, which is similar to GNU's `readelf`. Note that this subcommand requires nightly from 2018-09-01 or newer. ## [v0.1.2] - 2018-08-28 ### Added - Build and inspect mode. Some tools don't require that the path to the artifact is passed as an argument in this mode. See README for more details. ### Fixed - `cargo-objdump`: More robust detection of the target architecture. The `riscv32imac-unknown-none-elf` is now properly supported. - More robust post processing. If the output of the LLVM tool can *not* be processed then the original output is shown instead of just showing an error message. ## [v0.1.1] - 2018-07-15 ### Added - `cargo-strip` subcommand ### Changed - The `llvm-tools` component was renamed to `llvm-tools-preview` ## v0.1.0 - 2018-06-28 Initial release [Unreleased]: https://github.com/rust-embedded/cargo-binutils/compare/v0.3.5...HEAD [v0.3.5]: https://github.com/rust-embedded/cargo-binutils/compare/v0.3.4...v0.3.5 [v0.3.4]: https://github.com/rust-embedded/cargo-binutils/compare/v0.3.3...v0.3.4 [v0.3.3]: https://github.com/rust-embedded/cargo-binutils/compare/v0.3.2...v0.3.3 [v0.3.2]: https://github.com/rust-embedded/cargo-binutils/compare/v0.3.1...v0.3.2 [v0.3.1]: https://github.com/rust-embedded/cargo-binutils/compare/v0.3.0...v0.3.1 [v0.3.0]: https://github.com/rust-embedded/cargo-binutils/compare/v0.2.0...v0.3.0 [v0.2.0]: https://github.com/rust-embedded/cargo-binutils/compare/v0.1.7...v0.2.0 [v0.1.7]: https://github.com/rust-embedded/cargo-binutils/compare/v0.1.6...v0.1.7 [v0.1.6]: https://github.com/rust-embedded/cargo-binutils/compare/v0.1.5...v0.1.6 [v0.1.5]: https://github.com/rust-embedded/cargo-binutils/compare/v0.1.4...v0.1.5 [v0.1.4]: https://github.com/rust-embedded/cargo-binutils/compare/v0.1.3...v0.1.4 [v0.1.3]: https://github.com/rust-embedded/cargo-binutils/compare/v0.1.2...v0.1.3 [v0.1.2]: https://github.com/rust-embedded/cargo-binutils/compare/v0.1.1...v0.1.2 [v0.1.1]: https://github.com/rust-embedded/cargo-binutils/compare/v0.1.0...v0.1.1 cargo-binutils-0.3.5/CODE_OF_CONDUCT.md000064400000000000000000000110020072674642500153740ustar 00000000000000# The Rust Code of Conduct ## Conduct **Contact**: [Resources team](https://github.com/rust-embedded/wg#the-resources-team) * We are committed to providing a friendly, safe and welcoming environment for all, regardless of level of experience, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, nationality, or other similar characteristic. * On IRC, please avoid using overtly sexual nicknames or other nicknames that might detract from a friendly, safe and welcoming environment for all. * Please be kind and courteous. There's no need to be mean or rude. * Respect that people have differences of opinion and that every design or implementation choice carries a trade-off and numerous costs. There is seldom a right answer. * Please keep unstructured critique to a minimum. If you have solid ideas you want to experiment with, make a fork and see how it works. * We will exclude you from interaction if you insult, demean or harass anyone. That is not welcome behavior. We interpret the term "harassment" as including the definition in the [Citizen Code of Conduct](http://citizencodeofconduct.org/); if you have any lack of clarity about what might be included in that concept, please read their definition. In particular, we don't tolerate behavior that excludes people in socially marginalized groups. * Private harassment is also unacceptable. No matter who you are, if you feel you have been or are being harassed or made uncomfortable by a community member, please contact one of the channel ops or any of the [Resources team][team] immediately. Whether you're a regular contributor or a newcomer, we care about making this community a safe place for you and we've got your back. * Likewise any spamming, trolling, flaming, baiting or other attention-stealing behavior is not welcome. ## Moderation These are the policies for upholding our community's standards of conduct. 1. Remarks that violate the Rust standards of conduct, including hateful, hurtful, oppressive, or exclusionary remarks, are not allowed. (Cursing is allowed, but never targeting another user, and never in a hateful manner.) 2. Remarks that moderators find inappropriate, whether listed in the code of conduct or not, are also not allowed. 3. Moderators will first respond to such remarks with a warning. 4. If the warning is unheeded, the user will be "kicked," i.e., kicked out of the communication channel to cool off. 5. If the user comes back and continues to make trouble, they will be banned, i.e., indefinitely excluded. 6. Moderators may choose at their discretion to un-ban the user if it was a first offense and they offer the offended party a genuine apology. 7. If a moderator bans someone and you think it was unjustified, please take it up with that moderator, or with a different moderator, **in private**. Complaints about bans in-channel are not allowed. 8. Moderators are held to a higher standard than other community members. If a moderator creates an inappropriate situation, they should expect less leeway than others. In the Rust community we strive to go the extra step to look out for each other. Don't just aim to be technically unimpeachable, try to be your best self. In particular, avoid flirting with offensive or sensitive issues, particularly if they're off-topic; this all too often leads to unnecessary fights, hurt feelings, and damaged trust; worse, it can drive people away from the community entirely. And if someone takes issue with something you said or did, resist the urge to be defensive. Just stop doing what it was they complained about and apologize. Even if you feel you were misinterpreted or unfairly accused, chances are good there was something you could've communicated better — remember that it's your responsibility to make your fellow Rustaceans comfortable. Everyone wants to get along and we are all here first and foremost because we want to talk about cool technology. You will find that people will be eager to assume good intent and forgive as long as you earn their trust. The enforcement policies listed above apply to all official embedded WG venues; including official IRC channels (#rust-embedded); GitHub repositories under rust-embedded; and all forums under rust-embedded.org (forum.rust-embedded.org). *Adapted from the [Node.js Policy on Trolling](http://blog.izs.me/post/30036893703/policy-on-trolling) as well as the [Contributor Covenant v1.3.0](https://www.contributor-covenant.org/version/1/3/0/).* [team]: https://github.com/rust-embedded/wg#the-resources-team cargo-binutils-0.3.5/Cargo.lock0000644000000247430000000000100117500ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. [[package]] name = "addr2line" version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b6a2d3371669ab3ca9797670853d61402b03d0b4b9ebf33d677dfa720203072" dependencies = [ "gimli", ] [[package]] name = "adler" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e" [[package]] name = "aho-corasick" version = "0.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "043164d8ba5c4c3035fec9bbee8647c0261d788f3474306f93bb65901cae0e86" dependencies = [ "memchr", ] [[package]] name = "ansi_term" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" dependencies = [ "winapi", ] [[package]] name = "anyhow" version = "1.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6b602bfe940d21c130f3895acd65221e8a61270debe89d628b9cb4e3ccb8569b" [[package]] name = "atty" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ "hermit-abi", "libc", "winapi", ] [[package]] name = "backtrace" version = "0.3.50" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46254cf2fdcdf1badb5934448c1bcbe046a56537b3987d96c51a7afc5d03f293" dependencies = [ "addr2line", "cfg-if", "libc", "miniz_oxide", "object", "rustc-demangle", ] [[package]] name = "bitflags" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] name = "cargo-binutils" version = "0.3.5" dependencies = [ "anyhow", "cargo_metadata", "clap", "regex", "rustc-cfg", "rustc-demangle", "rustc_version", "serde", "toml", ] [[package]] name = "cargo_metadata" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89fec17b16f1ac67908af82e47d0a90a7afd0e1827b181cd77504323d3263d35" dependencies = [ "semver 0.10.0", "serde", "serde_json", ] [[package]] name = "cfg-if" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" [[package]] name = "clap" version = "2.33.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bdfa80d47f954d53a35a64987ca1422f495b8d6483c0fe9f7117b36c2a792129" dependencies = [ "ansi_term", "atty", "bitflags", "strsim", "textwrap", "unicode-width", "vec_map", ] [[package]] name = "failure" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86" dependencies = [ "backtrace", "failure_derive", ] [[package]] name = "failure_derive" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4" dependencies = [ "proc-macro2", "quote", "syn", "synstructure", ] [[package]] name = "gimli" version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724" [[package]] name = "hermit-abi" version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3deed196b6e7f9e44a2ae8d94225d80302d81208b1bb673fd21fe634645c85a9" dependencies = [ "libc", ] [[package]] name = "itoa" version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" [[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" version = "0.2.74" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2f02823cf78b754822df5f7f268fb59822e7296276d3e069d8e8cb26a14bd10" [[package]] name = "memchr" version = "2.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" [[package]] name = "miniz_oxide" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be0f75932c1f6cfae3c04000e40114adf955636e19040f9c0a2c380702aa1c7f" dependencies = [ "adler", ] [[package]] name = "object" version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ab52be62400ca80aa00285d25253d7f7c437b7375c4de678f5405d3afe82ca5" [[package]] name = "proc-macro2" version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12" dependencies = [ "unicode-xid", ] [[package]] name = "quote" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" dependencies = [ "proc-macro2", ] [[package]] name = "regex" version = "1.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6" dependencies = [ "aho-corasick", "memchr", "regex-syntax", "thread_local", ] [[package]] name = "regex-syntax" version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8" [[package]] name = "rustc-cfg" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ad221fe7cd09334f8735dcc157b1178e343f43dfaefcd1b09d7fd4fc0921b6f" dependencies = [ "failure", ] [[package]] name = "rustc-demangle" version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" [[package]] name = "rustc_version" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" dependencies = [ "semver 0.9.0", ] [[package]] name = "ryu" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" [[package]] name = "semver" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" dependencies = [ "semver-parser", ] [[package]] name = "semver" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "394cec28fa623e00903caf7ba4fa6fb9a0e260280bb8cdbbba029611108a0190" dependencies = [ "semver-parser", "serde", ] [[package]] name = "semver-parser" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" version = "1.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5317f7588f0a5078ee60ef675ef96735a1442132dc645eb1d12c018620ed8cd3" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" version = "1.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a0be94b04690fbaed37cddffc5c134bf537c8e3329d53e982fe04c374978f8e" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "serde_json" version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "164eacbdb13512ec2745fb09d51fd5b22b0d65ed294a1dcf7285a360c80a675c" dependencies = [ "itoa", "ryu", "serde", ] [[package]] name = "strsim" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "syn" version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4cdb98bcb1f9d81d07b536179c269ea15999b5d14ea958196413869445bb5250" dependencies = [ "proc-macro2", "quote", "unicode-xid", ] [[package]] name = "synstructure" version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701" dependencies = [ "proc-macro2", "quote", "syn", "unicode-xid", ] [[package]] name = "textwrap" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" dependencies = [ "unicode-width", ] [[package]] name = "thread_local" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" dependencies = [ "lazy_static", ] [[package]] name = "toml" version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffc92d160b1eef40665be3a05630d003936a3bc7da7421277846c2613e92c71a" dependencies = [ "serde", ] [[package]] name = "unicode-width" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" [[package]] name = "unicode-xid" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" [[package]] name = "vec_map" version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" [[package]] name = "winapi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ "winapi-i686-pc-windows-gnu", "winapi-x86_64-pc-windows-gnu", ] [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" cargo-binutils-0.3.5/Cargo.toml0000644000000025660000000000100117720ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2018" name = "cargo-binutils" version = "0.3.5" authors = ["The Embedded WG Tools Team ", "Jorge Aparicio "] description = "Proxy for LLVM tools like llvm-nm, llvm-objdump and llvm-size" documentation = "https://github.com/rust-embedded/cargo-binutils#cargo-binutils" readme = "README.md" keywords = ["llvm", "size", "objdump", "nm"] categories = ["command-line-utilities", "development-tools"] license = "MIT OR Apache-2.0" repository = "https://github.com/rust-embedded/cargo-binutils/" [dependencies.anyhow] version = "1.0" [dependencies.cargo_metadata] version = "0.11" [dependencies.clap] version = "2.33" [dependencies.regex] version = "1.3" [dependencies.rustc-cfg] version = "0.4" [dependencies.rustc-demangle] version = "0.1" [dependencies.rustc_version] version = "0.2" [dependencies.serde] version = "1.0" [dependencies.toml] version = "0.5" cargo-binutils-0.3.5/Cargo.toml.orig000064400000000000000000000013470072674642500154770ustar 00000000000000[package] edition = "2018" authors = [ "The Embedded WG Tools Team ", "Jorge Aparicio ", ] categories = ["command-line-utilities", "development-tools"] description = "Proxy for LLVM tools like llvm-nm, llvm-objdump and llvm-size" documentation = "https://github.com/rust-embedded/cargo-binutils#cargo-binutils" keywords = ["llvm", "size", "objdump", "nm"] license = "MIT OR Apache-2.0" name = "cargo-binutils" readme = "README.md" repository = "https://github.com/rust-embedded/cargo-binutils/" version = "0.3.5" [dependencies] cargo_metadata = "0.11" clap = "2.33" regex = "1.3" rustc-cfg = "0.4" rustc-demangle = "0.1" rustc_version = "0.2" serde = "1.0" toml = "0.5" anyhow = "1.0" cargo-binutils-0.3.5/LICENSE-APACHE000064400000000000000000000251370072674642500145370ustar 00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. cargo-binutils-0.3.5/LICENSE-MIT000064400000000000000000000020420072674642500142350ustar 00000000000000Copyright (c) 2018 Jorge Aparicio Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. cargo-binutils-0.3.5/README.md000064400000000000000000000142340072674642500140660ustar 00000000000000# `cargo-binutils` > Cargo subcommands to invoke the LLVM tools shipped with the Rust toolchain **NOTE** This is **not** an official Rust project. This project is developed and maintained by the [Embedded WG Tools team][team]. ## Features - All Rust symbols in the output of the LLVM tools are automatically demangled. - No need to pass the path to the artifact as an argument if using the tool in "build and inspect" mode. ## Installation ``` console $ cargo install cargo-binutils $ rustup component add llvm-tools-preview ``` ## Usage This: ``` console $ rust-$tool ${args[@]} ``` is basically sugar for: ``` console $ $(find $(rustc --print sysroot) -name llvm-$tool) ${args[@]} ``` Apart from these `rust-*` tools, which are direct proxies for the llvm tools in the `llvm-tools-preview` component, the crate also provides some Cargo subcommands that will first build the project and then run the llvm tool on the output artifact. This: ``` console $ cargo size --example foo ``` is sugar for: ``` console $ cargo build --example foo $ rust-size target/examples/foo ``` These commands take similar options to `cargo build` and you can specify a specific binary with `--bin NAME`, an example with `--example NAME` or the default binary by not passing `--bin` or `--example`. In the case of `cargo-objdump` the architecture of the compilation target is passed as `-arch-name=$target` to `llvm-objdump`. `-arch-name` specifies to which architecture disassemble the object file to. You can get more information about the CLI of each tool by running `rust-$tool -help`. All the Cargo subcommands accept a `--verbose` / `-v` flag. In verbose mode the `rust-$tool` invocation will be printed to stderr. Build and inspect mode: Some subcommands accept the flags: `--bin`, `--example`, `--lib`, `--target` and `--release`. These can be used to make the subcommand first build the respective binary, example or library and have the path to the artifact be automatically passed to the LLVM tool. This mode only works when the subcommand is used from within a Cargo project. *Disclaimer* Note that `cargo-binutils` simply proxies the LLVM tools in the `llvm-tools-preview` component and the Rust project makes no guarantee about the availability and the CLI of these tools -- i.e. the availability and CLI of these tools may change as new Rust releases are made. ## Examples ### `nm` List all symbols in an executable ``` console $ cargo nm --release 0800040a T BusFault 0800040a T DebugMonitor 0800040a T DefaultHandler 0800065e T HardFault 0800040a T MemoryManagement 0800040a T NonMaskableInt 0800040a T PendSV 0800040c T Reset 0800040a T SVCall 0800040a T SysTick 0800040a T UsageFault 08000408 T UserHardFault 08000008 R __EXCEPTIONS 08000040 R __INTERRUPTS 08000004 R __RESET_VECTOR 08000000 R __STACK_START ``` List all symbols in an executable sorted by size (smallest first). ``` console $ cargo nm --release -- --print-size --size-sort 0800040a 00000002 T DefaultHandler 08000408 00000002 T UserHardFault 08000004 00000004 R __RESET_VECTOR 08000400 00000008 T main 08000008 00000038 R __EXCEPTIONS 0800040c 00000252 T Reset 08000040 000003c0 R __INTERRUPTS ``` ### `objcopy` Transform the output of Cargo (ELF) into binary format. ``` console $ cargo objcopy --release -- -O binary app.bin $ stat --printf="%s\n" app.bin 1642 ``` ### `objdump` Disassemble a binary. ``` console $ cargo objdump --release -- --disassemble --no-show-raw-insn target/thumbv7m-none-eabi/debug/app: file format ELF32-arm-little Disassembly of section .text: main: 8000400: push {r7, lr} 8000402: bl #608 8000406: b #-8 UserHardFault: 8000408: trap UsageFault: 800040a: trap Reset: 800040c: push.w {r4, r5, r6, r7, r8, lr} 8000410: movw r0, #0 8000414: movw r2, #0 8000418: movt r0, #8192 800041c: movt r2, #8192 (..) ``` ### `size` Print binary size in System V format ``` console $ cargo size --release -- -A -x target/thumbv7m-none-eabi/release/app : section size addr .vector_table 0x400 0x8000000 .text 0x26a 0x8000400 .rodata 0x2 0x800066a .data 0 0x20000000 .bss 0 0x20000000 .debug_str 0x107e 0 .debug_loc 0x3e2 0 .debug_abbrev 0x31b 0 .debug_info 0x19f9 0 .debug_ranges 0xe8 0 .debug_macinfo 0x1 0 .debug_pubnames 0x9ff 0 .debug_pubtypes 0x8dd 0 .ARM.attributes 0x2e 0 .debug_frame 0x6c 0 .debug_line 0x69b 0 .debug_aranges 0x40 0 Total 0x531a ``` ### `strip` Strip all symbols from the build artifact ``` console $ stat --printf="%s\n" target/release/hello 4094240 $ cargo-strip --release -- --strip-all -o smaller-hello $ stat --printf="%s\n" smaller-hello 424432 ``` ### `rust-lld` Provides a link to `lld`. Used to change the linker or providing a workaround if `-C linker-flavor` is not doing the job. `.cargo/config` ```toml [target.wasm32-unknown-unknown] linker = "rust-lld" ``` ## Minimum Supported Rust Version (MSRV) This crate is guaranteed to compile on stable Rust 1.46.0 and up. It *might* compile with older versions but that may change in any new patch release. ## License Licensed under either of - Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) - MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) at your option. ### Contribution Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. ## Code of Conduct Contribution to this crate is organized under the terms of the [Rust Code of Conduct][CoC], the maintainer of this crate, the [Embedded WG Tools team][team], promises to intervene to uphold that code of conduct. [CoC]: CODE_OF_CONDUCT.md [team]: https://github.com/rust-embedded/wg#the-tools-team cargo-binutils-0.3.5/src/bin/cargo-cov.rs000064400000000000000000000000750072674642500163720ustar 00000000000000fn main() { cargo_binutils::Tool::Cov.cargo_exec(None) } cargo-binutils-0.3.5/src/bin/cargo-nm.rs000064400000000000000000000004130072674642500162110ustar 00000000000000const EXAMPLES: &str = " EXAMPLES `cargo nm --lib` - lists all symbols `cargo nm --lib -- -print-size -size-sort` - lists all symbols sorted by size (smallest first)"; fn main() { cargo_binutils::Tool::Nm.cargo_exec(Some(EXAMPLES)) } cargo-binutils-0.3.5/src/bin/cargo-objcopy.rs000064400000000000000000000003260072674642500172470ustar 00000000000000const EXAMPLES: &str = " EXAMPLES `cargo objcopy --bin foo -- -O binary foo.hex` - converts the output (e.g. ELF) into binary format"; fn main() { cargo_binutils::Tool::Objcopy.cargo_exec(Some(EXAMPLES)) } cargo-binutils-0.3.5/src/bin/cargo-objdump.rs000064400000000000000000000004350072674642500172430ustar 00000000000000const EXAMPLES: &str = " EXAMPLES `cargo objdump --lib --release -- -d` - disassemble `cargo objdump --bin foo --release -- -s -j .rodata` - prints the contents of the .rodata section"; fn main() { cargo_binutils::Tool::Objdump.cargo_exec(Some(EXAMPLES)) } cargo-binutils-0.3.5/src/bin/cargo-profdata.rs000064400000000000000000000001020072674642500173720ustar 00000000000000fn main() { cargo_binutils::Tool::Profdata.cargo_exec(None) } cargo-binutils-0.3.5/src/bin/cargo-readobj.rs000064400000000000000000000003550072674642500172120ustar 00000000000000const EXAMPLES: &str = " EXAMPLES `cargo readobj --bin app -- -s` - Displays the section headers `cargo readobj --bin app -- -t` - Displays the symbol table"; fn main() { cargo_binutils::Tool::Readobj.cargo_exec(Some(EXAMPLES)) } cargo-binutils-0.3.5/src/bin/cargo-size.rs000064400000000000000000000004170072674642500165550ustar 00000000000000const EXAMPLES: &str = " EXAMPLES `cargo size --bin foo --release` - prints binary size in Berkeley format `cargo size --bin foo --release -- -A` - prints binary size in System V format"; fn main() { cargo_binutils::Tool::Size.cargo_exec(Some(EXAMPLES)) } cargo-binutils-0.3.5/src/bin/cargo-strip.rs000064400000000000000000000003050072674642500167400ustar 00000000000000const EXAMPLES: &str = " EXAMPLES `cargo strip --bin foo --release -- -strip-all -o stripped` - strips all symbols"; fn main() { cargo_binutils::Tool::Strip.cargo_exec(Some(EXAMPLES)) } cargo-binutils-0.3.5/src/bin/rust-ar.rs000064400000000000000000000000670072674642500161100ustar 00000000000000fn main() { cargo_binutils::Tool::Ar.rust_exec() } cargo-binutils-0.3.5/src/bin/rust-cov.rs000064400000000000000000000000700072674642500162670ustar 00000000000000fn main() { cargo_binutils::Tool::Cov.rust_exec() } cargo-binutils-0.3.5/src/bin/rust-ld.rs000064400000000000000000000000700072674642500160770ustar 00000000000000fn main() { cargo_binutils::Tool::Lld.rust_exec() } cargo-binutils-0.3.5/src/bin/rust-lld.rs000064400000000000000000000000700072674642500162530ustar 00000000000000fn main() { cargo_binutils::Tool::Lld.rust_exec() } cargo-binutils-0.3.5/src/bin/rust-nm.rs000064400000000000000000000000670072674642500161200ustar 00000000000000fn main() { cargo_binutils::Tool::Nm.rust_exec() } cargo-binutils-0.3.5/src/bin/rust-objcopy.rs000064400000000000000000000000740072674642500171510ustar 00000000000000fn main() { cargo_binutils::Tool::Objcopy.rust_exec() } cargo-binutils-0.3.5/src/bin/rust-objdump.rs000064400000000000000000000000740072674642500171440ustar 00000000000000fn main() { cargo_binutils::Tool::Objdump.rust_exec() } cargo-binutils-0.3.5/src/bin/rust-profdata.rs000064400000000000000000000000750072674642500173050ustar 00000000000000fn main() { cargo_binutils::Tool::Profdata.rust_exec() } cargo-binutils-0.3.5/src/bin/rust-readobj.rs000064400000000000000000000000740072674642500171120ustar 00000000000000fn main() { cargo_binutils::Tool::Readobj.rust_exec() } cargo-binutils-0.3.5/src/bin/rust-size.rs000064400000000000000000000000710072674642500164530ustar 00000000000000fn main() { cargo_binutils::Tool::Size.rust_exec() } cargo-binutils-0.3.5/src/bin/rust-strip.rs000064400000000000000000000000720072674642500166430ustar 00000000000000fn main() { cargo_binutils::Tool::Strip.rust_exec() } cargo-binutils-0.3.5/src/lib.rs000064400000000000000000000452510072674642500145150ustar 00000000000000#![deny(warnings)] use std::io::{self, BufReader, Write}; use std::path::{Component, Path}; use std::process::{Command, Stdio}; use std::{env, str}; use anyhow::{bail, Result}; use cargo_metadata::{Artifact, CargoOpt, Message, Metadata, MetadataCommand}; use clap::{App, AppSettings, Arg, ArgMatches}; use rustc_cfg::Cfg; pub use tool::Tool; mod llvm; mod postprocess; mod rustc; mod tool; /// Search for `file` in `path` and its parent directories fn search<'p>(path: &'p Path, file: &str) -> Option<&'p Path> { path.ancestors().find(|dir| dir.join(file).exists()) } fn parse(path: &Path) -> Result where T: for<'de> serde::Deserialize<'de>, { use std::fs::File; use std::io::Read; use toml::de; let mut s = String::new(); File::open(path)?.read_to_string(&mut s)?; Ok(de::from_str(&s)?) } /// Execution context // TODO this should be some sort of initialize once, read-only singleton pub struct Context { cfg: Cfg, /// Final compilation target target: String, } impl Context { /* Constructors */ /// Get a context structure from a built artifact. fn from_artifact(metadata: Metadata, artifact: &Artifact) -> Result { // Currently there is no clean way to get the target triple from cargo so we can only make // an approximation, we do this by extracting the target triple from the artifacts path. // For more info on the path structure see: https://doc.rust-lang.org/cargo/guide/build-cache.html // In the future it may be possible to replace this code and use a cargo feature: // See: https://github.com/rust-lang/cargo/issues/5579, https://github.com/rust-lang/cargo/issues/8002 // Should always succeed. let target_path = artifact.filenames[0].strip_prefix(metadata.target_directory)?; let target_name = if let Some(Component::Normal(path)) = target_path.components().next() { let path = path.to_string_lossy(); // TODO: How will custom profiles impact this? if path == "debug" || path == "release" { // Looks like this artifact was built for the host. rustc_version::version_meta()?.host } else { // The artifact path.to_string() } } else { unreachable!(); }; Self::from_target_name(&target_name) } /// Get a context structure from a provided target flag, used when cargo /// was not used to build the binary. fn from_flag(metadata: Metadata, target_flag: Option<&str>) -> Result { let host_target_name = rustc_version::version_meta()?.host; // Get the "default" target override in .cargo/config. let mut config_target_name = None; let config: toml::Value; if let Some(path) = search(&metadata.workspace_root, ".cargo/config") { config = parse(&path.join(".cargo/config"))?; config_target_name = config .get("build") .and_then(|build| build.get("target")) .and_then(|target| target.as_str()); } // Find the actual target. let target_name = target_flag .or(config_target_name) .unwrap_or(&host_target_name); Self::from_target_name(target_name) } fn from_target_name(target_name: &str) -> Result { let cfg = Cfg::of(target_name).map_err(|e| e.compat())?; Ok(Context { cfg, target: target_name.to_string(), }) } } enum BuildType<'a> { Any, Bin(&'a str), Example(&'a str), Test(&'a str), Bench(&'a str), Lib, } impl<'a> BuildType<'a> { fn matches(&self, artifact: &Artifact) -> bool { match self { BuildType::Bin(target_name) | BuildType::Example(target_name) | BuildType::Test(target_name) | BuildType::Bench(target_name) => { artifact.target.name == *target_name && artifact.executable.is_some() } // For info about 'kind' values see: // https://github.com/rust-lang/cargo/blob/d47a9545db81fe6d7e6c542bc8154f09d0e6c788/src/cargo/core/manifest.rs#L166-L181 // The only "Any" artifacts we can support are bins and examples, so let's make sure // no-one slips us a "custom-build" in form of a build.rs in BuildType::Any => artifact .target .kind .iter() .any(|s| s == "bin" || s == "example"), // Since LibKind can be an arbitrary string `LibKind:Other(String)` we filter by what it can't be BuildType::Lib => artifact.target.kind.iter().any(|s| { s != "bin" && s != "example" && s != "test" && s != "custom-build" && s != "bench" }), } } } fn args(tool: Tool, examples: Option<&str>) -> ArgMatches { let name = tool.name(); let about = format!( "Proxy for the `llvm-{}` tool shipped with the Rust toolchain.", name ); let after_help = format!( "\ The arguments specified *after* the `--` will be passed to the proxied tool invocation. To see all the flags the proxied tool accepts run `cargo-{} -- -help`.{}", name, examples.unwrap_or("") ); let app = App::new(format!("cargo-{}", name)) .about(&*about) .version(env!("CARGO_PKG_VERSION")) .settings(&[ AppSettings::UnifiedHelpMessage, AppSettings::DeriveDisplayOrder, AppSettings::DontCollapseArgsInUsage, ]) // as this is used as a Cargo subcommand the first argument will be the name of the binary // we ignore this argument .args(&[ Arg::with_name("binary-name").hidden(true), Arg::with_name("verbose") .long("verbose") .short("v") .multiple(true) .help("Use verbose output (-vv cargo verbose or -vvv for build.rs output)"), Arg::with_name("args") .last(true) .multiple(true) .help("The arguments to be proxied to the tool"), ]) .after_help(&*after_help); if tool.needs_build() { app.args(&[ Arg::with_name("quiet") .long("quiet") .short("q") .help("Don't print build output from `cargo build`"), Arg::with_name("package") .long("package") .short("p") .takes_value(true) .value_name("SPEC") .help("Package to build (see `cargo help pkgid`)"), Arg::with_name("jobs") .long("jobs") .short("j") .value_name("N") .help("Number of parallel jobs, defaults to # of CPUs"), Arg::with_name("lib") .long("lib") .conflicts_with_all(&["bin", "example", "test", "bench"]) .help("Build only this package's library"), Arg::with_name("bin") .long("bin") .takes_value(true) .value_name("NAME") .conflicts_with_all(&["lib", "example", "test", "bench"]) .help("Build only the specified binary"), Arg::with_name("example") .long("example") .takes_value(true) .value_name("NAME") .conflicts_with_all(&["lib", "bin", "test", "bench"]) .help("Build only the specified example"), Arg::with_name("test") .long("test") .takes_value(true) .value_name("NAME") .conflicts_with_all(&["lib", "bin", "example", "bench"]) .help("Build only the specified test target"), Arg::with_name("bench") .long("bench") .takes_value(true) .value_name("NAME") .conflicts_with_all(&["lib", "bin", "example", "test"]) .help("Build only the specified bench target"), Arg::with_name("release") .long("release") .help("Build artifacts in release mode, with optimizations"), Arg::with_name("profile") .long("profile") .value_name("PROFILE-NAME") .help("Build artifacts with the specified profile"), Arg::with_name("features") .long("features") .multiple(true) .number_of_values(1) .takes_value(true) .value_name("FEATURES") .help("Space-separated list of features to activate"), Arg::with_name("all-features") .long("all-features") .help("Do not activate the `default` feature"), Arg::with_name("no-default-features") .long("no-default-features") .help("Activate all available features"), Arg::with_name("target") .long("target") .takes_value(true) .value_name("TRIPLE") .help("Target triple for which the code is compiled"), Arg::with_name("color") .long("color") .takes_value(true) .possible_values(&["auto", "always", "never"]) .help("Coloring: auto, always, never"), Arg::with_name("frozen") .long("frozen") .help("Require Cargo.lock and cache are up to date"), Arg::with_name("locked") .long("locked") .help("Require Cargo.lock is up to date"), Arg::with_name("offline") .long("offline") .help("Run without accessing the network"), Arg::with_name("unstable-features") .short("Z") .multiple(true) .number_of_values(1) .takes_value(true) .value_name("FLAG") .help("Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details"), ]) .get_matches() } else { app.get_matches() } } pub fn run(tool: Tool, matches: ArgMatches) -> Result { let mut metadata_command = MetadataCommand::new(); if let Some(features) = matches.values_of("features") { metadata_command.features(CargoOpt::SomeFeatures( features.map(|s| s.to_owned()).collect(), )); } if matches.is_present("no-default-features") { metadata_command.features(CargoOpt::NoDefaultFeatures); } if matches.is_present("all-features") { metadata_command.features(CargoOpt::AllFeatures); } let metadata = metadata_command.exec()?; if metadata.workspace_members.is_empty() { bail!("Unable to find workspace members"); } let target_artifact = if tool.needs_build() { cargo_build(&matches, &metadata)? } else { None }; let mut tool_args = vec![]; if let Some(args) = matches.values_of("args") { tool_args.extend(args); } let mut lltool = Command::new(format!("rust-{}", tool.name())); if tool == Tool::Objdump { let ctxt = if let Some(artifact) = &target_artifact { Context::from_artifact(metadata, artifact)? } else { Context::from_flag(metadata, matches.value_of("target"))? }; let arch_name = llvm::arch_name(&ctxt.cfg, &ctxt.target); if arch_name == "thumb" { // `-arch-name=thumb` doesn't produce the right output so instead we pass // `-triple=$target`, which contains more information about the target lltool.args(&["--triple", &ctxt.target]); } else { lltool.args(&[format!("--arch-name={}", arch_name)]); } } // Extra flags if let Tool::Readobj = tool { // The default output style of `readobj` is JSON-like, which is not user friendly, so we // change it to the human readable GNU style lltool.arg("--elf-output-style=GNU"); } if tool.needs_build() { // Artifact if let Some(artifact) = &target_artifact { let file = match &artifact.executable { // Example and bins have an executable Some(val) => val, // Libs have an rlib and an rmeta. We want the rlib, which always // comes first in the filenames array after some quick testing. // // We could instead look for files ending in .rlib, but that would // fail for cdylib and other fancy crate kinds. None => &artifact.filenames[0], }; match tool { // Tools that don't need a build Tool::Ar | Tool::Cov | Tool::Lld | Tool::Profdata => {} // for some tools we change the CWD (current working directory) and // make the artifact path relative. This makes the path that the // tool will print easier to read. e.g. `libfoo.rlib` instead of // `/home/user/rust/project/target/$T/debug/libfoo.rlib`. Tool::Objdump | Tool::Nm | Tool::Readobj | Tool::Size => { lltool .current_dir(file.parent().unwrap()) .arg(file.file_name().unwrap()); } Tool::Objcopy | Tool::Strip => { lltool.arg(file); } } } } // User flags lltool.args(&tool_args); if matches.is_present("verbose") { eprintln!("{:?}", lltool); } let stdout = io::stdout(); let mut stdout = stdout.lock(); let output = lltool.stderr(Stdio::inherit()).output()?; // post process output let processed_output = match tool { Tool::Ar | Tool::Cov | Tool::Lld | Tool::Objcopy | Tool::Profdata | Tool::Strip => { output.stdout.into() } Tool::Nm | Tool::Objdump | Tool::Readobj => postprocess::demangle(&output.stdout), Tool::Size => postprocess::size(&output.stdout), }; stdout.write_all(&*processed_output)?; if output.status.success() { Ok(0) } else { Ok(output.status.code().unwrap_or(1)) } } fn cargo_build(matches: &ArgMatches, metadata: &Metadata) -> Result> { let cargo = env::var_os("CARGO").unwrap_or_else(|| "cargo".into()); let mut cargo = Command::new(cargo); cargo.arg("build"); let (build_type, verbose) = cargo_build_args(matches, &mut cargo); let quiet = matches.is_present("quiet"); cargo.arg("--message-format=json"); cargo.stdout(Stdio::piped()); if verbose > 0 { eprintln!("{:?}", cargo); } let mut child = cargo.spawn()?; let stdout = BufReader::new(child.stdout.take().expect("Pipe to cargo process failed")); // Note: We call `collect` to ensure we don't block stdout which could prevent the process from exiting let messages = Message::parse_stream(stdout).collect::>(); let status = child.wait()?; if !status.success() { bail!("Failed to parse crate metadata"); } let mut target_artifact: Option = None; for message in messages { match message? { 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); } } Message::CompilerMessage(msg) => { if !quiet || verbose > 1 { if let Some(rendered) = msg.message.rendered { print!("{}", rendered); } } } _ => (), } } if target_artifact.is_none() { bail!("Could not determine the wanted artifact"); } Ok(target_artifact) } fn cargo_build_args<'a>(matches: &'a ArgMatches<'a>, cargo: &mut Command) -> (BuildType<'a>, u64) { if matches.is_present("quiet") { cargo.arg("--quiet"); } if let Some(package) = matches.value_of("package") { cargo.arg("--package"); cargo.arg(package); } if let Some(jobs) = matches.value_of("jobs") { cargo.arg("-j"); cargo.arg(jobs); } let build_type = if matches.is_present("lib") { cargo.args(&["--lib"]); BuildType::Lib } else if let Some(bin_name) = matches.value_of("bin") { cargo.args(&["--bin", bin_name]); BuildType::Bin(bin_name) } else if let Some(example_name) = matches.value_of("example") { cargo.args(&["--example", example_name]); BuildType::Example(example_name) } else if let Some(test_name) = matches.value_of("test") { cargo.args(&["--test", test_name]); BuildType::Test(test_name) } else if let Some(bench_name) = matches.value_of("bench") { cargo.args(&["--bench", bench_name]); BuildType::Bench(bench_name) } else { BuildType::Any }; if matches.is_present("release") { cargo.arg("--release"); } if let Some(profile) = matches.value_of("profile") { cargo.arg("--profile"); cargo.arg(profile); } if let Some(features) = matches.values_of("features") { for feature in features { cargo.args(&["--features", feature]); } } if matches.is_present("no-default-features") { cargo.arg("--no-default-features"); } if matches.is_present("all-features") { cargo.arg("--all-features"); } // NOTE we do *not* use `project.target()` here because Cargo will figure things out on // its own (i.e. it will search and parse .cargo/config, etc.) if let Some(target) = matches.value_of("target") { cargo.args(&["--target", target]); } let verbose = matches.occurrences_of("verbose"); if verbose > 1 { cargo.arg(format!("-{}", "v".repeat((verbose - 1) as usize))); } if let Some(color) = matches.value_of("color") { cargo.arg("--color"); cargo.arg(color); } if matches.is_present("frozen") { cargo.arg("--frozen"); } if matches.is_present("locked") { cargo.arg("--locked"); } if matches.is_present("offline") { cargo.arg("--offline"); } if let Some(unstable_features) = matches.values_of("Z") { for unstable_feature in unstable_features { cargo.args(&["-Z", unstable_feature]); } } (build_type, verbose) } cargo-binutils-0.3.5/src/llvm.rs000064400000000000000000000036170072674642500147210ustar 00000000000000use rustc_cfg::Cfg; // Here we map Rust arches to LLVM arches // // Rust knows these arches as of 1.28 (from librustc_target/abi/call/mod.rs) // // - aarch64 // - arm // - asmjs (emscripten fork only) // - hexagon // - mips // - mips64 // - msp430 // - nvptx // - nvptx64 // - powerpc // - riscv32 // - riscv64 // - s390x // - sparc // - sparc64 // - wasm32 // - x86 // - x86_64 // // Rust LLVM knows these arches of 7.0 (from `llvm-objdump -version`) // // - aarch64 // - aarch64_be // - arm // - arm64 // - armeb // - hexagon // - mips // - mips64 // - mips64el // - mipsel // - msp430 // - nvptx // - nvptx64 // - ppc32 // - ppc64 // - ppc64le // - riscv32 // - riscv64 // - sparc // - sparcel // - sparcv9 // - systemz // - thumb // - thumbeb // - wasm32 // - wasm64 // - x86 // - x86-64 pub fn arch_name<'a>(cfg: &'a Cfg, target: &'a str) -> &'a str { const BIG: &str = "big"; const LITTLE: &str = "little"; let endian = &*cfg.target_endian; let arch = &*cfg.target_arch; if target.starts_with("thumb") { // no way to tell from `--print cfg` that the target is thumb only so we // completely rely on the target name here if endian == BIG { "thumbeb" } else { "thumb" } } else { match (arch, endian) { // non standard endianness ("aarch64", BIG) => "aarch64_be", ("arm", BIG) => "armeb", ("mips", LITTLE) => "mipsel", ("mips64", LITTLE) => "mips64el", ("powerpc64", LITTLE) => "ppc64le", ("sparc", LITTLE) => "sparcel", // names that match ("powerpc", _) => "ppc32", ("powerpc64", BIG) => "ppc64", ("sparc64", _) => "sparcv9", ("s390x", _) => "systemz", ("x86_64", _) => "x86-64", // all the other names match as of 1.28 _ => arch, } } } cargo-binutils-0.3.5/src/postprocess.rs000064400000000000000000000037460072674642500163360ustar 00000000000000use std::borrow::Cow; use std::str; use regex::{Captures, Regex}; // Here we post process the output of some tools to improve. If the output of the tool is not valid // UTF-8 then we don't touch it. // This pass demangles *all* the Rust symbols in the input pub fn demangle(bytes: &[u8]) -> Cow<[u8]> { let re = Regex::new(r#"_Z.+?E\b"#).expect("BUG: Malformed Regex"); if let Ok(text) = str::from_utf8(bytes) { match re.replace_all(text, |cs: &Captures| { format!("{}", rustc_demangle::demangle(cs.get(0).unwrap().as_str())) }) { Cow::Borrowed(s) => s.as_bytes().into(), Cow::Owned(s) => s.into_bytes().into(), } } else { bytes.into() } } // This pass turns the addresses in the output of `size -A` into hexadecimal format pub fn size(bytes: &[u8]) -> Cow<[u8]> { if let Ok(text) = str::from_utf8(bytes) { let mut s = text .lines() .map(|line| -> Cow { match line .split_whitespace() .nth(2) .and_then(|part| part.parse::().ok().map(|addr| (part, addr))) { // the lines to postprocess have the form ".section_name 100 1024" where // the second number is the address Some((needle, addr)) if line.starts_with('.') => { let pos = line.rfind(needle).unwrap(); let hex_addr = format!("{:#x}", addr); let start = pos + needle.as_bytes().len() - hex_addr.as_bytes().len(); format!("{}{}", &line[..start], hex_addr).into() } _ => line.into(), } }) .collect::>() .join("\n"); // `text.lines()` loses the trailing newline so we restore it here s.push('\n'); s.into_bytes().into() } else { bytes.into() } } cargo-binutils-0.3.5/src/rustc.rs000064400000000000000000000015410072674642500151010ustar 00000000000000use std::env; use std::path::PathBuf; use std::process::Command; use anyhow::Result; pub fn sysroot() -> Result { let rustc = env::var_os("RUSTC").unwrap_or_else(|| "rustc".into()); let output = Command::new(rustc).arg("--print").arg("sysroot").output()?; // Note: We must trim() to remove the `\n` from the end of stdout Ok(String::from_utf8(output.stdout)?.trim().to_owned()) } // See: https://github.com/rust-lang/rust/blob/564758c4c329e89722454dd2fbb35f1ac0b8b47c/src/bootstrap/dist.rs#L2334-L2341 pub fn rustlib() -> Result { let sysroot = sysroot()?; let mut pathbuf = PathBuf::from(sysroot); pathbuf.push("lib"); pathbuf.push("rustlib"); pathbuf.push(rustc_version::version_meta()?.host); // TODO: Prevent calling rustc_version::version_meta() multiple times pathbuf.push("bin"); Ok(pathbuf) } cargo-binutils-0.3.5/src/tool.rs000064400000000000000000000063100072674642500147150ustar 00000000000000use std::env::consts::EXE_SUFFIX; use std::path::PathBuf; use std::process::Command; use std::{env, process}; use anyhow::Result; use crate::rustc::rustlib; #[derive(Clone, Copy, PartialEq)] pub enum Tool { Ar, Cov, Lld, Nm, Objcopy, Objdump, Profdata, Readobj, Size, Strip, } impl Tool { pub fn name(self) -> &'static str { match self { Tool::Ar => "ar", Tool::Cov => "cov", Tool::Lld => "lld", Tool::Nm => "nm", Tool::Objcopy => "objcopy", Tool::Objdump => "objdump", Tool::Profdata => "profdata", Tool::Readobj => "readobj", Tool::Size => "size", Tool::Strip => "strip", } } pub fn exe(self) -> String { match self { Tool::Lld => format!("rust-lld{}", EXE_SUFFIX), _ => format!("llvm-{}{}", self.name(), EXE_SUFFIX), } } pub fn path(self) -> Result { let mut path = rustlib()?; path.push(self.exe()); Ok(path) } /// Forwards execution to the specified tool. /// If the tool fails to start or is not found this process exits with /// status code 101 the same as if the process has a panic! pub fn rust_exec(self) -> ! { let path = match self.path() { Err(e) => { eprintln!("Failed to find tool: {}\n{}", self.name(), e); process::exit(101) } Ok(p) => p, }; if !path.exists() { eprintln!("Could not find tool: {}\nat: {}\nConsider `rustup component add llvm-tools-preview`", self.name(), path.to_string_lossy()); process::exit(102) }; // Note: The first argument is the name of the binary (e.g. `rust-nm`) let args = env::args().skip(1); // Spawn the process and check if the process did spawn let status = match Command::new(path).args(args).status() { Err(e) => { eprintln!("Failed to execute tool: {}\n{}", self.name(), e); process::exit(101) } Ok(s) => s, }; // Forward the exit code from the tool process::exit(status.code().unwrap_or(101)); } /// Parses arguments for `cargo $tool` and then if needed executes `cargo build` /// before parsing the required arguments to `rust-$tool`. /// If the tool fails to start or is not found this process exits with /// status code 101 the same as if the process has a panic! pub fn cargo_exec(self, examples: Option<&str>) -> ! { let matches = crate::args(self, examples); match crate::run(self, matches) { Err(e) => { eprintln!("error: {}", e); process::exit(101) } Ok(ec) => process::exit(ec), } } // Whether this tool requires the project to be previously built pub fn needs_build(self) -> bool { match self { Tool::Ar | Tool::Cov | Tool::Lld | Tool::Profdata => false, Tool::Nm | Tool::Objcopy | Tool::Objdump | Tool::Readobj | Tool::Size | Tool::Strip => { true } } } } cargo-binutils-0.3.5/triagebot.toml000064400000000000000000000000110072674642500154500ustar 00000000000000[assign]