Path: blob/main/system/lib/libcxxabi/src/demangle/README.txt
6175 views
Itanium Name Demangler Library1==============================23Introduction4------------56This directory contains the generic itanium name demangler7library. The main purpose of the library is to demangle C++ symbols,8i.e. convert the string "_Z1fv" into "f()". You can also use the CRTP9base ManglingParser to perform some simple analysis on the mangled10name, or (in LLVM) use the opaque ItaniumPartialDemangler to query the11demangled AST.1213Why are there multiple copies of the this library in the source tree?14---------------------------------------------------------------------1516The canonical sources are in libcxxabi/src/demangle and some of the17files are copied to llvm/include/llvm/Demangle. The simple reason for18this comes from before the monorepo, and both [sub]projects need to19demangle symbols, but neither can depend on each other.2021* libcxxabi needs the demangler to implement __cxa_demangle, which is22part of the itanium ABI spec.2324* LLVM needs a copy for a bunch of places, and cannot rely on the25system's __cxa_demangle because it a) might not be available (i.e.,26on Windows), and b) may not be up-to-date on the latest language27features.2829The copy of the demangler in LLVM has some extra stuff that aren't30needed in libcxxabi (ie, the MSVC demangler, ItaniumPartialDemangler),31which depend on the shared generic components. Despite these32differences, we want to keep the "core" generic demangling library33identical between both copies to simplify development and testing.3435If you're working on the generic library, then do the work first in36libcxxabi, then run libcxxabi/src/demangle/cp-to-llvm.sh. This37script takes as an optional argument the path to llvm, and copies the38changes you made to libcxxabi over. Note that this script just39blindly overwrites all changes to the generic library in llvm, so be40careful.4142Because the core demangler needs to work in libcxxabi, everything43needs to be declared in an anonymous namespace (see44DEMANGLE_NAMESPACE_BEGIN), and you can't introduce any code that45depends on the libcxx dylib.4647FIXME: Now that LLVM is a monorepo, it should be possible to48de-duplicate this code, and have both LLVM and libcxxabi depend on a49shared demangler library.5051Testing52-------5354The tests are split up between libcxxabi/test/{unit,}test_demangle.cpp, and55llvm/unittests/Demangle. The llvm directory should only get tests for stuff not56included in the core library. In the future though, we should probably move all57the tests to LLVM.5859It is also a really good idea to run libFuzzer after non-trivial changes, see60libcxxabi/fuzz/cxa_demangle_fuzzer.cpp and https://llvm.org/docs/LibFuzzer.html.616263