class.c (emit_register_classes): Use assemble_jcr if possible.

2001-08-08  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_NAME): Define if we have named section
	and weak symbol support.
	* crtstuff.c (__JCR_LIST__): Define.
	(__JCR_END__): Define.
	(_Jv_RegiserClasses): Define weak symbol if possible.
	(__do_global_ctors_aux): Register classes for ELF targets with
	weak symbol support.

From-SVN: r44731
This commit is contained in:
Anthony Green 2001-08-08 23:33:51 +00:00 committed by Anthony Green
parent e8406c89d1
commit 6351543d13
4 changed files with 104 additions and 36 deletions

View File

@ -1,3 +1,15 @@
2001-08-08 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_NAME): Define if we have named section
and weak symbol support.
* crtstuff.c (__JCR_LIST__): Define.
(__JCR_END__): Define.
(_Jv_RegiserClasses): Define weak symbol if possible.
(__do_global_ctors_aux): Register classes for ELF targets with
weak symbol support.
2001-08-08 Kazu Hirata <kazu@hxi.com> 2001-08-08 Kazu Hirata <kazu@hxi.com>
* dbxout.c: Fix comment formatting. * dbxout.c: Fix comment formatting.

View File

@ -415,6 +415,14 @@ char __EH_FRAME_BEGIN__[]
= { }; = { };
#endif /* EH_FRAME_SECTION_NAME */ #endif /* EH_FRAME_SECTION_NAME */
#ifdef JCR_SECTION_NAME
/* Stick a label at the beginning of the java class registration info
so we can register them properly. */
STATIC void *__JCR_LIST__[] __attribute__ ((unused, section(JCR_SECTION_NAME)))
= { 0 };
#endif /* JCR_SECTION_NAME */
#endif /* defined(CRT_BEGIN) */ #endif /* defined(CRT_BEGIN) */
#ifdef CRT_END #ifdef CRT_END
@ -423,11 +431,25 @@ char __EH_FRAME_BEGIN__[]
#ifdef OBJECT_FORMAT_ELF #ifdef OBJECT_FORMAT_ELF
#ifdef JCR_SECTION_NAME
extern void _Jv_RegisterClasses (void *) __attribute__((weak));
static void *__JCR_END__[];
#endif
static func_ptr __CTOR_END__[]; static func_ptr __CTOR_END__[];
static void static void
__do_global_ctors_aux (void) __do_global_ctors_aux (void)
{ {
func_ptr *p; func_ptr *p;
#ifdef JCR_SECTION_NAME
void **jcr;
if (_Jv_RegisterClasses)
{
for (jcr = __JCR_END__ - 1; *jcr != NULL; jcr--);
if (*(jcr + 1))
_Jv_RegisterClasses (jcr + 1);
}
#endif
for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--) for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--)
(*p) (); (*p) ();
} }
@ -543,6 +565,14 @@ STATIC int __FRAME_END__[]
= { 0 }; = { 0 };
#endif /* EH_FRAME_SECTION */ #endif /* EH_FRAME_SECTION */
#ifdef JCR_SECTION_NAME
/* Stick a label at the beginning of the java class registration info
so we can register them properly. */
STATIC void *__JCR_END__[1]
__attribute__ ((unused, section(JCR_SECTION_NAME))) = { 0 };
#endif /* JCR_SECTION_NAME */
#endif /* defined(CRT_END) */ #endif /* defined(CRT_END) */
#else /* OBJECT_FORMAT_MACHO */ #else /* OBJECT_FORMAT_MACHO */

View File

@ -217,6 +217,15 @@ do { ASM_OUTPUT_LABEL(FILE,LABEL_ALTERNATE_NAME (INSN)); } while (0)
#endif #endif
#endif #endif
/* If we have named section and we support weak symbols, then use the
.jcr section for recording java classes which need to be registered
at program start-up time. */
#if defined (TARGET_ASM_NAMED_SECTION) && SUPPORTS_WEAK
#ifndef JCR_SECTION_NAME
#define JCR_SECTION_NAME ".jcr"
#endif
#endif
/* If we have no definition for UNIQUE_SECTION, but do have the /* If we have no definition for UNIQUE_SECTION, but do have the
ability to generate arbitrary sections, construct something ability to generate arbitrary sections, construct something
reasonable. */ reasonable. */

View File

@ -37,6 +37,7 @@ The Free Software Foundation is independent of Sun Microsystems, Inc. */
#include "output.h" #include "output.h"
#include "parse.h" #include "parse.h"
#include "ggc.h" #include "ggc.h"
#include "target.h"
static tree make_method_value PARAMS ((tree)); static tree make_method_value PARAMS ((tree));
static tree build_java_method_type PARAMS ((tree, tree, int)); static tree build_java_method_type PARAMS ((tree, tree, int));
@ -848,7 +849,6 @@ build_utf8_ref (name)
sprintf(buf, "_Utf%d", ++utf8_count); sprintf(buf, "_Utf%d", ++utf8_count);
decl = build_decl (VAR_DECL, get_identifier (buf), utf8const_type); decl = build_decl (VAR_DECL, get_identifier (buf), utf8const_type);
/* FIXME get some way to force this into .text, not .data. */
TREE_STATIC (decl) = 1; TREE_STATIC (decl) = 1;
DECL_ARTIFICIAL (decl) = 1; DECL_ARTIFICIAL (decl) = 1;
DECL_IGNORED_P (decl) = 1; DECL_IGNORED_P (decl) = 1;
@ -1865,45 +1865,62 @@ register_class ()
end = current; end = current;
} }
/* Generate a function that gets called at start-up (static contructor) time, /* Emit something to register classes at start-up time.
which calls registerClass for all the compiled classes. */
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 void
emit_register_classes () emit_register_classes ()
{ {
extern tree get_file_function_name PARAMS ((int)); if (SUPPORTS_WEAK && targetm.have_named_sections)
tree init_name = get_file_function_name ('I'); {
tree init_type = build_function_type (void_type_node, end_params_node); tree t;
tree init_decl; named_section_flags (JCR_SECTION_NAME, SECTION_WRITE,
tree t; POINTER_SIZE / BITS_PER_UNIT);
for (t = registered_class; t; t = TREE_CHAIN (t))
init_decl = build_decl (FUNCTION_DECL, init_name, init_type); assemble_integer (XEXP (DECL_RTL (t), 0),
SET_DECL_ASSEMBLER_NAME (init_decl, init_name); POINTER_SIZE / BITS_PER_UNIT, 1);
TREE_STATIC (init_decl) = 1; }
current_function_decl = init_decl; else
DECL_RESULT (init_decl) = build_decl(RESULT_DECL, NULL_TREE, void_type_node); {
/* DECL_EXTERNAL (init_decl) = 1;*/ extern tree get_file_function_name PARAMS ((int));
TREE_PUBLIC (init_decl) = 1; tree init_name = get_file_function_name ('I');
pushlevel (0); tree init_type = build_function_type (void_type_node, end_params_node);
make_decl_rtl (init_decl, NULL); tree init_decl;
init_function_start (init_decl, input_filename, 0); tree t;
expand_function_start (init_decl, 0);
init_decl = build_decl (FUNCTION_DECL, init_name, init_type);
for ( t = registered_class; t; t = TREE_CHAIN (t)) SET_DECL_ASSEMBLER_NAME (init_decl, init_name);
emit_library_call (registerClass_libfunc, 0, VOIDmode, 1, TREE_STATIC (init_decl) = 1;
XEXP (DECL_RTL (t), 0), Pmode); current_function_decl = init_decl;
DECL_RESULT (init_decl) = build_decl(RESULT_DECL, NULL_TREE, void_type_node);
expand_function_end (input_filename, 0, 0); /* DECL_EXTERNAL (init_decl) = 1;*/
poplevel (1, 0, 1); TREE_PUBLIC (init_decl) = 1;
{ pushlevel (0);
/* Force generation, even with -O3 or deeper. Gross hack. FIXME */ make_decl_rtl (init_decl, NULL);
int saved_flag = flag_inline_functions; init_function_start (init_decl, input_filename, 0);
flag_inline_functions = 0; expand_function_start (init_decl, 0);
rest_of_compilation (init_decl);
flag_inline_functions = saved_flag; for ( t = registered_class; t; t = TREE_CHAIN (t))
} emit_library_call (registerClass_libfunc, 0, VOIDmode, 1,
current_function_decl = NULL_TREE; XEXP (DECL_RTL (t), 0), Pmode);
assemble_constructor (XEXP (DECL_RTL (init_decl), 0), DEFAULT_INIT_PRIORITY);
expand_function_end (input_filename, 0, 0);
poplevel (1, 0, 1);
{
/* Force generation, even with -O3 or deeper. Gross hack. FIXME */
int saved_flag = flag_inline_functions;
flag_inline_functions = 0;
rest_of_compilation (init_decl);
flag_inline_functions = saved_flag;
}
current_function_decl = NULL_TREE;
assemble_constructor (XEXP (DECL_RTL (init_decl), 0), DEFAULT_INIT_PRIORITY);
}
} }
void void