= { };
#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
#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) ();
}
= { 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 */
#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));
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;
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