Patch: java class registration via .jcr section
green@peach.cygnus.co.uk
green@peach.cygnus.co.uk
Fri Aug 3 20:06:00 GMT 2001
Here's a revised version of the patch first proposed here:
http://gcc.gnu.org/ml/gcc-patches/2001-07/msg02102.html
I've cleaned up a couple of things and I think I implemented rth's
suggestions. One major change is that we default to the old mechanism
for targets with no weak symbol support.
Tested on powerpc-unknown-linux-gnu. Ok?
Thanks!
2001-08-02 Anthony Green <green@redhat.com>
* java/class.c (emit_register_classes): Use assemble_jcr if
possible. Keep the original mechanism as a fallback.
* defaults.h (JCR_SECTION): Define if we have JCR_SECTION_ASM_OP and
the target supports weak symbols.
* varasm.c (in_section): Add in_jcr.
(assemble_jcr): New function.
* crtstuff.c (__JCR_LIST__): Define.
(__JCR_END__): Define.
(_Jv_RegiserClass): Define weak symbol if possible.
(__do_global_ctors_aux): Register classes for ELF targets with
weak symbol support.
* config/elfos.h (ASM_OUTPUT_JCR): Define.
(JCR_SECTION_ASM_OP): Define.
Index: gcc/crtstuff.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/crtstuff.c,v
retrieving revision 1.41
diff -c -u -p -r1.41 crtstuff.c
--- crtstuff.c 2001/08/04 01:31:31 1.41
+++ crtstuff.c 2001/08/04 02:47:35
@@ -415,6 +415,14 @@ char __EH_FRAME_BEGIN__[]
= { };
#endif /* EH_FRAME_SECTION_NAME */
+#ifdef JCR_SECTION_ASM_OP
+/* Stick a label at the beginning of the java class registration info
+ so we can register them properly. */
+
+asm (JCR_SECTION_ASM_OP); /* cc1 doesn't know that we are switching! */
+STATIC void *__JCR_LIST__[1] __attribute__ ((__unused__)) = { 0 };
+#endif /* JCR_SECTION_ASM_OP */
+
#endif /* defined(CRT_BEGIN) */
#ifdef CRT_END
@@ -423,11 +431,21 @@ char __EH_FRAME_BEGIN__[]
#ifdef OBJECT_FORMAT_ELF
+#ifdef SUPPORTS_WEAK
+extern void _Jv_RegisterClass (void *) __attribute__((weak));
+#endif
+
+static void *__JCR_END__[];
static func_ptr __CTOR_END__[];
static void
__do_global_ctors_aux (void)
{
func_ptr *p;
+#ifdef SUPPORTS_WEAK
+ void **jcr;
+ for (jcr = __JCR_END__ - 1; *jcr != NULL; jcr--)
+ _Jv_RegisterClass (*jcr);
+#endif
for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--)
(*p) ();
}
@@ -542,6 +560,14 @@ STATIC int __FRAME_END__[]
__attribute__ ((unused, mode(SI), section(EH_FRAME_SECTION_NAME)))
= { 0 };
#endif /* EH_FRAME_SECTION */
+
+#ifdef JCR_SECTION_ASM_OP
+/* Stick a label at the beginning of the java class registration info
+ so we can register them properly. */
+
+asm (JCR_SECTION_ASM_OP); /* cc1 doesn't know that we are switching! */
+STATIC void *__JCR_END__[1] __attribute__ ((__unused__)) = { 0 };
+#endif /* JCR_SECTION_ASM_OP */
#endif /* defined(CRT_END) */
Index: gcc/defaults.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/defaults.h,v
retrieving revision 1.49
diff -c -u -p -r1.49 defaults.h
--- defaults.h 2001/08/04 01:31:31 1.49
+++ defaults.h 2001/08/04 02:47:35
@@ -215,6 +215,16 @@ do { ASM_OUTPUT_LABEL(FILE,LABEL_ALTERNA
#ifndef EH_FRAME_SECTION_NAME
#define EH_FRAME_SECTION_NAME ".eh_frame"
#endif
+
+/* If we have no definition for JCR_SECTION, but we do know how to
+ emit assembly for switching tothe .jcr section, call jcr_section to
+ use it. Only define it if we have a JCR_SECTION_ASM_OP, which is
+ used in crtstuff.c, and if the target supports weak symbols. */
+#if !defined (JCR_SECTION)
+# if defined (JCR_SECTION_ASM_OP) && defined (SUPPORTS_WEAK)
+# define JCR_SECTION() \
+ do { named_section (NULL_TREE, ".jcr", 0); } while (0)
+# endif
#endif
/* If we have no definition for UNIQUE_SECTION, but do have the
Index: gcc/varasm.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/varasm.c,v
retrieving revision 1.188
diff -c -u -p -r1.188 varasm.c
--- varasm.c 2001/08/04 01:31:32 1.188
+++ varasm.c 2001/08/04 02:47:37
@@ -188,6 +188,9 @@ static enum in_section { no_section, in_
#ifdef BSS_SECTION_ASM_OP
, in_bss
#endif
+#ifdef JCR_SECTION_ASM_OP
+ , in_jcr
+#endif
#ifdef EXTRA_SECTIONS
, EXTRA_SECTIONS
#endif
@@ -855,6 +858,19 @@ assemble_constructor (name)
assemble_name (asm_out_file, name);
fputc ('\n', asm_out_file);
}
+#endif
+}
+
+/* Likewise for java classes to register. */
+
+void
+assemble_jcr (name)
+ const char *name;
+{
+#ifdef ASM_OUTPUT_JCR
+ ASM_OUTPUT_JCR (asm_out_file, name);
+#else
+ abort ();
#endif
}
Index: gcc/config/elfos.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/elfos.h,v
retrieving revision 1.32
diff -c -u -p -r1.32 elfos.h
--- elfos.h 2001/08/04 01:31:32 1.32
+++ elfos.h 2001/08/04 02:47:37
@@ -378,6 +378,21 @@ dtors_section () \
while (0)
/* A C statement (sans semicolon) to output an
+ element in the table of java classes to register. */
+#define ASM_OUTPUT_JCR(FILE, NAME) \
+ do \
+ { \
+ JCR_SECTION(); \
+ fprintf (FILE, "%s", INT_ASM_OP); \
+ assemble_name (FILE, NAME); \
+ fprintf (FILE, "\n"); \
+ } \
+ while (0)
+
+/* The string to switch to the .jcr section for ELF objects. */
+#define JCR_SECTION_ASM_OP "\t.section\t.jcr,\"a\",@progbits"
+
+/* A C statement (sans semicolon) to output an
element in the table of global constructors. */
#define ASM_OUTPUT_CONSTRUCTOR(FILE, NAME) \
do \
Index: gcc/java/class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/class.c,v
retrieving revision 1.101
diff -c -u -p -r1.101 class.c
--- class.c 2001/07/31 22:20:05 1.101
+++ class.c 2001/08/04 02:47:38
@@ -1865,12 +1864,22 @@ register_class ()
end = current;
}
-/* Generate a function that gets called at start-up (static contructor) time,
- which calls registerClass for all the compiled classes. */
+/* Emit something to register classes at start-up time.
+ The preferred mechanism is through the .jcr section, which contain
+ a list of pointers to classes which get registered during
+ constructor invoction time. The fallback mechanism is to generate
+ a `constructor' function which calls _Jv_RegisterClass for each
+ class in this file. */
+
void
emit_register_classes ()
{
+#ifdef JCR_SECTION
+ tree t;
+ for ( t = registered_class; t; t = TREE_CHAIN (t))
+ assemble_jcr (XEXP (XEXP (DECL_RTL (t), 0), 0));
+#else
extern tree get_file_function_name PARAMS ((int));
tree init_name = get_file_function_name ('I');
tree init_type = build_function_type (void_type_node, end_params_node);
@@ -1904,6 +1913,7 @@ emit_register_classes ()
}
current_function_decl = NULL_TREE;
assemble_constructor (IDENTIFIER_POINTER (init_name));
+#endif
}
void
More information about the Gcc-patches
mailing list