README.txt 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. Itanium Name Demangler Library
  2. ==============================
  3. Introduction
  4. ------------
  5. This directory contains the generic itanium name demangler
  6. library. The main purpose of the library is to demangle C++ symbols,
  7. i.e. convert the string "_Z1fv" into "f()". You can also use the CRTP
  8. base ManglingParser to perform some simple analysis on the mangled
  9. name, or (in LLVM) use the opaque ItaniumPartialDemangler to query the
  10. demangled AST.
  11. Why are there multiple copies of the this library in the source tree?
  12. ---------------------------------------------------------------------
  13. The canonical sources are in libcxxabi/src/demangle and some of the
  14. files are copied to llvm/include/llvm/Demangle. The simple reason for
  15. this comes from before the monorepo, and both [sub]projects need to
  16. demangle symbols, but neither can depend on each other.
  17. * libcxxabi needs the demangler to implement __cxa_demangle, which is
  18. part of the itanium ABI spec.
  19. * LLVM needs a copy for a bunch of places, and cannot rely on the
  20. system's __cxa_demangle because it a) might not be available (i.e.,
  21. on Windows), and b) may not be up-to-date on the latest language
  22. features.
  23. The copy of the demangler in LLVM has some extra stuff that aren't
  24. needed in libcxxabi (ie, the MSVC demangler, ItaniumPartialDemangler),
  25. which depend on the shared generic components. Despite these
  26. differences, we want to keep the "core" generic demangling library
  27. identical between both copies to simplify development and testing.
  28. If you're working on the generic library, then do the work first in
  29. libcxxabi, then run the cp-to-llvm.sh script in src/demangle. This
  30. script takes as an optional argument the path to llvm, and copies the
  31. changes you made to libcxxabi over. Note that this script just
  32. blindly overwrites all changes to the generic library in llvm, so be
  33. careful.
  34. Because the core demangler needs to work in libcxxabi, everything
  35. needs to be declared in an anonymous namespace (see
  36. DEMANGLE_NAMESPACE_BEGIN), and you can't introduce any code that
  37. depends on the libcxx dylib.
  38. FIXME: Now that LLVM is a monorepo, it should be possible to
  39. de-duplicate this code, and have both LLVM and libcxxabi depend on a
  40. shared demangler library.
  41. Testing
  42. -------
  43. The tests are split up between libcxxabi/test/{unit,}test_demangle.cpp, and
  44. llvm/unittest/Demangle. The llvm directory should only get tests for stuff not
  45. included in the core library. In the future though, we should probably move all
  46. the tests to LLVM.
  47. It is also a really good idea to run libFuzzer after non-trivial changes, see
  48. libcxxabi/fuzz/cxa_demangle_fuzzer.cpp and https://llvm.org/docs/LibFuzzer.html.