Skip to content

Commit

Permalink
Add an c++ itanium demangler to llvm.
Browse files Browse the repository at this point in the history
This adds a copy of the demangler in libcxxabi.

The code also has no dependencies on anything else in LLVM. To enforce
that I added it as another library. That way a BUILD_SHARED_LIBS will
fail if anyone adds an use of StringRef for example.

The no llvm dependency combined with the fact that this has to build
on linux, OS X and Windows required a few changes to the code. In
particular:

    No constexpr.
    No alignas

On OS X at least this library has only one global symbol:
__ZN4llvm16itanium_demangleEPKcPcPmPi

My current plan is:

    Commit something like this
    Change lld to use it
    Change lldb to use it as the fallback

    Add a few #ifdefs so that exactly the same file can be used in
    libcxxabi to export abi::__cxa_demangle.

Once the fast demangler in lldb can handle any names this
implementation can be replaced with it and we will have the one true
demangler.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280732 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
espindola committed Sep 6, 2016
1 parent 99f377b commit ec44cfd
Show file tree
Hide file tree
Showing 20 changed files with 4,539 additions and 39 deletions.
7 changes: 0 additions & 7 deletions cmake/config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,6 @@ check_include_file(mach/mach.h HAVE_MACH_MACH_H)
check_include_file(mach-o/dyld.h HAVE_MACH_O_DYLD_H)
check_include_file(histedit.h HAVE_HISTEDIT_H)

# size_t must be defined before including cxxabi.h on FreeBSD 10.0.
check_cxx_source_compiles("
#include <stddef.h>
#include <cxxabi.h>
int main() { return 0; }
" HAVE_CXXABI_H)

# library checks
if( NOT PURE_WINDOWS )
check_library_exists(pthread pthread_create "" HAVE_LIBPTHREAD)
Expand Down
3 changes: 0 additions & 3 deletions include/llvm/Config/config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
/* Define to 1 if you have the `closedir' function. */
#cmakedefine HAVE_CLOSEDIR ${HAVE_CLOSEDIR}

/* Define to 1 if you have the <cxxabi.h> header file. */
#cmakedefine HAVE_CXXABI_H ${HAVE_CXXABI_H}

/* Define to 1 if you have the <CrashReporterClient.h> header file. */
#undef HAVE_CRASHREPORTERCLIENT_H

Expand Down
28 changes: 28 additions & 0 deletions include/llvm/Demangle/Demangle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//===--- Demangle.h ---------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include <cstddef>

namespace llvm {
/// This is a llvm local version of __cxa_demangle. Other than the name and
/// being in the llvm namespace it is identical.
///
/// The mangled_name is demangled into buf and returned. If the buffer is not
/// large enough, realloc is used to expand it.
///
/// The *status will be set to
/// unknown_error: -4
/// invalid_args: -3
/// invalid_mangled_name: -2
/// memory_alloc_failure: -1
/// success: 0

char *itaniumDemangle(const char *mangled_name, char *buf, size_t *n,
int *status);
}
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# `Support' and `TableGen' libraries are added on the top-level CMakeLists.txt

add_subdirectory(Demangle)
add_subdirectory(IR)
add_subdirectory(IRReader)
add_subdirectory(CodeGen)
Expand Down
3 changes: 3 additions & 0 deletions lib/Demangle/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_llvm_library(LLVMDemangle
ItaniumDemangle.cpp
)
Loading

0 comments on commit ec44cfd

Please sign in to comment.