[PATCH v1 08/13] tools build: Add feature test for abi::__cxa_demangle

From: Ian Rogers
Date: Sat Mar 11 2023 - 01:59:54 EST


cxxabi.h is part of libsdtc++ and LLVM's libcxx, providing
abi::__cxa_demangle a portable C++ demangler. Add a feature test to
detect that the function is available.

Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/build/Makefile.feature | 1 +
tools/build/feature/Makefile | 4 ++++
tools/build/feature/test-cxa-demangle.cpp | 17 +++++++++++++++++
3 files changed, 22 insertions(+)
create mode 100644 tools/build/feature/test-cxa-demangle.cpp

diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature
index 38f8851bd7cb..214622d7537c 100644
--- a/tools/build/Makefile.feature
+++ b/tools/build/Makefile.feature
@@ -80,6 +80,7 @@ FEATURE_TESTS_EXTRA := \
compile-32 \
compile-x32 \
cplus-demangle \
+ cxa-demangle \
gtk2 \
gtk2-infobar \
hello \
diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index dc9323e01e42..0a3b9281f8b0 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -23,6 +23,7 @@ FILES= \
test-libbfd-liberty.bin \
test-libbfd-liberty-z.bin \
test-cplus-demangle.bin \
+ test-cxa-demangle.bin \
test-libcap.bin \
test-libelf.bin \
test-libelf-getphdrnum.bin \
@@ -262,6 +263,9 @@ $(OUTPUT)test-libbfd-liberty-z.bin:
$(OUTPUT)test-cplus-demangle.bin:
$(BUILD) -liberty

+$(OUTPUT)test-cxa-demangle.bin:
+ $(BUILDXX)
+
$(OUTPUT)test-backtrace.bin:
$(BUILD)

diff --git a/tools/build/feature/test-cxa-demangle.cpp b/tools/build/feature/test-cxa-demangle.cpp
new file mode 100644
index 000000000000..a3e712f65c37
--- /dev/null
+++ b/tools/build/feature/test-cxa-demangle.cpp
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <stdio.h>
+#include <stdlib.h>
+#include <cxxabi.h>
+
+int main(void)
+{
+ size_t len = 256;
+ char *output = (char*)malloc(len);
+ int status;
+
+ output = abi::__cxa_demangle("FieldName__9ClassNameFd", output, &len, &status);
+
+ printf("demangled symbol: {%s}\n", output);
+
+ return 0;
+}
--
2.40.0.rc1.284.g88254d51c5-goog