Skip to content

Fix gcc4 mangling complex constchar#77

Merged
ochafik merged 5 commits intonativelibs4java:masterfrom
twitwi:fix-gcc4-mangling-complex-constchar
Sep 29, 2015
Merged

Fix gcc4 mangling complex constchar#77
ochafik merged 5 commits intonativelibs4java:masterfrom
twitwi:fix-gcc4-mangling-complex-constchar

Conversation

@twitwi
Copy link
Copy Markdown
Contributor

@twitwi twitwi commented Aug 19, 2015

Following mails reporting issues on the mailing list (replicated below), I fixed the "const char*" problems that appear as soon as the case is not trivial. I added the provided example as a test.

@ochafik : it has been tested only with "mvn -Dtest=org.bridj.DemanglingTest test", so it might be worth testing on a wider scope before merging.

On Monday, July 27, 2015 at 12:17:50 PM UTC-7, Kurt Granroth wrote:

   I'm using com.nativelibs4java.bridj.0.7.0 on a CentOS 5 system
   running Java 1.8.  gcc version 4.1.2; x64

   Let's say I have a C++ method like so:

   bool create( const char *template, const char *name);

   When linked into a shared library, it gets mangled into this:

   _ZN16cmd_create_event6createEPKcS1_


   This mangled name appears correct in that I can link to it from
   another C++ app with on problem.  Also, running 'nm --demangle' on
   the shared lib correctly demangles that name to the proper one.


   When I try to use this shared library with bridj, though, I get this
   error:


   org.bridj.demangling.Demangler$DemanglingException: Encountered a
   unexpected gcc mangler shortcut '1_' [a, b, s, t, d, i, o, _, 0_]
   (in symbol '_ZN16cmd_create_event6createEPKcS1_')


   That's not the only function that behaves like this -- I see
   hundreds of these errors for that library.


   I was able to work around that particular case by replacing the two
   string parameters with one struct, which had the two strings as
   member variables.  That works, if non-ideally.


   But I can't replace all 'const char*' instances with structs.
     Here's another example:


   const char *error() const;


   That's mangled into:


   _ZNK16cmd_create_event5errorEv


   The bridj parser doesn't like that one, either:


   org.bridj.demangling.Demangler$DemanglingException: Parsing error at
   position 3: Expected a number

            _ZNK16cmd_create_event5errorEv

               ^ (in symbol '_ZNK16cmd_create_event5errorEv')


   I'm not sure what to do in these cases.  Using the 'Symbol'
   annotation workaround doesn't help, since it's not so much a mapping
   problem as the fact that the bridj demangler doesn't think my
   methods are valid.


   Thoughts?

twitwi added 5 commits August 19, 2015 12:59
the test was passing due to a bug in the implementation (that will be fixed in subsequent commits)
…rtcuts

The const case is a special case as we erase the constness in the internal representation.
This way, what is a special type "const char" is a plain one "char" for bridj, but still need to be shorcut.

- tested with "mvn -Dtest=org.bridj.DemanglingTest test"
- complex template test still/now passing
- with the help of the convenient http://demangler.com/
ochafik added a commit that referenced this pull request Sep 29, 2015
Fix gcc4 demangling of non-trivial const char* cases
@ochafik ochafik merged commit 68ba72c into nativelibs4java:master Sep 29, 2015
@ochafik
Copy link
Copy Markdown
Member

ochafik commented Sep 29, 2015

Wow, thanks Rémi and sorry for the atrocious delay!

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.

2 participants