public inbox for java-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch 1/2] Add demangling for java resource files to libiberty
@ 2008-01-15  1:02 David Daney
  2008-01-15  1:23 ` [Patch 2/2] Make java compiled resources public David Daney
  2008-01-18 19:46 ` [Patch 1/2] Add demangling for java resource files to libiberty Ian Lance Taylor
  0 siblings, 2 replies; 10+ messages in thread
From: David Daney @ 2008-01-15  1:02 UTC (permalink / raw)
  To: gcc-patches, binutils, Java Patch List

[-- Attachment #1: Type: text/plain, Size: 2187 bytes --]

This is the first of a two part patch to make embedded java resources
public symbols in libgcj.a.

The patch is motivated by the fact that there are no references to the
resource files.  So when doing static linking there is no easy way to
make the linker include them in the compiled object.

The patches give the resource files public visibility with a mangled
name, this allows them to be forced into the output object.  The names
are given hidden visibility so that they do not pollute the namespace of
libgcj.so.

The mangling is as follows:

The resource name is broken into path components by '/' characters. Each component then has an '_' prepended and all '.' -> "$_" and '$' -> "$$".  The length of each component is then prepended to this and all are concatenated together and preceeded by "_ZGr".  "Gr" being an unused special-name designator that could be thought of as representing GNU-resource.  For example:

"java/util/iso4217.properties" mangles as:
"_ZGr5_java5_util20_iso4217$_properties"

This first part is to libiberty's demangler so that the mangling can be reversed.

OK to commit?

Tested on x86_64-pc-linux-gnu with no regressions.  Also tested with mipsel-linux-nm -C on a patched libgcj.a where it produces the expected results.

include/
2008-01-14  David Daney  <ddaney@avtrex.com>

	* demangle.h (demangle_component_type):  Add
	DEMANGLE_COMPONENT_JAVA_RESOURCE,
	DEMANGLE_COMPONENT_COMPOUND_NAME, and
	DEMANGLE_COMPONENT_CHARACTER as new enum values.
	(demangle_component): Add struct s_character to union u.

libiberty/
2008-01-14  David Daney  <ddaney@avtrex.com>

	* cp-demangle.c (d_dump): Handle DEMANGLE_COMPONENT_JAVA_RESOURCE,
	DEMANGLE_COMPONENT_COMPOUND_NAME, and
	DEMANGLE_COMPONENT_CHARACTER cases.
	(d_make_comp): Handle DEMANGLE_COMPONENT_COMPOUND_NAME and
	DEMANGLE_COMPONENT_JAVA_RESOURCE cases.
	(d_make_character): New function.
	(d_java_resource_part): Same.
	(d_java_resource): Same.
	(d_special_name): Handle "Gr" case.
	(d_print_comp): Handle DEMANGLE_COMPONENT_JAVA_RESOURCE,
	DEMANGLE_COMPONENT_COMPOUND_NAME, and
	DEMANGLE_COMPONENT_CHARACTER cases.
	(testsuite/demangle-expected): Add test for java resource name
	mangling.





[-- Attachment #2: demangle.patch --]
[-- Type: text/x-patch, Size: 6932 bytes --]

Index: include/demangle.h
===================================================================
RCS file: /cvs/src/src/include/demangle.h,v
retrieving revision 1.25
diff -u -p -r1.25 demangle.h
--- include/demangle.h	31 Aug 2007 20:20:44 -0000	1.25
+++ include/demangle.h	15 Jan 2008 00:21:18 -0000
@@ -362,7 +362,15 @@ enum demangle_component_type
      using 'n' instead of '-', we want a way to indicate a negative
      number which involves neither modifying the mangled string nor
      allocating a new copy of the literal in memory.  */
-  DEMANGLE_COMPONENT_LITERAL_NEG
+  DEMANGLE_COMPONENT_LITERAL_NEG,
+  /* A libgcj compiled resource.  The left subtree is the name of the
+     resource.  */
+  DEMANGLE_COMPONENT_JAVA_RESOURCE,
+  /* A name formed by the concatenation of two parts.  The left
+     subtree is the first part and the right subtree the second.  */
+  DEMANGLE_COMPONENT_COMPOUND_NAME,
+  /* A name formed by a single character.  */
+  DEMANGLE_COMPONENT_CHARACTER
 };
 
 /* Types which are only used internally.  */
@@ -448,6 +456,12 @@ struct demangle_component
       long number;
     } s_number;
 
+    /* For DEMANGLE_COMPONENT_CHARACTER.  */
+    struct
+    {
+      int character;
+    } s_character;
+
     /* For other types.  */
     struct
     {
Index: libiberty/cp-demangle.c
===================================================================
RCS file: /cvs/src/src/libiberty/cp-demangle.c,v
retrieving revision 1.69
diff -u -p -r1.69 cp-demangle.c
--- libiberty/cp-demangle.c	31 Aug 2007 20:20:49 -0000	1.69
+++ libiberty/cp-demangle.c	15 Jan 2008 00:21:31 -0000
@@ -650,6 +650,15 @@ d_dump (struct demangle_component *dc, i
     case DEMANGLE_COMPONENT_LITERAL_NEG:
       printf ("negative literal\n");
       break;
+    case DEMANGLE_COMPONENT_JAVA_RESOURCE:
+      printf ("java resource\n");
+      break;
+    case DEMANGLE_COMPONENT_COMPOUND_NAME:
+      printf ("compound name\n");
+      break;
+    case DEMANGLE_COMPONENT_CHARACTER:
+      printf ("character '%c'\n",  dc->u.s_character.character);
+      return;
     }
 
   d_dump (d_left (dc), indent + 2);
@@ -769,6 +778,7 @@ d_make_comp (struct d_info *di, enum dem
     case DEMANGLE_COMPONENT_TRINARY_ARG2:
     case DEMANGLE_COMPONENT_LITERAL:
     case DEMANGLE_COMPONENT_LITERAL_NEG:
+    case DEMANGLE_COMPONENT_COMPOUND_NAME:
       if (left == NULL || right == NULL)
 	return NULL;
       break;
@@ -795,6 +805,7 @@ d_make_comp (struct d_info *di, enum dem
     case DEMANGLE_COMPONENT_ARGLIST:
     case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
     case DEMANGLE_COMPONENT_CAST:
+    case DEMANGLE_COMPONENT_JAVA_RESOURCE:
       if (left == NULL)
 	return NULL;
       break;
@@ -1501,6 +1512,131 @@ d_operator_name (struct d_info *di)
     }
 }
 
+static struct demangle_component *
+d_make_character (struct d_info *di, int c)
+{
+  struct demangle_component *p;
+  p = d_make_empty (di);
+  if (p != NULL)
+    {
+      p->type = DEMANGLE_COMPONENT_CHARACTER;
+      p->u.s_character.character = c;
+    }
+  return p;
+}
+
+static struct demangle_component *
+d_java_resource_part (struct d_info *di)
+{
+  struct demangle_component *p = NULL;
+  struct demangle_component *next = NULL;
+  long len, i;
+  char c;
+  const char *str;
+
+  len = d_number (di);
+  if (len <= 1)
+    return NULL;
+
+  /* Eat the leading '_'.  */
+  if (d_next_char (di) != '_')
+    return NULL;
+  len--;
+
+  str = d_str (di);
+  i = 0;
+
+  while (len > 0)
+    {
+      c = str[i];
+      if (!c)
+	return NULL;
+
+      /* Each chunk is either a '$' escape...  */
+      if (c == '$')
+	{
+	  i++;
+	  switch (str[i++])
+	    {
+	    case '_':
+	      c = '.';
+	      break;
+	    case '$':
+	      c = '$';
+	      break;
+	    default:
+	      return NULL;
+	    }
+	  next = d_make_character (di, c);
+	  d_advance (di, i);
+	  str = d_str (di);
+	  len -= i;
+	  i = 0;
+	  if (next == NULL)
+	    return NULL;
+	}
+      /* ... or a sequence of characters.  */
+      else
+	{
+	  while (i < len && str[i] && str[i] != '$')
+	    i++;
+
+	  next = d_make_name (di, str, i);
+	  d_advance (di, i);
+	  str = d_str (di);
+	  len -= i;
+	  i = 0;
+	  if (next == NULL)
+	    return NULL;
+	}
+
+      if (p == NULL)
+	p = next;
+      else
+	{
+	  p = d_make_comp (di, DEMANGLE_COMPONENT_COMPOUND_NAME, p, next);
+	  if (p == NULL)
+	    return NULL;
+	}
+    }
+
+  return p;
+}
+
+static struct demangle_component *
+d_java_resource (struct d_info *di)
+{
+  struct demangle_component *p = NULL;
+  struct demangle_component *next = NULL;
+  struct demangle_component *t;
+
+  while (d_peek_char(di))
+    {
+      next = d_java_resource_part (di);
+      if (next == NULL)
+	return NULL;
+
+      if (p == NULL)
+	p = next;
+      else
+	{
+	  t = d_make_character (di, '/');
+	  if (t == NULL)
+	    return NULL;
+	  p = d_make_comp (di, DEMANGLE_COMPONENT_COMPOUND_NAME, p, t);
+	  if (p == NULL)
+	    return NULL;
+	  p = d_make_comp (di, DEMANGLE_COMPONENT_COMPOUND_NAME, p, next);
+	  if (p == NULL)
+	    return NULL;
+	}
+    }
+
+  p = d_make_comp (di, DEMANGLE_COMPONENT_JAVA_RESOURCE, p, NULL);
+
+  return p;
+}
+
 /* <special-name> ::= TV <type>
                   ::= TT <type>
                   ::= TI <type>
@@ -1514,6 +1650,7 @@ d_operator_name (struct d_info *di)
                   ::= TJ <type>
                   ::= GR <name>
 		  ::= GA <encoding>
+		  ::= Gr <resource name>
 */
 
 static struct demangle_component *
@@ -1605,6 +1742,9 @@ d_special_name (struct d_info *di)
 	  return d_make_comp (di, DEMANGLE_COMPONENT_HIDDEN_ALIAS,
 			      d_encoding (di, 0), NULL);
 
+	case 'r':
+	  return d_java_resource (di);
+
 	default:
 	  return NULL;
 	}
@@ -3552,6 +3692,20 @@ d_print_comp (struct d_print_info *dpi,
       }
       return;
 
+    case DEMANGLE_COMPONENT_JAVA_RESOURCE:
+      d_append_string (dpi, "java resource ");
+      d_print_comp (dpi, d_left (dc));
+      return;
+
+    case DEMANGLE_COMPONENT_COMPOUND_NAME:
+      d_print_comp (dpi, d_left (dc));
+      d_print_comp (dpi, d_right (dc));
+      return;
+
+    case DEMANGLE_COMPONENT_CHARACTER:
+      d_append_char (dpi, dc->u.s_character.character);
+      return;
+
     default:
       d_print_error (dpi);
       return;
Index: libiberty/testsuite/demangle-expected
===================================================================
RCS file: /cvs/src/src/libiberty/testsuite/demangle-expected,v
retrieving revision 1.37
diff -u -p -r1.37 demangle-expected
--- libiberty/testsuite/demangle-expected	6 May 2007 00:25:11 -0000	1.37
+++ libiberty/testsuite/demangle-expected	15 Jan 2008 00:21:33 -0000
@@ -3858,3 +3858,7 @@ foo()::var1
 --format=gnu-v3
 _ZZN7myspaceL3foo_1EvEN11localstruct1fEZNS_3fooEvE16otherlocalstruct
 myspace::foo()::localstruct::f(myspace::foo()::otherlocalstruct)
+# Java resource name
+--format=gnu-v3
+_ZGr5_java5_util20_iso4217$_properties
+java resource java/util/iso4217.properties

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2008-01-27  6:29 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-15  1:02 [Patch 1/2] Add demangling for java resource files to libiberty David Daney
2008-01-15  1:23 ` [Patch 2/2] Make java compiled resources public David Daney
2008-01-19 18:41   ` Tom Tromey
2008-01-22 22:00     ` David Daney
2008-01-23 11:40       ` Andrew Haley
2008-01-23 23:05         ` David Daney
2008-01-18 19:46 ` [Patch 1/2] Add demangling for java resource files to libiberty Ian Lance Taylor
2008-01-25 22:10   ` David Daney
2008-01-27  5:41     ` Ian Lance Taylor
2008-01-27  6:29       ` David Daney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).