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