Microsoft Demangler library#92
Conversation
|
Hi,
|
|
General comments on commit e597482 Importing LLVM MSVC Demangler
The purpose here is to get a single commit which adds and integrates the new libdemangler into binutils-gdb source tree. |
|
General comments on commit e09be82 Demangler for MSVC symbols. As I showed earlier (#92 (comment)), this commit needs to be refactored. Parts of it needs to be merged with the initial pull of the libdemangler-mscv. The rest needs to add support to demangle MSVC symbols in bfd's bfd_demangle function. |
16f2a73 to
fb77d8e
Compare
|
|
LIBCONV fix adds libconv to mingw builds (not added by default). Unrelated to libdemangle-msvc. The commit moved to the begining. |
fb77d8e to
cc82be5
Compare
Yes, GDB already requires C++17 (has been the case for 2 years or so). |
43e60c3 to
8618a7b
Compare
|
Does the libiconv change really have anything to do with the demangler? The log of commit: "Add LIBICONV to readelf, dllwrap, elfedit, nm, objdump, addr2line, cxxfilt." doesn't say. Why is that patch in this series? Also, |
8618a7b to
1f0eb46
Compare
It was supposed to be a dependency/prerequisite for building binutils thus it was a separate commit. |
| -I$(srcdir) \ | ||
| -I$(srcdir)/llvm/include \ | ||
| -I$(srcdir)/../include | ||
|
|
There was a problem hiding this comment.
We have only the static version build here; don't we need to have a shared library too? If yes, don't forget to add the library version information too.
There was a problem hiding this comment.
If it gets linked into libbfd then I guess we don't need the static lib.
Otherwise, I am looking into other libs namely libiberty and there also is not shared lib equivalent. I would not consider this library any different.
Yes, please. That follows the model we use for the gnulib/ directory, where the imported code is in the gnulib/import/ subdirectory. Very easy to tell what is imported and what is maintained downstream that way.
I don't recall how it was before, but one thing that I think is important that I had requested before is missing. I would very much like to keep the import of the llvm files separate from anything else, so that we can see your local changes to the llvm files as a separate commit. It will be easier to review/discuss those, an also, it'll be easier in the future when we next need to reimport import changes from llvm, or even wholesale reimport a new version. So I'd much prefer a patch/commit that first imports the llvm files into libdemangle-msvc/llvm, and then a second commit that adds the glue plus your local changes, at least. I don't see how it makes sense to have changes to binutils/'s configury in the "libdemangle-msvc: introduce MSVC symbol demangling library" patch, and then "libdemangle-msvc: use MSVC demangler in binutils" is the patch that actually makes use of libdemangle-msvc in binutils, and, it even changes the --enable-msvc-demangler options added by the first patch to --with-msvc-demangler. That really hints at a bad split. Please move the binutils configure changes from the first patch to the binutils patch. Same for the gdb changes. You have a lot of spurious space/tab / trailing spaces. Add this to your ~/.gitconfig: and then "git show/diff" will show you the bad space/tabs in red. Why do all tools that use bfd need to call bfd_set_msvc_demangler, instead of bfd doing it if libdemangle-msvc support is enabled in bfd? The use of CLANG_FOR_TARGET in the binutils tests is a bit too hacky. We should really switch to configuring the toolchain with --target=x86_64-pc-windows-msvc, and then you'd just use a normal istarget check to skip of not "istarget *-windows-msvc". But, OTOH, why do you need the compiler at all here? libiberty/testsuite/demangle-expected doesn't need one. Can't we do the same? The msvc demangler should be enabled by default at least when targeting windows. This: ... is assuming you're using a libstdc++ toolchain (i.e. GCC or Clang + libstdc++). There are other C++ runtime libraries, e.g., libc++ from llvm. The right way I think is to link with the C++ compiler instead of the C compiler if the msvc demangled is enabled. |
88c8e84 to
de6b4b8
Compare
Done
Please see the PR updated description and the
This mess is cleaned up now.
Done
Demangler back into libiberty, registered externally by bfd_init(). Still, cxxfilt needs to add the call to bfd_init() and readelf needs to register the library with libiberty, as it doesn't use libbfd (an option is to link readelf w/ libiberty if libdemangle-msvc is configured)>
Since the msvc demangler is now back in libiberty and it's registered externally by BFD, the tests are now removed except for cxxfilt testing which need no compilation, and readelf testing that doesn't need any new target/compiler.
A new configure option
Introducing CXXLINK command that follows LINK built by automake |
This is the first in a series of patches adding MSVC symbol demangling support to the GNU toolchain via a new library, libdemangle-msvc. Import the MicrosoftDemangle implementation from LLVM, vendored from: https://github.com/llvm/llvm-project llvm/lib/Demangle @ 04b05998b16721d41d2ad1e453cc4549483bb8e7 llvm/include/llvm/Demangle @ 54c9ddddd1da353b0303df1e86cf444c5363733d Changes: Sources: MicrosoftDemangle.cpp, MicrosoftDemangleNodes.cpp Headers: All. - Removed llvm-config.h includes. - MicrosoftDemangle.cpp changes: - Errors sent to SET_ERROR macro, for error location reporting. - Demangler::parse() has itanium demangler calls commented out.
de6b4b8 to
ddb2bfb
Compare
18b4c68 to
7340327
Compare
|
@czidev-amd @palves All comments should be addressed. |
b6a2c58 to
2239994
Compare
czidev-amd
left a comment
There was a problem hiding this comment.
Looks better, You still need to fix CXX issue for binutils.
| # Every tool that links libbfd needs C++ linking when libdemangle-msvc | ||
| # is in the mix. An empty C++ source in nodist_EXTRA_*_SOURCES tells | ||
| # automake to pick the C++ linker. | ||
| nodist_EXTRA_size_SOURCES = dummy.cxx |
There was a problem hiding this comment.
This requires every binutils build a C++ compiler. this can be very problematic request as it may change build systems across different distro providers. I would at least add a guarding if ENABLE_MSVC_DEMANGLER statement.
You need to check if everything works like before without CXX compiler: (CXX=false ./configure ...) at least for binutils.
There was a problem hiding this comment.
Actually the way automake works I can't make inclusion of cxx files conditional. Switched to the new link command for binutils:
if ENABLE_MSVC_DEMANGLER
BINUTILS_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CXX) $(AM_CXXFLAGS) $(CXXFLAGS) \
$(AM_LDFLAGS) $(LDFLAGS) -o $@
else
BINUTILS_LINK = $(LINK)
endif
objdump_LINK = $(BINUTILS_LINK)
nm_new_LINK = $(BINUTILS_LINK)
...
| (Ignored for MSVC demangling)\n"); | ||
| #endif | ||
| fprintf (stream, "\ | ||
| ]-r|--no-recurse-limit] Disable a limit on recursion whilst demangling\n"); |
There was a problem hiding this comment.
Typo, bracket opening ] instead of [
This is the second in a series of patches adding MSVC symbol demangling
support to the GNU toolchain.
Add the libdemangle-msvc wrapper library around the imported LLVM MSVC
demangler.
The library provides msvc_demangle(), which accepts an MSVC-mangled
name and returns the demangled string, integrated behind the
HAVE_MSVC_DEMANGLER preprocessor guard.
A new configure option --with-msvc-demangler controls whether the
MSVC demangling library is built. It accepts yes, no, or auto.
The library is skipped when the flag is set to no, otherwise is built.
The MSVC demangler does not provide an equivalent of libiberty's
cplus_demangle_v3_components, which returns a structured AST from
a mangled name. Implementing one would require converting the LLVM
demangler's AST into libiberty's demangle_component tree. Instead,
implementation is provided for only two functions that operate on
libiberty's AST: cp_class_name_from_physname & method_name_from_physname.
Build system changes:
- Top-level Makefile.def: add libdemangle-msvc as a host module with
dependencies from all-gdb and all-binutils.
- Top-level configure.ac: --with-msvc-demangler controls whether
libdemangle-msvc is built (default: off).
- include/demangle.h: declare msvc_demangle(),
msvc_class_name_from_physname(), msvc_method_name_from_physname().
This is the third in a series of patches adding MSVC symbol demangling support to the GNU toolchain. Add an 'msvc' entry to libiberty_demanglers[] so that -s msvc / --format=msvc is accepted by c++filt and 'set demangle-style msvc' by gdb. Add cplus_demangle_set_msvc_handler() to allow consumers to register an MSVC demangling callback at runtime. In cplus_demangle(), dispatch to the registered handler when (MSVC_DEMANGLING || AUTO_DEMANGLING) and the symbol starts with '?'.
This is the fourth in a series of patches adding MSVC symbol demangling support to the GNU toolchain. Register the MSVC demangler handler with cplus_demangle_set_msvc_handler() from bfd_init(), enabling cplus_demangle() to dispatch MSVC-mangled symbols to libdemangle-msvc when available. The handler is only registered when libdemangle-msvc is linked in (HAVE_MSVC_DEMANGLER). Strip MSVC compiler-emitted '$<tag>$' prefixes in bfd_demangle().
This is the fifth in a series of patches adding MSVC symbol
demangling support to the GNU toolchain.
GDB links and uses libdemangle-msvc if enabled: at least one
Windows target is selected or --with-msvc-demangler is specified.
bfd_init() registers the MSVC handler with libiberty, so
gdb_demangle() now handles MSVC mangled symbols as well.
libdemangle-msvc does not expose a demangle_component AST. In
its place, the library provides direct equivalents for the gdb
functions that would otherwise consume that AST: when mangled name
is recognised as MSVC-mangled, cp_class_name_from_physname()
dispatches to msvc_class_name_from_physname(), and
method_name_from_physname() dispatches to
msvc_method_name_from_physname().
Tests:
* gdb.cp/demangle.exp: probe for MSVC support; skip MSVC
cases when absent.
* unittests/cp-support-selftests.c: cover both helpers on
Itanium and MSVC mangled names.
This is the sixth in a series of patches adding MSVC symbol demangling support to the GNU toolchain. Link binutils against libdemangle-msvc when enabled: at least one Windows target is selected or --with-msvc-demangler is specified. Since libdemangle-msvc is a C++ library, the affected programs are linked with the C++ compiler using automake's nodist_EXTRA_*_SOURCES trick. cxxfilt: strip MSVC compiler-emitted '$<tag>$' prefixes before passing symbols to cplus_demangle(). readelf: register the liberty's MSVC handler explicitly so MSVC symbols can be demangled. Add testsuite coverage in cxxfilt.exp with a probe that skips MSVC tests in builds without MSVC support. Exercise -s msvc / --format=msvc style selection and --msvc-full. Add testsuite coverage in readelf.exp.
This is the last in a series of patches adding MSVC symbol demangling support to the GNU toolchain. * README-ROCM.md: Document the --with-msvc-demangler configure option and the resulting behaviour of c++filt, readelf and gdb. * CHANGELOG_AMD.md: Add release-note entry under the upcoming ROCgdb section.
2239994 to
51d0add
Compare
This series adds optional MSVC (Microsoft Visual C++) mangled name demangling to the GNU toolchain, using an in-tree library (
libdemangle-msvc) that wraps LLVM's MicrosoftDemangle.The library provides
msvc_demangle(), which accepts an MSVC-mangled name and returns the demangled string. The function is accessed from withinlibibertyjust like any other demangling function (access based on style flag, the demangler added to the existing list of demanglers etc.). It's registered externally (using the newly introducedcplus_demangle_set_msvc_handler() )to avoid licensing issues. Thelibibertyalso sets a new demangling stylemsvcthat tools can use - e.g.cxxfilt,readelf,set demangle-stylecommand in GDB etc.The library does not provide an equivalent of libiberty's
cplus_demangle_v3_components, which returns a structured AST from a mangled name. Implementing one would require converting the LLVM demangler's AST into libiberty'sdemangle_componenttree. Instead, implementation is provided for only two functions that operate on libiberty's AST: GDB'scp_class_name_from_physname&method_name_from_physname. Provided aremsvc_class_name_from_physname&msvc_method_name_from_physnameand are called DIRECTLY from the aforementioned functions (note that `method_name_from_physname actually has no users in GDB).The BFD library registers the MSVC demangler from within
bfd_init()function, iflibdemangle-msvcis configured. This means all the binutils that uselibbfdmust also linklibdemangle-msvc, if the library is configured (see below).cxxfiltnow callsbfd_init()in order to register the MSVC demangler.readelfnow registers the demangler explicitly usingcplus_demangle_set_msvc_handler().Configuration:
--with-msvc-demanglercontrols whether thelibdemangle-msvclibrary is built. The library is skipped when the flag is set to no, otherwise is built.--with-msvc-demanglerflag is set.Testsuite:
Exercise -s msvc / --format=msvc style selection.
* GDB unittests/cp-support-selftests.c: cover
cp_class_name_from_physname&method_name_from_physname.Docs:
Commits:
libdemangle-msvcand enables it's build using the top level configure script.libdemangle-msvcto libiberty, bfd, gdb and binutils respectively.TODO:
GDB currently calls
msvc_class_name_from_physname&msvc_method_name_from_physname. directly if the the symbol appears to be MSVC mangled. A better approach would be to introduce a generic GDB API that calls intolibiberty: Thelibibertyshould offer "class-name-from-physname" and "method-from-physname" interfaces that different demanglers can implement. Iflibibertyhas no "native" (fast-path) implementation registered for the type of the symbol received, it returns NULL and the GDB continues with the existing AST-walk and extraction. This effectively moves demangling and style selection tolibiberty. This would also need another set of registration functions, along withcplus_demangle_set_msvc_handler().