[compiler-rt] [compiler-rt][GWP-ASan] Use no-op backtrace if execinfo.h missing (PR #201266)
Brian Cain via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 2 21:27:52 PDT 2026
https://github.com/androm3da created https://github.com/llvm/llvm-project/pull/201266
backtrace_linux_libc.cpp requires execinfo.h, which is not present in some C libraries (musl for example).
Add a cmake check_include_file guard: on targets with execinfo.h the existing RTGwpAsanBacktraceLibc is built unchanged; on targets without it a new RTGwpAsanBacktraceNone stub is built instead (all three function pointers return nullptr). Mirror the same check in scudo/standalone so it links against whichever library was built.
>From 7d81f91ec3d9599511899cf775d2d5e0969dca81 Mon Sep 17 00:00:00 2001
From: Brian Cain <brian.cain at oss.qualcomm.com>
Date: Tue, 2 Jun 2026 19:50:25 -0500
Subject: [PATCH] [compiler-rt][GWP-ASan] Use no-op backtrace if execinfo.h
missing
backtrace_linux_libc.cpp requires execinfo.h, which is not present in some
C libraries (musl for example).
Add a cmake check_include_file guard: on targets with execinfo.h the existing
RTGwpAsanBacktraceLibc is built unchanged; on targets without it a new
RTGwpAsanBacktraceNone stub is built instead (all three function pointers
return nullptr). Mirror the same check in scudo/standalone so it links
against whichever library was built.
---
compiler-rt/lib/gwp_asan/CMakeLists.txt | 23 +++++++++++++++----
.../lib/gwp_asan/optional/backtrace_none.cpp | 22 ++++++++++++++++++
.../lib/scudo/standalone/CMakeLists.txt | 11 ++++++++-
3 files changed, 50 insertions(+), 6 deletions(-)
create mode 100644 compiler-rt/lib/gwp_asan/optional/backtrace_none.cpp
diff --git a/compiler-rt/lib/gwp_asan/CMakeLists.txt b/compiler-rt/lib/gwp_asan/CMakeLists.txt
index f638adda3abe1..6a7aaf19d05a1 100644
--- a/compiler-rt/lib/gwp_asan/CMakeLists.txt
+++ b/compiler-rt/lib/gwp_asan/CMakeLists.txt
@@ -90,11 +90,24 @@ add_compiler_rt_object_libraries(RTGwpAsanOptionsParser
CFLAGS ${GWP_ASAN_OPTIONS_PARSER_CFLAGS})
# As above, build the pre-implemented optional backtrace support libraries.
-add_compiler_rt_object_libraries(RTGwpAsanBacktraceLibc
- ARCHS ${GWP_ASAN_SUPPORTED_ARCH}
- SOURCES optional/backtrace_linux_libc.cpp
- ADDITIONAL_HEADERS ${GWP_ASAN_BACKTRACE_HEADERS}
- CFLAGS ${GWP_ASAN_CFLAGS})
+# backtrace_linux_libc.cpp requires execinfo.h. On targets without it
+# build RTGwpAsanBacktraceNone which provides null stubs so that
+# GWP-ASan still functions as a guard allocator without stack-trace capture.
+include(CheckIncludeFile)
+check_include_file(execinfo.h COMPILER_RT_HAS_EXECINFO_H)
+if(COMPILER_RT_HAS_EXECINFO_H)
+ add_compiler_rt_object_libraries(RTGwpAsanBacktraceLibc
+ ARCHS ${GWP_ASAN_SUPPORTED_ARCH}
+ SOURCES optional/backtrace_linux_libc.cpp
+ ADDITIONAL_HEADERS ${GWP_ASAN_BACKTRACE_HEADERS}
+ CFLAGS ${GWP_ASAN_CFLAGS})
+else()
+ add_compiler_rt_object_libraries(RTGwpAsanBacktraceNone
+ ARCHS ${GWP_ASAN_SUPPORTED_ARCH}
+ SOURCES optional/backtrace_none.cpp
+ ADDITIONAL_HEADERS ${GWP_ASAN_BACKTRACE_HEADERS}
+ CFLAGS ${GWP_ASAN_CFLAGS})
+endif()
add_compiler_rt_object_libraries(RTGwpAsanSegvHandler
ARCHS ${GWP_ASAN_SUPPORTED_ARCH}
SOURCES optional/segv_handler_posix.cpp
diff --git a/compiler-rt/lib/gwp_asan/optional/backtrace_none.cpp b/compiler-rt/lib/gwp_asan/optional/backtrace_none.cpp
new file mode 100644
index 0000000000000..0530d2bb0c993
--- /dev/null
+++ b/compiler-rt/lib/gwp_asan/optional/backtrace_none.cpp
@@ -0,0 +1,22 @@
+//===-- backtrace_none.cpp --------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+// Stub backtrace implementation for targets where execinfo.h is unavailable
+// (e.g. musl libc). GWP-ASan still functions as a guard allocator; only
+// the stack-trace capture is absent.
+
+#include "gwp_asan/optional/backtrace.h"
+
+namespace gwp_asan {
+namespace backtrace {
+
+options::Backtrace_t getBacktraceFunction() { return nullptr; }
+PrintBacktrace_t getPrintBacktraceFunction() { return nullptr; }
+SegvBacktrace_t getSegvBacktraceFunction() { return nullptr; }
+
+} // namespace backtrace
+} // namespace gwp_asan
diff --git a/compiler-rt/lib/scudo/standalone/CMakeLists.txt b/compiler-rt/lib/scudo/standalone/CMakeLists.txt
index 20c59b4600613..1718f7e083f61 100644
--- a/compiler-rt/lib/scudo/standalone/CMakeLists.txt
+++ b/compiler-rt/lib/scudo/standalone/CMakeLists.txt
@@ -169,8 +169,17 @@ if (COMPILER_RT_HAS_GWP_ASAN)
endif()
add_dependencies(scudo_standalone gwp_asan)
+ # RTGwpAsanBacktraceLibc requires execinfo.h (not available on some C
+ # libs. Use RTGwpAsanBacktraceNone which provides null stubs.
+ include(CheckIncludeFile)
+ check_include_file(execinfo.h COMPILER_RT_HAS_EXECINFO_H)
+ if(COMPILER_RT_HAS_EXECINFO_H)
+ set(_gwp_asan_backtrace_lib RTGwpAsanBacktraceLibc)
+ else()
+ set(_gwp_asan_backtrace_lib RTGwpAsanBacktraceNone)
+ endif()
list(APPEND SCUDO_OBJECT_LIBS
- RTGwpAsan RTGwpAsanBacktraceLibc RTGwpAsanSegvHandler
+ RTGwpAsan ${_gwp_asan_backtrace_lib} RTGwpAsanSegvHandler
RTGwpAsanOptionsParser)
append_list_if(COMPILER_RT_HAS_OMIT_FRAME_POINTER_FLAG -fno-omit-frame-pointer
More information about the llvm-commits
mailing list