From ae229a616b8498eca487e111725ec6857abd0f82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 5 Jul 2023 10:22:31 +0200 Subject: [PATCH 01/22] CI: add workflow for checking binary size --- .github/workflows/check-binary-size.yml | 86 +++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 .github/workflows/check-binary-size.yml diff --git a/.github/workflows/check-binary-size.yml b/.github/workflows/check-binary-size.yml new file mode 100644 index 000000000..5ee9786cc --- /dev/null +++ b/.github/workflows/check-binary-size.yml @@ -0,0 +1,86 @@ +# This workflow checks if a PR commit has changed the size of a hello world Rust program. +# It downloads Rustc and compiles two versions of a stage0 compiler - one using the base commit +# of the PR, and one using the latest commit in the PR. +# If the size of the hello world program has changed, it posts a comment to the PR. +name: Check binary size + +on: + pull_request: + branches: + - master + +jobs: + test: + name: Check binary size + runs-on: ubuntu-latest + permissions: + pull-requests: write + steps: + - name: Print info + run: | + echo "Current SHA: ${{ github.event.pull_request.head.sha }}" + echo "Base SHA: ${{ github.event.pull_request.base.sha }}" + - name: Clone Rustc + uses: actions/checkout@v3 + with: + repository: rust-lang/rust + fetch-depth: 1 + - name: Fetch backtrace + run: git submodule update --init library/backtrace + - name: Create hello world program that uses backtrace + run: printf "fn main() { panic!(); }" > foo.rs + - name: Build binary with base version of backtrace + run: | + printf "[llvm]\ndownload-ci-llvm = true\n\n[rust]\nincremental = false\n" > config.toml + cd library/backtrace + git remote add kobzol https://github.com/kobzol/backtrace-rs + git fetch --all + git checkout ${{ github.event.pull_request.base.sha }} + cd ../.. + git add library/backtrace + python3 x.py build library --stage 0 + cp -r ./build/x86_64-unknown-linux-gnu/stage0/bin ./build/x86_64-unknown-linux-gnu/stage0-sysroot/bin + cp -r ./build/x86_64-unknown-linux-gnu/stage0/lib/*.so ./build/x86_64-unknown-linux-gnu/stage0-sysroot/lib + ./build/x86_64-unknown-linux-gnu/stage0-sysroot/bin/rustc -O foo.rs -o binary-reference + - name: Build binary with PR version of backtrace + run: | + cd library/backtrace + git checkout ${{ github.event.pull_request.head.sha }} + cd ../.. + git add library/backtrace + rm -rf build/x86_64-unknown-linux-gnu/stage0-std + python3 x.py build library --stage 0 + cp -r ./build/x86_64-unknown-linux-gnu/stage0/bin ./build/x86_64-unknown-linux-gnu/stage0-sysroot/bin + cp -r ./build/x86_64-unknown-linux-gnu/stage0/lib/*.so ./build/x86_64-unknown-linux-gnu/stage0-sysroot/lib + ./build/x86_64-unknown-linux-gnu/stage0-sysroot/bin/rustc -O foo.rs -o binary-updated + - name: Display binary size + run: | + ls -la binary-* + echo "SIZE_REFERENCE=$(stat -c '%s' binary-reference)" >> "$GITHUB_ENV" + echo "SIZE_UPDATED=$(stat -c '%s' binary-updated)" >> "$GITHUB_ENV" + - name: Post a PR comment if the size has changed + uses: actions/github-script@v6 + with: + script: | + const reference = process.env.SIZE_REFERENCE; + const updated = process.env.SIZE_UPDATED; + const diff = updated - reference; + const plus = diff > 0 ? "+" : ""; + const diff_str = `${plus}${diff}B`; + + if (diff !== 0) { + // The body is created here and wrapped so "weirdly" to avoid whitespace at the start of the lines, + // which is interpreted as a code block by Markdown. + const body = `Below is the size of a hello-world Rust program linked with libstd with backtrace. + + Original binary size: **${reference}B** + Updated binary size: **${updated}B** + Difference: **${diff_str}**`; + + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body + }) + } From 06f3ff4552bf288ae20d37dbebf010e38214ee82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Thu, 6 Jul 2023 10:52:16 +0200 Subject: [PATCH 02/22] CI: fix fetch of PR fork commits in binary size check workflow --- .github/workflows/check-binary-size.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-binary-size.yml b/.github/workflows/check-binary-size.yml index 5ee9786cc..c43f117ca 100644 --- a/.github/workflows/check-binary-size.yml +++ b/.github/workflows/check-binary-size.yml @@ -33,7 +33,7 @@ jobs: run: | printf "[llvm]\ndownload-ci-llvm = true\n\n[rust]\nincremental = false\n" > config.toml cd library/backtrace - git remote add kobzol https://github.com/kobzol/backtrace-rs + git remote add head-pr https://github.com/${{ github.event.pull_request.head.repo.full_name }} git fetch --all git checkout ${{ github.event.pull_request.base.sha }} cd ../.. From 4f2e06fecfe42a4d38d4fd8cfa3522783a7f0b33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Thu, 6 Jul 2023 17:03:33 +0200 Subject: [PATCH 03/22] Switch to `pull_request_target` event This should hopefully resolve the permission issue. --- .github/workflows/check-binary-size.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-binary-size.yml b/.github/workflows/check-binary-size.yml index c43f117ca..7660905b3 100644 --- a/.github/workflows/check-binary-size.yml +++ b/.github/workflows/check-binary-size.yml @@ -5,7 +5,7 @@ name: Check binary size on: - pull_request: + pull_request_target: branches: - master From a16c5730ac001284177ec3ecb83da32708ff2f88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Thu, 6 Jul 2023 17:04:23 +0200 Subject: [PATCH 04/22] Add percent calculation --- .github/workflows/check-binary-size.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check-binary-size.yml b/.github/workflows/check-binary-size.yml index 7660905b3..5104b6d88 100644 --- a/.github/workflows/check-binary-size.yml +++ b/.github/workflows/check-binary-size.yml @@ -69,13 +69,14 @@ jobs: const diff_str = `${plus}${diff}B`; if (diff !== 0) { + const percent = (((updated / reference) - 1) * 100).toFixed(2); // The body is created here and wrapped so "weirdly" to avoid whitespace at the start of the lines, // which is interpreted as a code block by Markdown. const body = `Below is the size of a hello-world Rust program linked with libstd with backtrace. Original binary size: **${reference}B** Updated binary size: **${updated}B** - Difference: **${diff_str}**`; + Difference: **${diff_str}** (${percent}%)`; github.rest.issues.createComment({ issue_number: context.issue.number, From 89b2ccd6e44c3aa3003a165fdcabf1e7c16ba7d6 Mon Sep 17 00:00:00 2001 From: Jason Heeris Date: Mon, 17 Jul 2023 17:35:44 +0800 Subject: [PATCH 05/22] Omit copying patched std build output for checking binary size in CI. (rust-lang/backtrace#550) This is now done by the bootstrapping process. See rust-lang/rust#113341. --- .github/workflows/check-binary-size.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/check-binary-size.yml b/.github/workflows/check-binary-size.yml index 5104b6d88..0beae1da9 100644 --- a/.github/workflows/check-binary-size.yml +++ b/.github/workflows/check-binary-size.yml @@ -39,8 +39,6 @@ jobs: cd ../.. git add library/backtrace python3 x.py build library --stage 0 - cp -r ./build/x86_64-unknown-linux-gnu/stage0/bin ./build/x86_64-unknown-linux-gnu/stage0-sysroot/bin - cp -r ./build/x86_64-unknown-linux-gnu/stage0/lib/*.so ./build/x86_64-unknown-linux-gnu/stage0-sysroot/lib ./build/x86_64-unknown-linux-gnu/stage0-sysroot/bin/rustc -O foo.rs -o binary-reference - name: Build binary with PR version of backtrace run: | @@ -50,8 +48,6 @@ jobs: git add library/backtrace rm -rf build/x86_64-unknown-linux-gnu/stage0-std python3 x.py build library --stage 0 - cp -r ./build/x86_64-unknown-linux-gnu/stage0/bin ./build/x86_64-unknown-linux-gnu/stage0-sysroot/bin - cp -r ./build/x86_64-unknown-linux-gnu/stage0/lib/*.so ./build/x86_64-unknown-linux-gnu/stage0-sysroot/lib ./build/x86_64-unknown-linux-gnu/stage0-sysroot/bin/rustc -O foo.rs -o binary-updated - name: Display binary size run: | From 0533d475a52389ea0612b5543316bb571afc30ac Mon Sep 17 00:00:00 2001 From: Jubilee <46493976+workingjubilee@users.noreply.github.com> Date: Mon, 17 Jul 2023 12:29:04 -0700 Subject: [PATCH 06/22] Fix drop-on-copy lint (rust-lang/backtrace-rs#551) --- src/windows.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/windows.rs b/src/windows.rs index 9ec3ba99b..92c2b2e66 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -177,9 +177,9 @@ macro_rules! ffi { assert_eq!($name as usize, winapi::$name as usize); let mut x: unsafe extern "system" fn($($args)*) -> $ret; x = $name; - drop(x); + let _ = x; x = winapi::$name; - drop(x); + let _ = x; } } )* From 2f2e9f9539c7631a2f060c99fbe86297cfd31629 Mon Sep 17 00:00:00 2001 From: Mason Remaley Date: Sun, 23 Jul 2023 18:52:30 -0700 Subject: [PATCH 07/22] Corrects /proc/pid/maps parser to correctly handle spaces in pathnames --- .../gimli/parse_running_mmaps_unix.rs | 53 +++++++++++++++---- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/src/symbolize/gimli/parse_running_mmaps_unix.rs b/src/symbolize/gimli/parse_running_mmaps_unix.rs index deeeb2971..5b342d237 100644 --- a/src/symbolize/gimli/parse_running_mmaps_unix.rs +++ b/src/symbolize/gimli/parse_running_mmaps_unix.rs @@ -85,16 +85,37 @@ impl FromStr for MapsEntry { // e.g.: "ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0 [vsyscall]" // e.g.: "7f5985f46000-7f5985f48000 rw-p 00039000 103:06 76021795 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2" // e.g.: "35b1a21000-35b1a22000 rw-p 00000000 00:00 0" + // + // Note that paths may contain spaces, so we can't use `str::split` for parsing (until + // Split::remainder is stabalized #77998). fn from_str(s: &str) -> Result { - let mut parts = s - .split(' ') // space-separated fields - .filter(|s| s.len() > 0); // multiple spaces implies empty strings that need to be skipped. - let range_str = parts.next().ok_or("Couldn't find address")?; - let perms_str = parts.next().ok_or("Couldn't find permissions")?; - let offset_str = parts.next().ok_or("Couldn't find offset")?; - let dev_str = parts.next().ok_or("Couldn't find dev")?; - let inode_str = parts.next().ok_or("Couldn't find inode")?; - let pathname_str = parts.next().unwrap_or(""); // pathname may be omitted. + let (range_str, s) = s.trim().split_once(' ').unwrap_or((s, "")); + if range_str.is_empty() { + return Err("Couldn't find address"); + } + + let (perms_str, s) = s.trim().split_once(' ').unwrap_or((s, "")); + if range_str.is_empty() { + return Err("Couldn't find permissions"); + } + + let (offset_str, s) = s.trim().split_once(' ').unwrap_or((s, "")); + if range_str.is_empty() { + return Err("Couldn't find offset"); + } + + let (dev_str, s) = s.trim().split_once(' ').unwrap_or((s, "")); + if range_str.is_empty() { + return Err("Couldn't find dev"); + } + + let (inode_str, s) = s.trim().split_once(' ').unwrap_or((s, "")); + if range_str.is_empty() { + return Err("Couldn't find inode"); + } + + // Pathname may be omitted in which case it will be empty + let pathname_str = s.trim(); let hex = |s| usize::from_str_radix(s, 16).map_err(|_| "Couldn't parse hex number"); let address = if let Some((start, limit)) = range_str.split_once('-') { @@ -229,4 +250,18 @@ fn check_maps_entry_parsing_32bit() { pathname: Default::default(), } ); + assert_eq!( + "b7c79000-b7e02000 r--p 00000000 08:01 60662705 \ + /executable/path/with some spaces" + .parse::() + .unwrap(), + MapsEntry { + address: (0xb7c79000, 0xb7e02000), + perms: ['r', '-', '-', 'p'], + offset: 0x00000000, + dev: (0x08, 0x01), + inode: 0x60662705, + pathname: "/executable/path/with some spaces".into(), + } + ); } From 047c2b316fdb2e3aa01943896d905b117f77f3f9 Mon Sep 17 00:00:00 2001 From: Mason Remaley Date: Mon, 24 Jul 2023 13:30:24 -0700 Subject: [PATCH 08/22] Fixes copy paste error --- src/symbolize/gimli/parse_running_mmaps_unix.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/symbolize/gimli/parse_running_mmaps_unix.rs b/src/symbolize/gimli/parse_running_mmaps_unix.rs index 5b342d237..4fbd980ff 100644 --- a/src/symbolize/gimli/parse_running_mmaps_unix.rs +++ b/src/symbolize/gimli/parse_running_mmaps_unix.rs @@ -95,22 +95,22 @@ impl FromStr for MapsEntry { } let (perms_str, s) = s.trim().split_once(' ').unwrap_or((s, "")); - if range_str.is_empty() { + if perms_str.is_empty() { return Err("Couldn't find permissions"); } let (offset_str, s) = s.trim().split_once(' ').unwrap_or((s, "")); - if range_str.is_empty() { + if offset_str.is_empty() { return Err("Couldn't find offset"); } let (dev_str, s) = s.trim().split_once(' ').unwrap_or((s, "")); - if range_str.is_empty() { + if dev_str.is_empty() { return Err("Couldn't find dev"); } let (inode_str, s) = s.trim().split_once(' ').unwrap_or((s, "")); - if range_str.is_empty() { + if inode_str.is_empty() { return Err("Couldn't find inode"); } From c017a001e33790fbbbd3744d70caacaf4121536e Mon Sep 17 00:00:00 2001 From: Mason Remaley Date: Mon, 24 Jul 2023 13:31:57 -0700 Subject: [PATCH 09/22] Adds test for multiple continuous spaces --- src/symbolize/gimli/parse_running_mmaps_unix.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/symbolize/gimli/parse_running_mmaps_unix.rs b/src/symbolize/gimli/parse_running_mmaps_unix.rs index 4fbd980ff..a1e4e780b 100644 --- a/src/symbolize/gimli/parse_running_mmaps_unix.rs +++ b/src/symbolize/gimli/parse_running_mmaps_unix.rs @@ -264,4 +264,18 @@ fn check_maps_entry_parsing_32bit() { pathname: "/executable/path/with some spaces".into(), } ); + assert_eq!( + "b7c79000-b7e02000 r--p 00000000 08:01 60662705 \ + /executable/path/with multiple-continues spaces " + .parse::() + .unwrap(), + MapsEntry { + address: (0xb7c79000, 0xb7e02000), + perms: ['r', '-', '-', 'p'], + offset: 0x00000000, + dev: (0x08, 0x01), + inode: 0x60662705, + pathname: "/executable/path/with multiple-continues spaces".into(), + } + ); } From ce72d89eb85eacfb1e8cdb47fcc37c211ae78dbc Mon Sep 17 00:00:00 2001 From: Mason Remaley Date: Mon, 24 Jul 2023 13:37:19 -0700 Subject: [PATCH 10/22] Replaces most trims with trim_start --- .../gimli/parse_running_mmaps_unix.rs | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/symbolize/gimli/parse_running_mmaps_unix.rs b/src/symbolize/gimli/parse_running_mmaps_unix.rs index a1e4e780b..f3460ad75 100644 --- a/src/symbolize/gimli/parse_running_mmaps_unix.rs +++ b/src/symbolize/gimli/parse_running_mmaps_unix.rs @@ -89,27 +89,27 @@ impl FromStr for MapsEntry { // Note that paths may contain spaces, so we can't use `str::split` for parsing (until // Split::remainder is stabalized #77998). fn from_str(s: &str) -> Result { - let (range_str, s) = s.trim().split_once(' ').unwrap_or((s, "")); + let (range_str, s) = s.trim_start().split_once(' ').unwrap_or((s, "")); if range_str.is_empty() { return Err("Couldn't find address"); } - let (perms_str, s) = s.trim().split_once(' ').unwrap_or((s, "")); + let (perms_str, s) = s.trim_start().split_once(' ').unwrap_or((s, "")); if perms_str.is_empty() { return Err("Couldn't find permissions"); } - let (offset_str, s) = s.trim().split_once(' ').unwrap_or((s, "")); + let (offset_str, s) = s.trim_start().split_once(' ').unwrap_or((s, "")); if offset_str.is_empty() { return Err("Couldn't find offset"); } - let (dev_str, s) = s.trim().split_once(' ').unwrap_or((s, "")); + let (dev_str, s) = s.trim_start().split_once(' ').unwrap_or((s, "")); if dev_str.is_empty() { return Err("Couldn't find dev"); } - let (inode_str, s) = s.trim().split_once(' ').unwrap_or((s, "")); + let (inode_str, s) = s.trim_start().split_once(' ').unwrap_or((s, "")); if inode_str.is_empty() { return Err("Couldn't find inode"); } @@ -278,4 +278,18 @@ fn check_maps_entry_parsing_32bit() { pathname: "/executable/path/with multiple-continues spaces".into(), } ); + assert_eq!( + " b7c79000-b7e02000 r--p 00000000 08:01 60662705 \ + /executable/path/starts-with-spaces" + .parse::() + .unwrap(), + MapsEntry { + address: (0xb7c79000, 0xb7e02000), + perms: ['r', '-', '-', 'p'], + offset: 0x00000000, + dev: (0x08, 0x01), + inode: 0x60662705, + pathname: "/executable/path/starts-with-spaces".into(), + } + ); } From aeb25db61227c22540b4b4263a6602b518796753 Mon Sep 17 00:00:00 2001 From: Mason Remaley Date: Mon, 24 Jul 2023 13:48:00 -0700 Subject: [PATCH 11/22] Allows for paths with trailing spaces --- src/symbolize/gimli/parse_running_mmaps_unix.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/symbolize/gimli/parse_running_mmaps_unix.rs b/src/symbolize/gimli/parse_running_mmaps_unix.rs index f3460ad75..a7121f142 100644 --- a/src/symbolize/gimli/parse_running_mmaps_unix.rs +++ b/src/symbolize/gimli/parse_running_mmaps_unix.rs @@ -115,7 +115,7 @@ impl FromStr for MapsEntry { } // Pathname may be omitted in which case it will be empty - let pathname_str = s.trim(); + let pathname_str = s.trim_start(); let hex = |s| usize::from_str_radix(s, 16).map_err(|_| "Couldn't parse hex number"); let address = if let Some((start, limit)) = range_str.split_once('-') { @@ -275,7 +275,7 @@ fn check_maps_entry_parsing_32bit() { offset: 0x00000000, dev: (0x08, 0x01), inode: 0x60662705, - pathname: "/executable/path/with multiple-continues spaces".into(), + pathname: "/executable/path/with multiple-continues spaces ".into(), } ); assert_eq!( From edad5f0eb7516b62816ade3f70bcbab93354ed13 Mon Sep 17 00:00:00 2001 From: Mason Remaley Date: Sun, 30 Jul 2023 16:04:13 -0400 Subject: [PATCH 12/22] Update src/symbolize/gimli/parse_running_mmaps_unix.rs Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com> --- src/symbolize/gimli/parse_running_mmaps_unix.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/symbolize/gimli/parse_running_mmaps_unix.rs b/src/symbolize/gimli/parse_running_mmaps_unix.rs index a7121f142..a009b92f8 100644 --- a/src/symbolize/gimli/parse_running_mmaps_unix.rs +++ b/src/symbolize/gimli/parse_running_mmaps_unix.rs @@ -266,7 +266,7 @@ fn check_maps_entry_parsing_32bit() { ); assert_eq!( "b7c79000-b7e02000 r--p 00000000 08:01 60662705 \ - /executable/path/with multiple-continues spaces " + /executable/path/with multiple-continuous spaces " .parse::() .unwrap(), MapsEntry { From 45aa13b4b31331da5d493d72e43a78deaa78aaf1 Mon Sep 17 00:00:00 2001 From: Mason Remaley Date: Sun, 30 Jul 2023 16:04:47 -0400 Subject: [PATCH 13/22] Update src/symbolize/gimli/parse_running_mmaps_unix.rs Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com> --- src/symbolize/gimli/parse_running_mmaps_unix.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/symbolize/gimli/parse_running_mmaps_unix.rs b/src/symbolize/gimli/parse_running_mmaps_unix.rs index a009b92f8..acf91e0a8 100644 --- a/src/symbolize/gimli/parse_running_mmaps_unix.rs +++ b/src/symbolize/gimli/parse_running_mmaps_unix.rs @@ -275,7 +275,7 @@ fn check_maps_entry_parsing_32bit() { offset: 0x00000000, dev: (0x08, 0x01), inode: 0x60662705, - pathname: "/executable/path/with multiple-continues spaces ".into(), + pathname: "/executable/path/with multiple-continuous spaces ".into(), } ); assert_eq!( From aa3186abab63415edebe3f1f7061ab8bce0a6f14 Mon Sep 17 00:00:00 2001 From: Mason Remaley Date: Sun, 30 Jul 2023 16:04:55 -0400 Subject: [PATCH 14/22] Update src/symbolize/gimli/parse_running_mmaps_unix.rs Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com> --- src/symbolize/gimli/parse_running_mmaps_unix.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/symbolize/gimli/parse_running_mmaps_unix.rs b/src/symbolize/gimli/parse_running_mmaps_unix.rs index acf91e0a8..5d4b34675 100644 --- a/src/symbolize/gimli/parse_running_mmaps_unix.rs +++ b/src/symbolize/gimli/parse_running_mmaps_unix.rs @@ -87,7 +87,7 @@ impl FromStr for MapsEntry { // e.g.: "35b1a21000-35b1a22000 rw-p 00000000 00:00 0" // // Note that paths may contain spaces, so we can't use `str::split` for parsing (until - // Split::remainder is stabalized #77998). + // Split::remainder is stabilized #77998). fn from_str(s: &str) -> Result { let (range_str, s) = s.trim_start().split_once(' ').unwrap_or((s, "")); if range_str.is_empty() { From 6e15e9b20944da3a943d2d85dac8678581fc9a5a Mon Sep 17 00:00:00 2001 From: Tyler Mandry Date: Thu, 17 Aug 2023 19:39:41 -0400 Subject: [PATCH 15/22] Bump to 0.3.69 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index cff2c9e66..2d1d34fb3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "backtrace" -version = "0.3.68" +version = "0.3.69" authors = ["The Rust Project Developers"] build = "build.rs" license = "MIT OR Apache-2.0" From 2efc59165a7e99bf425b8bb60ccfe9a9e7f23e8b Mon Sep 17 00:00:00 2001 From: Dangyi Liu Date: Thu, 17 Aug 2023 16:58:27 -0700 Subject: [PATCH 16/22] Use extended symbolization markup on Fuchsia (rust-lang/backtrace-rs#559) {{{reset:begin/end}}} pair will allow symbolization to be performed on the whole stack rather than individual frames. --- src/print.rs | 3 ++- src/print/fuchsia.rs | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/print.rs b/src/print.rs index 8d9cbe3d4..395328a0a 100644 --- a/src/print.rs +++ b/src/print.rs @@ -83,7 +83,8 @@ impl<'a, 'b> BacktraceFmt<'a, 'b> { /// This is currently a no-op but is added for future compatibility with /// backtrace formats. pub fn finish(&mut self) -> fmt::Result { - // Currently a no-op-- including this hook to allow for future additions. + #[cfg(target_os = "fuchsia")] + fuchsia::finish_context(self.fmt)?; Ok(()) } diff --git a/src/print/fuchsia.rs b/src/print/fuchsia.rs index ce3f17862..cb872697d 100644 --- a/src/print/fuchsia.rs +++ b/src/print/fuchsia.rs @@ -425,7 +425,7 @@ impl DsoPrinter<'_, '_> { /// This function prints the Fuchsia symbolizer markup for all information contained in a DSO. pub fn print_dso_context(out: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - out.write_str("{{{reset}}}\n")?; + out.write_str("{{{reset:begin}}}\n")?; let mut visitor = DsoPrinter { writer: out, module_count: 0, @@ -434,3 +434,8 @@ pub fn print_dso_context(out: &mut core::fmt::Formatter<'_>) -> core::fmt::Resul for_each_dso(&mut visitor); visitor.error } + +/// This function prints the Fuchsia symbolizer markup to end the backtrace. +pub fn finish_context(out: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + out.write_str("{{{reset:end}}}\n") +} From 40410b7c31618c5ee82501839f7744c379bb9642 Mon Sep 17 00:00:00 2001 From: Philip Craig Date: Fri, 18 Aug 2023 10:04:24 +1000 Subject: [PATCH 17/22] Update addr2line and object dependencies (rust-lang/backtrace-rs#557) --- .github/workflows/main.yml | 2 +- Cargo.toml | 4 ++-- crates/as-if-std/Cargo.toml | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 29fff2795..21d7cb492 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -229,7 +229,7 @@ jobs: with: submodules: true - name: Install Rust - run: rustup update 1.55.0 && rustup default 1.55.0 + run: rustup update 1.65.0 && rustup default 1.65.0 - run: cargo build miri: diff --git a/Cargo.toml b/Cargo.toml index cff2c9e66..40aad711b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,11 +37,11 @@ rustc-serialize = { version = "0.3", optional = true } # Optionally demangle C++ frames' symbols in backtraces. cpp_demangle = { default-features = false, version = "0.4.0", optional = true, features = ["alloc"] } -addr2line = { version = "0.20.0", default-features = false } +addr2line = { version = "0.21.0", default-features = false } miniz_oxide = { version = "0.7.0", default-features = false } [dependencies.object] -version = "0.31.1" +version = "0.32.0" default-features = false features = ['read_core', 'elf', 'macho', 'pe', 'unaligned', 'archive'] diff --git a/crates/as-if-std/Cargo.toml b/crates/as-if-std/Cargo.toml index 012e60f8f..0c9ff007c 100644 --- a/crates/as-if-std/Cargo.toml +++ b/crates/as-if-std/Cargo.toml @@ -15,11 +15,11 @@ bench = false cfg-if = "1.0" rustc-demangle = "0.1.21" libc = { version = "0.2.146", default-features = false } -addr2line = { version = "0.20.0", default-features = false, optional = true } +addr2line = { version = "0.21.0", default-features = false, optional = true } miniz_oxide = { version = "0.7", default-features = false } [dependencies.object] -version = "0.31.1" +version = "0.32.0" default-features = false optional = true features = ['read_core', 'elf', 'macho', 'pe', 'unaligned', 'archive'] From 037356f09a4392dec129b835a42c3bde4067cadf Mon Sep 17 00:00:00 2001 From: mulkieran Date: Thu, 17 Aug 2023 20:14:21 -0400 Subject: [PATCH 18/22] Exclude ci directory from packaged crate (rust-lang/backtrace-rs#555) I do not think there is compelling reason to release the ci support as part of a Rust source code package. In addition, the crate, as it is released now, gets flagged in some security scans due to the presence of Dockerfiles which are considered to be following some unsafe practices. Most Linux distros package using the vendored appraoch and provide a vendor tarfile of an application's dependencies. Scanners will tend to expect that the contents of the vendor tarfile will be source code. These Dockerfiles are already being flagged by some scanners; other contents of the ci directory may be flagged in future. --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 40aad711b..45b6f13b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ A library to acquire a stack trace (backtrace) at runtime in a Rust program. autoexamples = true autotests = true edition = "2018" +exclude = ["/ci/"] [workspace] members = ['crates/cpp_smoke_test', 'crates/as-if-std'] From 347972118810d7d4a32a2f5879d1a260fa68d344 Mon Sep 17 00:00:00 2001 From: Peter Jaszkowiak Date: Thu, 17 Aug 2023 20:22:27 -0600 Subject: [PATCH 19/22] Enable calling build.rs directly from std/build.rs (rust-lang/backtrace-rs#556) Enable calling build.rs directly from std/build.rs and call buildscript in `as-if-std` buildscript to test that it will work during bootstrap. --- build.rs | 12 ++++++++++-- crates/as-if-std/Cargo.toml | 4 ++++ crates/as-if-std/build.rs | 8 ++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/build.rs b/build.rs index 812fbb1fe..9bd3abd16 100644 --- a/build.rs +++ b/build.rs @@ -1,8 +1,10 @@ extern crate cc; use std::env; +use std::path::Path; -fn main() { +// Must be public so the build script of `std` can call it. +pub fn main() { match env::var("CARGO_CFG_TARGET_OS").unwrap_or_default().as_str() { "android" => build_android(), _ => {} @@ -10,7 +12,13 @@ fn main() { } fn build_android() { - let expansion = match cc::Build::new().file("src/android-api.c").try_expand() { + // Resolve `src/android-api.c` relative to this file. + // Required to support calling this from the `std` build script. + let android_api_c = Path::new(file!()) + .parent() + .unwrap() + .join("src/android-api.c"); + let expansion = match cc::Build::new().file(android_api_c).try_expand() { Ok(result) => result, Err(e) => { println!("failed to run C compiler: {}", e); diff --git a/crates/as-if-std/Cargo.toml b/crates/as-if-std/Cargo.toml index 0c9ff007c..bbb76f721 100644 --- a/crates/as-if-std/Cargo.toml +++ b/crates/as-if-std/Cargo.toml @@ -24,6 +24,10 @@ default-features = false optional = true features = ['read_core', 'elf', 'macho', 'pe', 'unaligned', 'archive'] +[build-dependencies] +# Dependency of the `backtrace` crate +cc = "1.0.67" + [features] default = ['backtrace'] backtrace = ['addr2line', 'object'] diff --git a/crates/as-if-std/build.rs b/crates/as-if-std/build.rs index 7018b1017..7669f555d 100644 --- a/crates/as-if-std/build.rs +++ b/crates/as-if-std/build.rs @@ -1,3 +1,11 @@ +// backtrace-rs requires a feature check on Android targets, so +// we need to run its build.rs as well. +#[allow(unused_extern_crates)] +#[path = "../../build.rs"] +mod backtrace_build_rs; + fn main() { println!("cargo:rustc-cfg=backtrace_in_libstd"); + + backtrace_build_rs::main(); } From 8bb67c74a6c7a473ed60cacb69043de7a3032e5b Mon Sep 17 00:00:00 2001 From: klensy Date: Wed, 5 Jul 2023 14:20:37 +0300 Subject: [PATCH 20/22] for windows-msvc targets, dont use miniz_oxide, addr2line, object, libc --- Cargo.toml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 45b6f13b6..4541e60bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,6 @@ exclude = [ [dependencies] cfg-if = "1.0" rustc-demangle = "0.1.4" -libc = { version = "0.2.146", default-features = false } # Optionally enable the ability to serialize a `Backtrace`, controlled through # the `serialize-*` features below. @@ -38,10 +37,12 @@ rustc-serialize = { version = "0.3", optional = true } # Optionally demangle C++ frames' symbols in backtraces. cpp_demangle = { default-features = false, version = "0.4.0", optional = true, features = ["alloc"] } -addr2line = { version = "0.21.0", default-features = false } +[target.'cfg(not(all(windows, target_env = "msvc", not(target_vendor = "uwp"))))'.dependencies] miniz_oxide = { version = "0.7.0", default-features = false } +addr2line = { version = "0.21.0", default-features = false } +libc = { version = "0.2.146", default-features = false } -[dependencies.object] +[target.'cfg(not(all(windows, target_env = "msvc", not(target_vendor = "uwp"))))'.dependencies.object] version = "0.32.0" default-features = false features = ['read_core', 'elf', 'macho', 'pe', 'unaligned', 'archive'] From b6d24cdeffd590c54b19ac678ec7679ee6960a18 Mon Sep 17 00:00:00 2001 From: klensy Date: Thu, 6 Jul 2023 15:55:06 +0300 Subject: [PATCH 21/22] gate gimli usage on windows with gnu --- src/symbolize/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/symbolize/mod.rs b/src/symbolize/mod.rs index dbc346522..a7c199506 100644 --- a/src/symbolize/mod.rs +++ b/src/symbolize/mod.rs @@ -471,7 +471,7 @@ cfg_if::cfg_if! { mod dbghelp; use dbghelp as imp; } else if #[cfg(all( - any(unix, windows), + any(unix, all(windows, target_env = "gnu")), not(target_vendor = "uwp"), not(target_os = "emscripten"), any(not(backtrace_in_libstd), feature = "backtrace"), From 56c215e92a8de2346084ed6415d3cc7937ce1b78 Mon Sep 17 00:00:00 2001 From: klensy Date: Sat, 8 Jul 2023 14:04:43 +0300 Subject: [PATCH 22/22] sync as-if-std crate --- crates/as-if-std/Cargo.toml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/as-if-std/Cargo.toml b/crates/as-if-std/Cargo.toml index bbb76f721..bcbcfe159 100644 --- a/crates/as-if-std/Cargo.toml +++ b/crates/as-if-std/Cargo.toml @@ -15,10 +15,12 @@ bench = false cfg-if = "1.0" rustc-demangle = "0.1.21" libc = { version = "0.2.146", default-features = false } -addr2line = { version = "0.21.0", default-features = false, optional = true } -miniz_oxide = { version = "0.7", default-features = false } -[dependencies.object] +[target.'cfg(not(all(windows, target_env = "msvc", not(target_vendor = "uwp"))))'.dependencies] +miniz_oxide = { version = "0.7.0", optional = true, default-features = false } +addr2line = { version = "0.21.0", optional = true, default-features = false } + +[target.'cfg(not(all(windows, target_env = "msvc", not(target_vendor = "uwp"))))'.dependencies.object] version = "0.32.0" default-features = false optional = true @@ -30,4 +32,4 @@ cc = "1.0.67" [features] default = ['backtrace'] -backtrace = ['addr2line', 'object'] +backtrace = ['addr2line', 'miniz_oxide', 'object']