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>
* dbxout.c: Fix comment formatting.

View File

@ -415,6 +415,14 @@ char __EH_FRAME_BEGIN__[]
= { };
#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) */
#ifdef CRT_END
@ -423,11 +431,25 @@ char __EH_FRAME_BEGIN__[]
#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 void
__do_global_ctors_aux (void)
{
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--)
(*p) ();
}
@ -543,6 +565,14 @@ STATIC int __FRAME_END__[]
= { 0 };
#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) */
#else /* OBJECT_FORMAT_MACHO */

View File

@ -217,6 +217,15 @@ do { ASM_OUTPUT_LABEL(FILE,LABEL_ALTERNATE_NAME (INSN)); } while (0)
#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
ability to generate arbitrary sections, construct something
reasonable. */

View File

@ -37,6 +37,7 @@ The Free Software Foundation is independent of Sun Microsystems, Inc. */
#include "output.h"
#include "parse.h"
#include "ggc.h"
#include "target.h"
static tree make_method_value PARAMS ((tree));
static tree build_java_method_type PARAMS ((tree, tree, int));
@ -848,7 +849,6 @@ build_utf8_ref (name)
sprintf(buf, "_Utf%d", ++utf8_count);
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;
DECL_ARTIFICIAL (decl) = 1;
DECL_IGNORED_P (decl) = 1;
@ -1865,45 +1865,62 @@ 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 ()
{
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);
tree init_decl;
tree t;
init_decl = build_decl (FUNCTION_DECL, init_name, init_type);
SET_DECL_ASSEMBLER_NAME (init_decl, init_name);
TREE_STATIC (init_decl) = 1;
current_function_decl = init_decl;
DECL_RESULT (init_decl) = build_decl(RESULT_DECL, NULL_TREE, void_type_node);
/* DECL_EXTERNAL (init_decl) = 1;*/
TREE_PUBLIC (init_decl) = 1;
pushlevel (0);
make_decl_rtl (init_decl, NULL);
init_function_start (init_decl, input_filename, 0);
expand_function_start (init_decl, 0);
for ( t = registered_class; t; t = TREE_CHAIN (t))
emit_library_call (registerClass_libfunc, 0, VOIDmode, 1,
XEXP (DECL_RTL (t), 0), Pmode);
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);
if (SUPPORTS_WEAK && targetm.have_named_sections)
{
tree t;
named_section_flags (JCR_SECTION_NAME, SECTION_WRITE,
POINTER_SIZE / BITS_PER_UNIT);
for (t = registered_class; t; t = TREE_CHAIN (t))
assemble_integer (XEXP (DECL_RTL (t), 0),
POINTER_SIZE / BITS_PER_UNIT, 1);
}
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);
tree init_decl;
tree t;
init_decl = build_decl (FUNCTION_DECL, init_name, init_type);
SET_DECL_ASSEMBLER_NAME (init_decl, init_name);
TREE_STATIC (init_decl) = 1;
current_function_decl = init_decl;
DECL_RESULT (init_decl) = build_decl(RESULT_DECL, NULL_TREE, void_type_node);
/* DECL_EXTERNAL (init_decl) = 1;*/
TREE_PUBLIC (init_decl) = 1;
pushlevel (0);
make_decl_rtl (init_decl, NULL);
init_function_start (init_decl, input_filename, 0);
expand_function_start (init_decl, 0);
for ( t = registered_class; t; t = TREE_CHAIN (t))
emit_library_call (registerClass_libfunc, 0, VOIDmode, 1,
XEXP (DECL_RTL (t), 0), Pmode);
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