From 4b0ed4fd8a8ef1955179fe5ca2a4420d9fdba002 Mon Sep 17 00:00:00 2001 From: Matt Wozniski Date: Thu, 25 Jul 2024 19:35:30 -0400 Subject: [PATCH] Simplify updating libbacktrace Previously our `regenerate_libbacktrace.sh` script could only clone the repo and re-apply our existing patches. Give it the ability to also update to a different commit and rebase our patches. If the rebasing fails, have it leave the `.git` directory around so that a developer can manually rebase and finish the job. Signed-off-by: Matt Wozniski --- ...-internal-functions-of-libbacktrace.patch} | 17 ++++++++ ...-debuginfod-support-to-libbacktrace.patch} | 17 ++++++++ src/vendor/regenerate_libbacktrace.sh | 40 +++++++++++++------ 3 files changed, 62 insertions(+), 12 deletions(-) rename src/vendor/{libbacktrace_7e2b7da3d6568d2e4e78658f22e701746a48d7e1_patch.diff => libbacktrace-patches/0001-Expose-some-internal-functions-of-libbacktrace.patch} (93%) rename src/vendor/{libbacktrace_7e2b7da3d6568d2e4e78658f22e701746a48d7e1_debuginfod_patch.diff => libbacktrace-patches/0002-Add-debuginfod-support-to-libbacktrace.patch} (94%) diff --git a/src/vendor/libbacktrace_7e2b7da3d6568d2e4e78658f22e701746a48d7e1_patch.diff b/src/vendor/libbacktrace-patches/0001-Expose-some-internal-functions-of-libbacktrace.patch similarity index 93% rename from src/vendor/libbacktrace_7e2b7da3d6568d2e4e78658f22e701746a48d7e1_patch.diff rename to src/vendor/libbacktrace-patches/0001-Expose-some-internal-functions-of-libbacktrace.patch index 2416439ccc..98613ae5e6 100644 --- a/src/vendor/libbacktrace_7e2b7da3d6568d2e4e78658f22e701746a48d7e1_patch.diff +++ b/src/vendor/libbacktrace-patches/0001-Expose-some-internal-functions-of-libbacktrace.patch @@ -1,3 +1,17 @@ +From d99c0a30bacfe6cae604a85250f12587d0fee932 Mon Sep 17 00:00:00 2001 +From: Matt Wozniski +Date: Thu, 25 Jul 2024 18:59:09 -0400 +Subject: [PATCH] Expose some internal functions of libbacktrace + +Memray uses these for more control than the public entry points give. +--- + Makefile.am | 2 +- + Makefile.in | 2 +- + elf.c | 10 +++++----- + internal.h | 39 +++++++++++++++++++++++++++++++++++++++ + macho.c | 31 +++++++++++++++++++------------ + 5 files changed, 65 insertions(+), 19 deletions(-) + diff --git a/Makefile.am b/Makefile.am index 4d509a2..f80a9e6 100644 --- a/Makefile.am @@ -224,3 +238,6 @@ index fc4c959..527c5ac 100644 break; default: error_callback (data, "executable file is not an executable", 0); +-- +2.42.3 + diff --git a/src/vendor/libbacktrace_7e2b7da3d6568d2e4e78658f22e701746a48d7e1_debuginfod_patch.diff b/src/vendor/libbacktrace-patches/0002-Add-debuginfod-support-to-libbacktrace.patch similarity index 94% rename from src/vendor/libbacktrace_7e2b7da3d6568d2e4e78658f22e701746a48d7e1_debuginfod_patch.diff rename to src/vendor/libbacktrace-patches/0002-Add-debuginfod-support-to-libbacktrace.patch index 0ab2bce73f..b6cb2b0485 100644 --- a/src/vendor/libbacktrace_7e2b7da3d6568d2e4e78658f22e701746a48d7e1_debuginfod_patch.diff +++ b/src/vendor/libbacktrace-patches/0002-Add-debuginfod-support-to-libbacktrace.patch @@ -1,3 +1,17 @@ +From b052eda140ac673de19a3060523fb250d898ffb6 Mon Sep 17 00:00:00 2001 +From: Matt Wozniski +Date: Thu, 25 Jul 2024 18:59:10 -0400 +Subject: [PATCH] Add debuginfod support to libbacktrace + +Allow fetching debug info from a debuginfod server when unwinding. +--- + Makefile.am | 5 +- + Makefile.in | 5 +- + debuginfod_support.h | 115 +++++++++++++++++++++++++++++++++++++++++++ + elf.c | 64 ++++++++++++++++++++++++ + 4 files changed, 185 insertions(+), 4 deletions(-) + create mode 100644 debuginfod_support.h + diff --git a/Makefile.am b/Makefile.am index f80a9e6..15e87c7 100644 --- a/Makefile.am @@ -283,3 +297,6 @@ index 80482a4..61f08af 100644 if (!state->threaded) { +-- +2.42.3 + diff --git a/src/vendor/regenerate_libbacktrace.sh b/src/vendor/regenerate_libbacktrace.sh index 989380b7b7..ae616d0c15 100755 --- a/src/vendor/regenerate_libbacktrace.sh +++ b/src/vendor/regenerate_libbacktrace.sh @@ -1,23 +1,39 @@ #!/usr/bin/env bash set -Eeuo pipefail -SNAPSHOT_COMMIT=7e2b7da3d6568d2e4e78658f22e701746a48d7e1 -LIBBACKTRACE_DIR="libbacktrace" +if [[ $# -ne 0 ]] && [[ $# -ne 1 ]]; then + echo "Usage: $0 [new-commit]" + exit 1 +fi -echo "checking" $(ls) +old_snapshot=7e2b7da3d6568d2e4e78658f22e701746a48d7e1 +new_snapshot=${1:-} echo ">>> Cloning libbacktrace" -rm -rf "$LIBBACKTRACE_DIR" -git clone https://github.com/ianlancetaylor/libbacktrace.git "$LIBBACKTRACE_DIR" +rm -rf libbacktrace +git clone https://github.com/ianlancetaylor/libbacktrace.git libbacktrace -echo ">>> Checking out commit ${SNAPSHOT_COMMIT}" -cd "$LIBBACKTRACE_DIR" -git checkout $SNAPSHOT_COMMIT 1>/dev/null +echo "Applying patches" +cd libbacktrace +git checkout "$old_snapshot" +git am ../libbacktrace-patches/* + +if [[ -n "$new_snapshot" ]]; then + echo "Rebasing on $new_snapshot" + if git rebase "$new_snapshot"; then + echo "Rebased successfully. Updating patches." + (cd ../libbacktrace-patches && git rm -f 0*) + git format-patch "$new_snapshot" --no-numbered --output-directory=../libbacktrace-patches + (cd ../libbacktrace-patches && git add 0*) + else + echo "Failed to apply patches. You must finish rebasing manually." + echo "When you are satisfied, update the patches by running:" + echo " git format-patch $new_snapshot --no-numbered --output-directory=../libbacktrace-patches" + echo "Be sure to remove the old patches first if the file names will change." + exit 1 + fi +fi -echo ">>> Applying main patch for commit ${SNAPSHOT_COMMIT}" -git apply ../libbacktrace_${SNAPSHOT_COMMIT}_patch.diff -echo ">>> Applying debuginfod patch for commit ${SNAPSHOT_COMMIT}" -git apply ../libbacktrace_${SNAPSHOT_COMMIT}_debuginfod_patch.diff rm -rf .git echo "Regenerated vendored libbacktrace"