README.txt 2.5 KB

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