GCJ adding extra underscore to enum value symbol name?
Andrew Haley
aph@gcc.gnu.org
Sun Apr 1 10:57:00 GMT 2007
Fred Pendleton writes:
> I'm running into a problem compiling a Java enum using GCJ 4.3.0 20070323, with the
> ecj front end. It appears as though GCJ is inserting an extra underscore character
> into the symbol name of certain Java enum values when compiling to an object file.
>
> Take this example Java enum:
> ////////////////////////////
> public enum TestEnum
> {
> TEST,
> PREREQUISITE,
> TEST_PREREQUISITE,
> TEST_TEST_PREREQUISITE,
> TEST_TEST_TEST_TEST
> }
> ////////////////////////////
>
> And this C++ code that uses the enum value TestEnum.TEST_TEST_PREREQUISITE:
> ////////////////////////////
> #include "TestEnum.h"
>
> TestEnum* e = TestEnum::TEST_TEST_PREREQUISITE;
> ////////////////////////////
>
> After compiling the Java enum to an object file, these are the symbol names that nm
> emits:
> _ZN8TestEnum4TESTE
> _ZN8TestEnum12PREREQUISITEE
> _ZN8TestEnum17TEST_PREREQUISITEE
> _ZN8TestEnum23TEST_TEST_PREREQU_ISITEE
> _ZN8TestEnum19TEST_TEST_TEST_TESTE
>
> Notice that the second last symbol name has an extra underscore between the U and the
> I, and that this underscore does not exist in the Java enum value's name. This
> appears to be causing problems when linking via CNI to C++ code that does not expect
> that underscore to be present. According to nm run on the object file for the above
> C++ code, the _ZN8TestEnum22TEST_TEST_PREREQUISITEE symbol is expected.
>
> Can anyone shed some light onto why this is happening? Is it a bug in GCJ?
You've hit a bug in append_unicode_mangled_name(). The fix might be
as simple as this:
Index: mangle_name.c
===================================================================
--- mangle_name.c (revision 123084)
+++ mangle_name.c (working copy)
@@ -84,7 +84,10 @@
int ch = UTF8_GET(ptr, limit);
if ((ISALNUM (ch) && ch != 'U') || ch == '$')
- obstack_1grow (mangle_obstack, ch);
+ {
+ obstack_1grow (mangle_obstack, ch);
+ uuU = 0;
+ }
/* Everything else needs encoding */
else
{
Let us know if this works.
Andrew.
More information about the Java
mailing list