Skip to content

Rewrite Of C++ Demanglers#69

Closed
brightprogrammer wants to merge 54 commits intorizinorg:mainfrom
brightprogrammer:gpl_rewrite
Closed

Rewrite Of C++ Demanglers#69
brightprogrammer wants to merge 54 commits intorizinorg:mainfrom
brightprogrammer:gpl_rewrite

Conversation

@brightprogrammer
Copy link
Copy Markdown
Contributor

@brightprogrammer brightprogrammer commented Jan 3, 2025

Remove old GPL code from libiberty and completely rewrite both GNU v2 and GNU v3 demanglers with LGPL license.

Work plan :

Test plan :

  • Already added in Add More GNU v2/v3 Tests #68
  • Write a fuzzer (in less than 100 lines) as implemented in GCC?
  • Build old GCC version (maybe using Qemu) and then compile and get [mangled, original] name pairs for testing.

Attachments :

- Common types like int, signed char, etc... are being demangled in
function params now
- Support for custom types in function param list needs to be added.
- Support for repeated parameter types.
Now 180 tests pass out of all. Two tests seem to be wrong at the moment,
but will take a look later.

TODO
- Sequence of identical types
- Templates
- Function params that have qualifier list in their type
@brightprogrammer
Copy link
Copy Markdown
Contributor Author

We do need to find a way to test the GNU v2 code more like we do for GNU v3. There are very few examples. Also due to lack of a precise grammar, things like special naming conventions are hard for me to cover. Any suggestions?

@brightprogrammer brightprogrammer marked this pull request as ready for review January 17, 2025 10:34
@brightprogrammer
Copy link
Copy Markdown
Contributor Author

There are some function parameter types for which tests don't exist. I haven't added them for now, because I won't have any way to test my implementation.

From the beginning itself, a single test is passing. Now I just have to
keep fixing tests to make the demangler work.
@wargio
Copy link
Copy Markdown
Member

wargio commented Feb 2, 2025

overall this looks very very good. great job!

Inline rewriting of boolean values and unsigned int values.
- (bool)0         ==> false
- (bool)1         ==> true
- (unsigned int)N ==> Nu
Templates parameters don't get registered after level 2. This is a
guess. ABI is not clear with this. It is possible that after this level
it stops detecting builtin types. We'll see...
Lots of green in one go!
Missed to read an 'E' just after expr primary ends
multiple times APPEND_TYPE called because it was outside optional block
Whenever a template is substituted, the type must be forcefully appended
to list of detected types. This means, we override the usual way we
ignore already detected types.
Slow and steady progress
@brightprogrammer brightprogrammer mentioned this pull request Apr 22, 2025
1 task

#define REPLACE_GLOBAL_N_WITH_ANON_NAMESPACE 1

#if 0
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is temporary, it helps in debugging, placing breakpoints conditionally.

// SPDX-License-Identifier: LGPL-3.0-only

/**
* Documentation for used grammar can be found at either of
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Doxygen \file syntax here and everywhere

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants