This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Make java compiled resources public.


Andrew Haley wrote:
> Jakub Jelinek writes:
>  > On Thu, Dec 20, 2007 at 12:42:04AM -0800, David Daney wrote:
>  > > This patch makes java compiled resources public symbols.  This is needed
>  > > so that when statically linking to libgcj, the resource files in
>  > > libgcj.a can be linked by passing -u to the linker.  In 4.2 we could
>  > > statically link java.util.Currency, but in 4.3 this class now depends on
>  > > an compiled core:/ resource file.  Without this patch it is impossible
>  > > (or at least very awkward) to force the resource file to be linked.
>  > 
>  > If so, at least make the symbols hidden, so that they aren't exported from
>  > ELF shared libraries where visibility is supported.
>
> Makes sense; this is only for static linking.
>   
Right, here is a new version of the patch.  Differences from the
original patch:

* The resource symbols are now have hidden visibility.  I have verified
that they do not appear the libgcj.so's dynamic symbol table.

* Minor comment fixes.

I am working on a corresponding demangler patch.

How about this version:
2007-12-21  David Daney  <ddaney@avtrex.com>

    * resource.c (Jr_count): Remove.
    (compile_resource_data): Call java_mangle_resource_name to generate
    decl name.  Make resource decl public and hidden.
    * mangle.c (append_resource_name_hunk): New function.
    (java_mangle_resource_name): Same.
    * java-tree.h (java_mangle_resource_name): Declare new function.


Index: gcc/java/resource.c
===================================================================
--- gcc/java/resource.c	(revision 131121)
+++ gcc/java/resource.c	(working copy)
@@ -51,14 +51,10 @@ The Free Software Foundation is independ
 /* A list of all the resources files.  */
 static GTY(()) tree resources = NULL;
 
-/* Count of all the resources compiled in this invocation.  */
-static int Jr_count = 0;
-
 void
 compile_resource_data (const char *name, const char *buffer, int length)
 {
   tree rtype, field = NULL_TREE, data_type, rinit, data, decl;
-  char buf[60];
 
   data_type = build_prim_array_type (unsigned_byte_type_node,
 				     strlen (name) + length);
@@ -79,11 +75,10 @@ compile_resource_data (const char *name,
   TREE_CONSTANT (rinit) = 1;
   TREE_INVARIANT (rinit) = 1;
 
-  /* Generate a unique-enough identifier.  */
-  sprintf (buf, "_Jr%d", ++Jr_count);
-
-  decl = build_decl (VAR_DECL, get_identifier (buf), rtype);
+  decl = build_decl (VAR_DECL, java_mangle_resource_name (name), rtype);
   TREE_STATIC (decl) = 1;
+  TREE_PUBLIC (decl) = 1;
+  DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
   DECL_ARTIFICIAL (decl) = 1;
   DECL_IGNORED_P (decl) = 1;
   TREE_READONLY (decl) = 1;
Index: gcc/java/mangle.c
===================================================================
--- gcc/java/mangle.c	(revision 131121)
+++ gcc/java/mangle.c	(working copy)
@@ -796,6 +796,86 @@ compression_table_add (tree type)
   TREE_VEC_ELT (compression_table, compression_next++) = type;
 }
 
+/* Prepend '_' so leading digits are encoded properly.  Also replace
+   '.' with "$_" and '$' with "$$".  The result is encoded with
+   append_gpp_mangled_name.  */
+
+static void
+append_resource_name_hunk(const unsigned char *hunk, int len)
+{
+  /* We need twice the length if all characters are escaped.  */
+  unsigned char *n = (unsigned char *)alloca (2 * len + 1);
+  unsigned char *d;
+  const unsigned char *w1;
+  const unsigned char *w2;
+  const unsigned char *limit;
+
+  d = n;
+
+  *d++ = '_';
+  memcpy (n + 1, hunk, len);
+
+  w1 = hunk;
+  limit = hunk + len;
+  while (w1 < limit)
+    {
+      int ch;
+      w2 = w1;
+      ch = UTF8_GET(w1, limit);
+      gcc_assert (ch > 0);
+      if (ch == '.')
+	{
+	  *d++ = '$';
+	  *d++ = '_';
+	}
+      else if (ch == '$')
+	{
+	  *d++ = '$';
+	  *d++ = '$';
+	}
+      else
+	{
+	  memcpy (d, w2, w1 - w2);
+	  d += w1 - w2;
+	}
+    }
+  append_gpp_mangled_name ((char *)n, d - n);
+}
+
+/* Mangle an embedded resource file name.  Each path component is
+   encoded with append_resource_name_hunk.  */
+
+tree
+java_mangle_resource_name (const char *name)
+{
+  const unsigned char *ptr;
+  const unsigned char *start_of_hunk;
+  const unsigned char *end_of_hunk;
+  const unsigned char *limit = (const unsigned char *)name + strlen(name);
+
+  init_mangling ();
+  MANGLE_RAW_STRING ("Gr");
+
+  ptr = (const unsigned char *)name;
+
+  while (ptr < limit)
+    {
+      start_of_hunk = ptr;
+      end_of_hunk = ptr;
+      while (ptr < limit)
+	{
+	  int ch;
+	  ch = UTF8_GET(ptr, limit);
+	  if (ch == '/')
+	    break;
+	  end_of_hunk = ptr;
+	}
+      append_resource_name_hunk (start_of_hunk, end_of_hunk - start_of_hunk);
+    }
+
+  return finish_mangling ();
+}
+
 /* Mangling initialization routine.  */
 
 static void
Index: gcc/java/java-tree.h
===================================================================
--- gcc/java/java-tree.h	(revision 131121)
+++ gcc/java/java-tree.h	(working copy)
@@ -1205,6 +1205,7 @@ extern void java_check_methods (tree);
 extern void java_mangle_decl (tree);
 extern tree java_mangle_class_field (struct obstack *, tree);
 extern tree java_mangle_vtable (struct obstack *, tree);
+extern tree java_mangle_resource_name (const char *);
 extern void append_gpp_mangled_name (const char *, int);
 
 extern void add_predefined_file (tree);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]