Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 39 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ if(NOT absl_FOUND)
set(BUILD_TESTING "${BLOATY_BUILD_TESTING_SAVE}")
endif()

add_definitions(-D_LIBCXXABI_FUNC_VIS=) # For Demumble.
if(BLOATY_ENABLE_RE2)
add_definitions(-DUSE_RE2)
endif()
Expand Down Expand Up @@ -190,6 +189,9 @@ if(NOT absl_FOUND)
endif()
include_directories("${CMAKE_CURRENT_BINARY_DIR}/src")

include_directories(third_party/demumble/third_party/llvm/include)
include_directories(third_party/demumble/third_party/swift/include)

# Baseline build flags.
if(MSVC)
set(CMAKE_CXX_FLAGS "/EHsc /wd4018 /D_CRT_SECURE_NO_WARNINGS /DNOMINMAX")
Expand All @@ -198,9 +200,23 @@ else()
set(CMAKE_CXX_FLAGS_DEBUG "-g1")
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g1")
set_source_files_properties(third_party/demumble/third_party/libcxxabi/cxa_demangle.cpp PROPERTIES COMPILE_FLAGS -Wno-implicit-fallthrough)
set_source_files_properties(third_party/demumble/third_party/llvm/lib/Demangle/MicrosoftDemangle.cpp
third_party/demumble/third_party/llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
third_party/demumble/third_party/swift/lib/Demangling/Demangler.cpp
third_party/demumble/third_party/swift/lib/Demangling/Errors.cpp
third_party/demumble/third_party/swift/lib/Demangling/NodePrinter.cpp
third_party/demumble/third_party/swift/lib/Demangling/OldDemangler.cpp
third_party/demumble/third_party/swift/lib/Demangling/OldRemangler.cpp
third_party/demumble/third_party/swift/lib/Demangling/Remangler.cpp
PROPERTIES COMPILE_FLAGS -Wno-unused-parameter)
endif()

add_definitions(
-DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING=1
-DSWIFT_STDLIB_HAS_TYPE_PRINTING=1
-DSWIFT_SUPPORT_OLD_MANGLING=1
)

if(APPLE)
elseif(UNIX)
if(BLOATY_ENABLE_BUILDID)
Expand Down Expand Up @@ -276,8 +292,27 @@ add_library(libbloaty STATIC
src/util.cc
src/util.h
src/webassembly.cc
# One source file, no special build system needed.
third_party/demumble/third_party/libcxxabi/cxa_demangle.cpp

# Demumble has an open issue build as a library.
# See https://github.com/nico/demumble/issues/39

third_party/demumble/third_party/llvm/lib/Demangle/Demangle.cpp
third_party/demumble/third_party/llvm/lib/Demangle/DLangDemangle.cpp
third_party/demumble/third_party/llvm/lib/Demangle/ItaniumDemangle.cpp
third_party/demumble/third_party/llvm/lib/Demangle/MicrosoftDemangle.cpp
third_party/demumble/third_party/llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
third_party/demumble/third_party/llvm/lib/Demangle/RustDemangle.cpp
third_party/demumble/third_party/swift/lib/Demangling/Context.cpp
third_party/demumble/third_party/swift/lib/Demangling/CrashReporter.cpp
third_party/demumble/third_party/swift/lib/Demangling/Demangler.cpp
third_party/demumble/third_party/swift/lib/Demangling/Errors.cpp
third_party/demumble/third_party/swift/lib/Demangling/ManglingUtils.cpp
third_party/demumble/third_party/swift/lib/Demangling/NodeDumper.cpp
third_party/demumble/third_party/swift/lib/Demangling/NodePrinter.cpp
third_party/demumble/third_party/swift/lib/Demangling/OldDemangler.cpp
third_party/demumble/third_party/swift/lib/Demangling/OldRemangler.cpp
third_party/demumble/third_party/swift/lib/Demangling/Punycode.cpp
third_party/demumble/third_party/swift/lib/Demangling/Remangler.cpp
)
set_property(TARGET libbloaty PROPERTY FOLDER "bloaty")

Expand Down
39 changes: 32 additions & 7 deletions src/bloaty.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ typedef size_t z_size_t;
#include "bloaty.pb.h"
#include "google/protobuf/io/zero_copy_stream_impl.h"
#include "google/protobuf/text_format.h"
#include "llvm/Demangle/Demangle.h"
#include "re.h"
#include "swift/Demangling/Demangle.h"
#include "util.h"

using std::string_view;
Expand Down Expand Up @@ -162,9 +164,6 @@ static std::string CSVEscape(string_view str) {
}
}

extern "C" char* __cxa_demangle(const char* mangled_name, char* buf, size_t* n,
int* status);

std::string ItaniumDemangle(string_view symbol, DataSource source) {
if (source != DataSource::kShortSymbols &&
source != DataSource::kFullSymbols) {
Expand All @@ -182,15 +181,41 @@ std::string ItaniumDemangle(string_view symbol, DataSource source) {
if (absl::debugging_internal::Demangle(demangle_from.data(), demangled,
Comment thread
EricRahm marked this conversation as resolved.
sizeof(demangled))) {
return std::string(demangled);
} else if (char* ms = llvm::microsoftDemangle(
demangle_from, NULL, NULL,
llvm::MSDemangleFlags(llvm::MSDF_NoAccessSpecifier |
llvm::MSDF_NoCallingConvention |
llvm::MSDF_NoMemberType |
llvm::MSDF_NoReturnType))) {
std::string ret(ms);
free(ms);
return ret;
} else if (swift::Demangle::isSwiftSymbol(demangle_from)) {
Comment thread
EricRahm marked this conversation as resolved.
auto Opts =
swift::Demangle::DemangleOptions::SimplifiedUIDemangleOptions();
std::string swift =
swift::Demangle::demangleSymbolAsString(demangle_from, Opts);
return swift;
} else {
return std::string(symbol);
}
} else if (source == DataSource::kFullSymbols) {
char* demangled = __cxa_demangle(demangle_from.data(), NULL, NULL, NULL);
if (demangled) {
std::string ret(demangled);
free(demangled);
if (char* itanium = llvm::itaniumDemangle(demangle_from)) {
std::string ret(itanium);
free(itanium);
return ret;
} else if (char* ms = llvm::microsoftDemangle(demangle_from, NULL, NULL)) {
std::string ret(ms);
free(ms);
return ret;
} else if (char* rust = llvm::rustDemangle(demangle_from)) {
std::string ret(rust);
free(rust);
return ret;
} else if (swift::Demangle::isSwiftSymbol(demangle_from)) {
swift::Demangle::DemangleOptions options;
options.SynthesizeSugarOnTypes = true;
return swift::Demangle::demangleSymbolAsString(demangle_from, options);
} else {
return std::string(symbol);
}
Expand Down
50 changes: 50 additions & 0 deletions tests/elf/demangle-multi.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Test that bloaty can demangle Swift, Rust, Microsoft, and complex C++ symbols using demumble

# RUN: %yaml2obj %s -o %t.obj
# RUN: %bloaty %t.obj -d fullsymbols | %FileCheck %s --check-prefix=FULL
# RUN: %bloaty %t.obj -d shortsymbols | %FileCheck %s --check-prefix=SHORT

# FULL-DAG: test.hello() -> ()
# FULL-DAG: foo::bar::<>
# FULL-DAG: void __cdecl test(void)
# FULL-DAG: __llvm_libc_21_0_0_git::cpp::enable_if<cpp::is_floating_point_v<_Float16> && FPBits<_Float16>::FRACTION_LEN < 64ul, _Float16>::type __llvm_libc_21_0_0_git::fputil::DyadicFloat<64ul>::generic_as<_Float16, true>() const

# SHORT-DAG: hello()
# SHORT-DAG: foo::bar::<>
# SHORT-DAG: test(void)
# SHORT-DAG: __llvm_libc_21_0_0_git::fputil::DyadicFloat<>::generic_as<>()

--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
Sections:
- Name: .text
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
AddressAlign: 0x10
Content: '90909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090'
Symbols:
- Name: _$s4test5helloyyF
Type: STT_FUNC
Section: .text
Value: 0x0
Size: 0x10
- Name: _RINvC3foo3barE
Type: STT_FUNC
Section: .text
Value: 0x10
Size: 0x10
- Name: '?test@@YAXXZ'
Type: STT_FUNC
Section: .text
Value: 0x20
Size: 0x10
- Name: _ZNK22__llvm_libc_21_0_0_git6fputil11DyadicFloatILm64EE10generic_asIDF16_Lb1EEENS_3cpp9enable_ifIXaasr3cppE19is_floating_point_vIT_Eltsr6FPBitsIS6_EE12FRACTION_LENLm64EES6_E4typeEv
Type: STT_FUNC
Section: .text
Value: 0x30
Size: 0x10
...
2 changes: 1 addition & 1 deletion third_party/demumble
Submodule demumble updated 86 files
+31 −0 .github/workflows/test.yml
+18 −0 .gitignore
+57 −24 CMakeLists.txt
+27 −15 README.md
+10 −9 RELEASING
+87 −50 demumble.cc
+33 −9 demumble_test.py
+141 −0 dist.py
+84 −0 scripts/copy-swift-demangle.sh
+0 −37 third_party/libcxxabi/LICENSE.txt
+0 −4,992 third_party/libcxxabi/cxa_demangle.cpp
+279 −0 third_party/llvm/LICENSE.txt
+80 −0 third_party/llvm/include/llvm-c/DataTypes.h
+135 −0 third_party/llvm/include/llvm/ADT/ADL.h
+325 −0 third_party/llvm/include/llvm/ADT/DenseMapInfo.h
+680 −0 third_party/llvm/include/llvm/ADT/Hashing.h
+2,568 −0 third_party/llvm/include/llvm/ADT/STLExtras.h
+72 −0 third_party/llvm/include/llvm/ADT/STLForwardCompat.h
+76 −0 third_party/llvm/include/llvm/ADT/STLFunctionalExtras.h
+926 −0 third_party/llvm/include/llvm/ADT/StringRef.h
+196 −0 third_party/llvm/include/llvm/ADT/StringSwitch.h
+422 −0 third_party/llvm/include/llvm/ADT/bit.h
+378 −0 third_party/llvm/include/llvm/ADT/iterator.h
+86 −0 third_party/llvm/include/llvm/ADT/iterator_range.h
+62 −0 third_party/llvm/include/llvm/Config/abi-breaking.h
+204 −0 third_party/llvm/include/llvm/Config/llvm-config.h
+549 −0 third_party/llvm/include/llvm/Demangle/Compiler.h
+132 −0 third_party/llvm/include/llvm/Demangle/Demangle.h
+97 −0 third_party/llvm/include/llvm/Demangle/DemangleConfig.h
+5,954 −0 third_party/llvm/include/llvm/Demangle/ItaniumDemangle.h
+104 −0 third_party/llvm/include/llvm/Demangle/ItaniumNodes.def
+289 −0 third_party/llvm/include/llvm/Demangle/MicrosoftDemangle.h
+629 −0 third_party/llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
+122 −0 third_party/llvm/include/llvm/Demangle/StringView.h
+38 −0 third_party/llvm/include/llvm/Demangle/StringViewExtras.h
+203 −0 third_party/llvm/include/llvm/Demangle/Utility.h
+852 −0 third_party/llvm/include/llvm/Support/Casting.h
+607 −0 third_party/llvm/include/llvm/Support/Compiler.h
+21 −0 third_party/llvm/include/llvm/Support/DataTypes.h
+157 −0 third_party/llvm/include/llvm/Support/ErrorHandling.h
+68 −0 third_party/llvm/include/llvm/Support/SwapByteOrder.h
+97 −0 third_party/llvm/include/llvm/Support/type_traits.h
+594 −0 third_party/llvm/lib/Demangle/DLangDemangle.cpp
+73 −0 third_party/llvm/lib/Demangle/Demangle.cpp
+597 −0 third_party/llvm/lib/Demangle/ItaniumDemangle.cpp
+2,465 −0 third_party/llvm/lib/Demangle/MicrosoftDemangle.cpp
+658 −0 third_party/llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
+1,259 −0 third_party/llvm/lib/Demangle/RustDemangle.cpp
+211 −0 third_party/swift/LICENSE.txt
+31 −0 third_party/swift/include/swift/ABI/InvertibleProtocols.def
+168 −0 third_party/swift/include/swift/AST/Ownership.h
+202 −0 third_party/swift/include/swift/AST/ReferenceStorage.def
+200 −0 third_party/swift/include/swift/Basic/Assertions.h
+189 −0 third_party/swift/include/swift/Basic/InlineBitfield.h
+114 −0 third_party/swift/include/swift/Basic/LLVM.h
+90 −0 third_party/swift/include/swift/Basic/MacroRoles.def
+798 −0 third_party/swift/include/swift/Basic/STLExtras.h
+798 −0 third_party/swift/include/swift/Demangling/Demangle.h
+402 −0 third_party/swift/include/swift/Demangling/DemangleNodes.def
+696 −0 third_party/swift/include/swift/Demangling/Demangler.h
+70 −0 third_party/swift/include/swift/Demangling/Errors.h
+96 −0 third_party/swift/include/swift/Demangling/ManglingMacros.h
+337 −0 third_party/swift/include/swift/Demangling/ManglingUtils.h
+35 −0 third_party/swift/include/swift/Demangling/NamespaceMacros.h
+68 −0 third_party/swift/include/swift/Demangling/Punycode.h
+104 −0 third_party/swift/include/swift/Demangling/StandardTypesMangling.def
+1,897 −0 third_party/swift/include/swift/Demangling/TypeDecoder.h
+222 −0 third_party/swift/include/swift/Demangling/TypeLookupError.h
+41 −0 third_party/swift/include/swift/Demangling/ValueWitnessMangling.def
+187 −0 third_party/swift/include/swift/Strings.h
+291 −0 third_party/swift/lib/Demangling/Context.cpp
+35 −0 third_party/swift/lib/Demangling/CrashReporter.cpp
+50 −0 third_party/swift/lib/Demangling/CrashReporter.h
+4,380 −0 third_party/swift/lib/Demangling/Demangler.cpp
+67 −0 third_party/swift/lib/Demangling/DemanglerAssert.h
+227 −0 third_party/swift/lib/Demangling/Errors.cpp
+86 −0 third_party/swift/lib/Demangling/ManglingUtils.cpp
+78 −0 third_party/swift/lib/Demangling/NodeDumper.cpp
+3,724 −0 third_party/swift/lib/Demangling/NodePrinter.cpp
+2,406 −0 third_party/swift/lib/Demangling/OldDemangler.cpp
+3,056 −0 third_party/swift/lib/Demangling/OldRemangler.cpp
+370 −0 third_party/swift/lib/Demangling/Punycode.cpp
+4,155 −0 third_party/swift/lib/Demangling/Remangler.cpp
+197 −0 third_party/swift/lib/Demangling/RemanglerBase.h
+0 −185 third_party/wine/LICENSE.txt
+0 −1,628 third_party/wine/undname.c