Skip to content

Commit

Permalink
v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nico committed Aug 5, 2024
2 parents c874601 + 0bdefcd commit e82c452
Show file tree
Hide file tree
Showing 72 changed files with 34,869 additions and 146 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Build and test

on: [push, pull_request]
on: {push: { branches: [main] }, pull_request: {}}

jobs:
build:
Expand Down
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ if (WIN32)
endif()

include_directories(third_party/llvm/include)
include_directories(third_party/swift/include)
add_definitions(
-DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING=1
-DSWIFT_SUPPORT_OLD_MANGLING=1
-DSWIFT_STDLIB_HAS_TYPE_PRINTING=1
)
add_executable(demumble
demumble.cc
third_party/llvm/lib/Demangle/Demangle.cpp
Expand All @@ -47,6 +53,17 @@ add_executable(demumble
third_party/llvm/lib/Demangle/MicrosoftDemangle.cpp
third_party/llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
third_party/llvm/lib/Demangle/RustDemangle.cpp
third_party/swift/lib/Demangling/Context.cpp
third_party/swift/lib/Demangling/CrashReporter.cpp
third_party/swift/lib/Demangling/Demangler.cpp
third_party/swift/lib/Demangling/Errors.cpp
third_party/swift/lib/Demangling/ManglingUtils.cpp
third_party/swift/lib/Demangling/NodeDumper.cpp
third_party/swift/lib/Demangling/NodePrinter.cpp
third_party/swift/lib/Demangling/OldDemangler.cpp
third_party/swift/lib/Demangling/OldRemangler.cpp
third_party/swift/lib/Demangling/Punycode.cpp
third_party/swift/lib/Demangling/Remangler.cpp
)
set_target_properties(demumble PROPERTIES CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Use cmake to build: `cmake -G Ninja . && ninja`
Run tests after building: `python demumble_test.py`

`cxa_demangle.cpp` needs more C++11 than Visual Studio 2013 supports, so
to build on Windows you need to use Visual Studion 2015 or use clang-cl
to build on Windows you need to use Visual Studio 2015 or use clang-cl
as C++ compiler like so:

cmake -G Ninja -DCMAKE_CXX_COMPILER=path/to/llvm-build/bin/clang-cl.exe
5 changes: 3 additions & 2 deletions RELEASING
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
Push new release branch:
1. make sure branches 'main' and 'release' are synced up locally
1. make sure branches 'main' and 'release' are synced up locally, check out main
2. update kDemumbleVersion in demumble.cc with new version (with ".git"), then
git commit -am 'mark this 1.0.0.git'
3. git checkout release; git merge main
4. fix version number in src/version.cc (it will conflict in the above)
5. commit, tag, push (don't forget to push --tags), build binaries
# on the 'release' branch
git commit -am v1.0.0; git push origin release
git tag v1.0.0; git push --tags
./dist.py # on the 'release' branch
./dist.py
# Push the 1.0.0.git change on main too:
git checkout main; git push origin main
6. add demumble-{linux,mac,win}.zip to https://github.com/nico/demumble/releases
40 changes: 35 additions & 5 deletions demumble.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
#include <algorithm>

#include "llvm/Demangle/Demangle.h"
#include "swift/Demangling/Demangle.h"

const char kDemumbleVersion[] = "1.2.3";
const char kDemumbleVersion[] = "1.3.0";

static int print_help(FILE* out) {
fprintf(out,
Expand All @@ -33,6 +34,14 @@ static void print_demangled(const char* format, std::string_view s,
} else if (char* ms = llvm::microsoftDemangle(s, n_used, NULL)) {
printf(format, ms, (int)s.size(), s.data());
free(ms);
} else if (swift::Demangle::isSwiftSymbol(s)) {
swift::Demangle::DemangleOptions options;
options.SynthesizeSugarOnTypes = true;
std::string swift = swift::Demangle::demangleSymbolAsString(s, options);
if (swift == s)
printf("%.*s", (int)s.size(), s.data()); // Not a mangled name
else
printf(format, swift.c_str(), (int)s.size(), s.data());
} else {
printf("%.*s", (int)s.size(), s.data());
}
Expand All @@ -44,11 +53,17 @@ static bool is_mangle_char_itanium(char c) {
}

static bool is_mangle_char_rust(char c) {
// See https://rust-lang.github.io/rfcs/2603-rust-symbol-name-mangling-v0.html.
// https://rust-lang.github.io/rfcs/2603-rust-symbol-name-mangling-v0.html.
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9') || c == '_';
}

static bool is_mangle_char_swift(char c) {
// https://github.com/swiftlang/swift/blob/main/docs/ABI/Mangling.rst
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9') || c == '_' || c == '$';
}

static bool is_mangle_char_win(char c) {
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9') || strchr("?_@$", c);
Expand All @@ -68,6 +83,18 @@ static bool is_plausible_rust_prefix(char* s) {
return s[0] == '_' && s[1] == 'R';
}

static bool is_plausible_swift_prefix(char* s) {
// https://github.com/swiftlang/swift/blob/main/docs/ABI/Mangling.rst
// But also swift/test/Demangle/Inputs/manglings.txt, which has
// _Tt, _TF etc as prefix.

// FIXME: This is missing prefix `@__swiftmacro_`.
return
(s[0] == '$' && s[1] == 's') ||
(s[0] == '_' && s[1] == 'T') ||
(s[0] == '$' && s[1] == 'S');
}

static char buf[8192];
int main(int argc, char* argv[]) {
enum { kPrintAll, kPrintMatching } print_mode = kPrintAll;
Expand Down Expand Up @@ -119,13 +146,13 @@ int main(int argc, char* argv[]) {
char* end = cur + strlen(cur);

while (cur != end) {
size_t special = strcspn(cur, "_?");
size_t offset_to_possible_symbol = strcspn(cur, "_?$");
if (print_mode == kPrintAll)
printf("%.*s", static_cast<int>(special), cur);
printf("%.*s", static_cast<int>(offset_to_possible_symbol), cur);
else if (need_separator)
printf("\n");
need_separator = false;
cur += special;
cur += offset_to_possible_symbol;
if (cur == end)
break;

Expand All @@ -139,6 +166,9 @@ int main(int argc, char* argv[]) {
else if (is_plausible_rust_prefix(cur))
while (cur + n_sym != end && is_mangle_char_rust(cur[n_sym]))
++n_sym;
else if (is_plausible_swift_prefix(cur))
while (cur + n_sym != end && is_mangle_char_swift(cur[n_sym]))
++n_sym;
else {
if (print_mode == kPrintAll)
printf("_");
Expand Down
4 changes: 4 additions & 0 deletions demumble_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
'std::mem::align_of::<f64>\nmylib::foo::bar\n'),
('demumble < _RINvNtC3std3mem8align_ofdE _RNvNvC5mylib3foo3bar',
'std::mem::align_of::<f64>\nmylib::foo::bar\n'),
('demumble _TtP3foo3bar_', 'foo.bar\n'),
('demumble < _TtP3foo3bar_', 'foo.bar\n'),
('demumble $sSS5countSivg', 'Swift.String.count.getter : Swift.Int\n'),
('demumble < $sSS5countSivg', 'Swift.String.count.getter : Swift.Int\n'),
('demumble ?Fxi@@YAHP6AHH@Z@Z', 'int __cdecl Fxi(int (__cdecl *)(int))\n'),
('demumble ??0S@@QEAA@$$QEAU0@@Z', 'public: __cdecl S::S(struct S &&)\n'),
('demumble ??_C@_02PCEFGMJL@hi?$AA@', '"hi"\n'),
Expand Down
84 changes: 84 additions & 0 deletions scripts/copy-swift-demangle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/bash

# Swift's demangler is much less hermetic than LLVM's. This copies all the
# code needed by Swift's demangler into this repository.

set -eu

# Adopt these three to match your local swift checkout and your local
# llvm checkout and build dir:

LLVM_SRC=$HOME/src/llvm-project/llvm
SWIFT_SRC=$HOME/src/swift
LLVM_HEADER_GEN_SRC=$HOME/src/llvm-project/out/gn/gen/llvm/include/llvm

# The rest only needs updating if the set of needed files changes:

cd "$(dirname "$0")"/..

LLVM_INC_SRC=$LLVM_SRC/include/llvm
LLVM_DST=third_party/llvm
LLVM_INC_DST=$LLVM_DST/include/llvm

SWIFT_INC_SRC=$SWIFT_SRC/include/swift
SWIFT_DST=third_party/swift
SWIFT_INC_DST=$SWIFT_DST/include/swift

rm -rf $LLVM_INC_DST/ADT
rm -rf $LLVM_INC_DST/Config
rm -rf $LLVM_INC_DST/Support
rm -rf $LLVM_DST/include/llvm-c
rm -rf $SWIFT_DST

mkdir -p $LLVM_INC_DST/ADT
cp "$LLVM_INC_SRC"/ADT/ADL.h $LLVM_INC_DST/ADT
cp "$LLVM_INC_SRC"/ADT/DenseMapInfo.h $LLVM_INC_DST/ADT
cp "$LLVM_INC_SRC"/ADT/Hashing.h $LLVM_INC_DST/ADT
cp "$LLVM_INC_SRC"/ADT/STLExtras.h $LLVM_INC_DST/ADT
cp "$LLVM_INC_SRC"/ADT/STLForwardCompat.h $LLVM_INC_DST/ADT
cp "$LLVM_INC_SRC"/ADT/STLFunctionalExtras.h $LLVM_INC_DST/ADT
cp "$LLVM_INC_SRC"/ADT/StringRef.h $LLVM_INC_DST/ADT
cp "$LLVM_INC_SRC"/ADT/StringSwitch.h $LLVM_INC_DST/ADT
cp "$LLVM_INC_SRC"/ADT/bit.h $LLVM_INC_DST/ADT
cp "$LLVM_INC_SRC"/ADT/iterator.h $LLVM_INC_DST/ADT
cp "$LLVM_INC_SRC"/ADT/iterator_range.h $LLVM_INC_DST/ADT

mkdir -p $LLVM_INC_DST/Config
cp "$LLVM_HEADER_GEN_SRC"/Config/abi-breaking.h $LLVM_INC_DST/Config
cp "$LLVM_HEADER_GEN_SRC"/Config/llvm-config.h $LLVM_INC_DST/Config

mkdir -p $LLVM_INC_DST/Support
cp "$LLVM_INC_SRC"/Support/Casting.h $LLVM_INC_DST/Support
cp "$LLVM_INC_SRC"/Support/Compiler.h $LLVM_INC_DST/Support
cp "$LLVM_INC_SRC"/Support/DataTypes.h $LLVM_INC_DST/Support
cp "$LLVM_INC_SRC"/Support/ErrorHandling.h $LLVM_INC_DST/Support
cp "$LLVM_INC_SRC"/Support/SwapByteOrder.h $LLVM_INC_DST/Support
cp "$LLVM_INC_SRC"/Support/type_traits.h $LLVM_INC_DST/Support

mkdir -p $LLVM_DST/include/llvm-c
cp "$LLVM_SRC"/include/llvm-c/DataTypes.h $LLVM_DST/include/llvm-c

mkdir -p $SWIFT_DST
cp "$SWIFT_SRC"/LICENSE.txt $SWIFT_DST

mkdir -p $SWIFT_INC_DST
cp -R "$SWIFT_INC_SRC"/Demangling $SWIFT_INC_DST
cp "$SWIFT_INC_SRC"/Strings.h $SWIFT_INC_DST

mkdir -p $SWIFT_INC_DST/ABI
cp "$SWIFT_INC_SRC"/ABI/InvertibleProtocols.def $SWIFT_INC_DST/ABI

mkdir -p $SWIFT_INC_DST/AST
cp "$SWIFT_INC_SRC"/AST/Ownership.h $SWIFT_INC_DST/AST
cp "$SWIFT_INC_SRC"/AST/ReferenceStorage.def $SWIFT_INC_DST/AST

mkdir -p $SWIFT_INC_DST/Basic
cp "$SWIFT_INC_SRC"/Basic/Assertions.h $SWIFT_INC_DST/Basic
cp "$SWIFT_INC_SRC"/Basic/InlineBitfield.h $SWIFT_INC_DST/Basic
cp "$SWIFT_INC_SRC"/Basic/LLVM.h $SWIFT_INC_DST/Basic
cp "$SWIFT_INC_SRC"/Basic/MacroRoles.def $SWIFT_INC_DST/Basic
cp "$SWIFT_INC_SRC"/Basic/STLExtras.h $SWIFT_INC_DST/Basic

mkdir -p $SWIFT_DST/lib
cp -R "$SWIFT_SRC"/lib/Demangling $SWIFT_DST/lib
rm $SWIFT_DST/lib/Demangling/CMakeLists.txt
80 changes: 80 additions & 0 deletions third_party/llvm/include/llvm-c/DataTypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*===-- include/llvm-c/DataTypes.h - Define fixed size types ------*- 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 *|
|* *|
|*===----------------------------------------------------------------------===*|
|* *|
|* This file contains definitions to figure out the size of _HOST_ data types.*|
|* This file is important because different host OS's define different macros,*|
|* which makes portability tough. This file exports the following *|
|* definitions: *|
|* *|
|* [u]int(32|64)_t : typedefs for signed and unsigned 32/64 bit system types*|
|* [U]INT(8|16|32|64)_(MIN|MAX) : Constants for the min and max values. *|
|* *|
|* No library is required when using these functions. *|
|* *|
|*===----------------------------------------------------------------------===*/

/* Please leave this file C-compatible. */

#ifndef LLVM_C_DATATYPES_H
#define LLVM_C_DATATYPES_H

#include <inttypes.h>
#include <stdint.h>

#ifndef _MSC_VER

#if !defined(UINT32_MAX)
# error "The standard header <cstdint> is not C++11 compliant. Must #define "\
"__STDC_LIMIT_MACROS before #including llvm-c/DataTypes.h"
#endif

#if !defined(UINT32_C)
# error "The standard header <cstdint> is not C++11 compliant. Must #define "\
"__STDC_CONSTANT_MACROS before #including llvm-c/DataTypes.h"
#endif

/* Note that <inttypes.h> includes <stdint.h>, if this is a C99 system. */
#include <sys/types.h>

#ifdef _AIX
// GCC is strict about defining large constants: they must have LL modifier.
#undef INT64_MAX
#undef INT64_MIN
#endif

#else /* _MSC_VER */
#ifdef __cplusplus
#include <cstddef>
#include <cstdlib>
#else
#include <stddef.h>
#include <stdlib.h>
#endif
#include <sys/types.h>

#if defined(_WIN64)
typedef signed __int64 ssize_t;
#else
typedef signed int ssize_t;
#endif /* _WIN64 */

#endif /* _MSC_VER */

/* Set defaults for constants which we cannot find. */
#if !defined(INT64_MAX)
# define INT64_MAX 9223372036854775807LL
#endif
#if !defined(INT64_MIN)
# define INT64_MIN ((-INT64_MAX)-1)
#endif
#if !defined(UINT64_MAX)
# define UINT64_MAX 0xffffffffffffffffULL
#endif

#endif /* LLVM_C_DATATYPES_H */
Loading

0 comments on commit e82c452

Please sign in to comment.