From ee9c98039acc6932da7c73d0bf55f1f0b51108fd Mon Sep 17 00:00:00 2001 From: Jaroslav Bachorik Date: Wed, 28 May 2025 10:19:35 +0200 Subject: [PATCH] Patch upstream stackWalker.cpp not to fail on unaligned access --- ddprof-lib/build.gradle | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/ddprof-lib/build.gradle b/ddprof-lib/build.gradle index 493f05af..9ceb5c4c 100644 --- a/ddprof-lib/build.gradle +++ b/ddprof-lib/build.gradle @@ -215,9 +215,34 @@ def patchStackFrame = tasks.register("patchStackFrame") { } } +def patchStackWalker = tasks.register("patchStackWalker") { + description = 'Patch stackWalker.cpp after copying' + configure { + dependsOn copyUpstreamFiles + } + doLast { + def file = file("${projectDir}/src/main/cpp-external/stackWalker.cpp") + if (!file.exists()) throw new GradleException("File not found: ${file}") + + def content = file.getText('UTF-8') + def original = content + + // Add no_sanitize to walkVM + content = content.replaceAll( + /(int\s+StackWalker::walkVM\s*\()/, + '__attribute__((no_sanitize("address"))) int StackWalker::walkVM(' + ) + + if (content != original) { + file.write(content, 'UTF-8') + println "Patched stackWalker.cpp" + } + } +} + def initSubrepoTask = tasks.register('initSubrepo') { configure { - dependsOn copyUpstreamFiles, patchStackFrame + dependsOn copyUpstreamFiles, patchStackFrame, patchStackWalker } }