From 82fa9c7851beeb448fc6977f92297fb123c9f1de Mon Sep 17 00:00:00 2001 From: Maximilian Downey Twiss <creatorsmithmdt@gmail.com> Date: Thu, 24 Nov 2022 18:44:19 +1100 Subject: [PATCH 10/56] Re-add JCR_SECTION_NAME, TARGET_USE_JCR_SECTION, __LIBGCC_JCR_SECTION_NAME__, _Jv_RegisterClasses, __JCR_LIST__, __JCR_END__.
gcc/c-family/ChangeLog: * c-cppbuiltin.cc (c_cpp_builtins): Define __LIBGCC_JCR_SECTION_NAME__. gcc/ChangeLog: * config/darwin.h (JCR_SECTION_NAME): Define. * config/i386/cygming.h (TARGET_USE_JCR_SECTION): Likewise. * config/i386/mingw32.h (TARGET_USE_JCR_SECTION): Undefine. * config/pa/pa64-hpux.h (JCR_SECTION_NAME): Re-add. * config/rs6000/aix71.h (TARGET_USE_JCR_SECTION): Define. * defaults.h (JCR_SECTION_NAME): Define. (TARGET_USE_JCR_SECTION): Define. * doc/tm.texi.in (TARGET_USE_JCR_SECTION): Document. * doc/tm.texi: Regenerate. * system.h (fancy_abort): Do not poison TARGET_USE_JCR_SECTION nor JCR_SECTION_NAME. libgcc/ChangeLog: * config/i386/cygming-crtbegin.c (_Jv_RegisterClasses): Re-add. (__JCR_LIST__): Likewise. (__gcc_register_frame): Attempt to _Jv_RegisterClasses. * config/i386/cygming-crtend.c (__JCR_END__): Re-add. * config/ia64/crtbegin.S (__JCR_LIST__): Likewise. * config/ia64/crtend.S (__JCR_END__): Likewise. * config/pa/pa64-hpux-lib.h (defined): * crtstuff.c: Re-add __LIBGCC_JCR_SECTION_NAME__ to preprocessor conditionals. (__JCR_LIST__, __JCR_END__): Re-add. (frame_dummy): Attempt to _Jv_RegisterClasses. (__do_global_ctors_1): Likewise. --- gcc/c-family/c-cppbuiltin.cc | 4 ++ gcc/config/darwin.h | 3 ++ gcc/config/i386/cygming.h | 5 +++ gcc/config/i386/mingw32.h | 3 ++ gcc/config/pa/pa64-hpux.h | 2 + gcc/config/rs6000/aix71.h | 2 + gcc/defaults.h | 21 ++++++++++ gcc/doc/tm.texi | 6 +++ gcc/doc/tm.texi.in | 6 +++ gcc/system.h | 3 +- libgcc/config/i386/cygming-crtbegin.c | 12 ++++++ libgcc/config/i386/cygming-crtend.c | 8 ++++ libgcc/config/ia64/crtbegin.S | 4 ++ libgcc/config/ia64/crtend.S | 5 +++ libgcc/config/pa/pa64-hpux-lib.h | 4 +- libgcc/crtstuff.c | 57 ++++++++++++++++++++++++--- 16 files changed, 136 insertions(+), 9 deletions(-) diff --git a/gcc/c-family/c-cppbuiltin.cc b/gcc/c-family/c-cppbuiltin.cc index 333f3e138d6..bdc834afbb8 100644 --- a/gcc/c-family/c-cppbuiltin.cc +++ b/gcc/c-family/c-cppbuiltin.cc @@ -1480,6 +1480,10 @@ c_cpp_builtins (cpp_reader *pfile) builtin_define_with_value ("__LIBGCC_EH_FRAME_SECTION_NAME__", EH_FRAME_SECTION_NAME, 1); #endif +#ifdef JCR_SECTION_NAME + builtin_define_with_value ("__LIBGCC_JCR_SECTION_NAME__", + JCR_SECTION_NAME, 1); +#endif #ifdef CTORS_SECTION_ASM_OP builtin_define_with_value ("__LIBGCC_CTORS_SECTION_ASM_OP__", CTORS_SECTION_ASM_OP, 1); diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h index d1b4f277c2e..3cea1f7a36e 100644 --- a/gcc/config/darwin.h +++ b/gcc/config/darwin.h @@ -1067,6 +1067,9 @@ enum machopic_addr_class { #define EH_FRAME_SECTION_NAME "__TEXT" #define EH_FRAME_SECTION_ATTR ",coalesced,no_toc+strip_static_syms+live_support" +/* Java runtime class list. */ +#define JCR_SECTION_NAME "__DATA,jcr,regular,no_dead_strip" + #undef ASM_PREFERRED_EH_DATA_FORMAT #define ASM_PREFERRED_EH_DATA_FORMAT(CODE,GLOBAL) \ (((CODE) == 2 && (GLOBAL) == 1) \ diff --git a/gcc/config/i386/cygming.h b/gcc/config/i386/cygming.h index 867ac5bf181..921279b9837 100644 --- a/gcc/config/i386/cygming.h +++ b/gcc/config/i386/cygming.h @@ -444,6 +444,11 @@ do { \ #endif /* HAVE_GAS_WEAK */ +/* FIXME: SUPPORTS_WEAK && TARGET_HAVE_NAMED_SECTIONS is true, + but for .jcr section to work we also need crtbegin and crtend + objects. */ +#define TARGET_USE_JCR_SECTION 1 + /* Decide whether it is safe to use a local alias for a virtual function when constructing thunks. */ #undef TARGET_USE_LOCAL_THUNK_ALIAS_P diff --git a/gcc/config/i386/mingw32.h b/gcc/config/i386/mingw32.h index c1ab489c377..d3a1dd3292e 100644 --- a/gcc/config/i386/mingw32.h +++ b/gcc/config/i386/mingw32.h @@ -281,6 +281,9 @@ do { \ #undef TARGET_N_FORMAT_TYPES #define TARGET_N_FORMAT_TYPES 3 +/* Let defaults.h definition of TARGET_USE_JCR_SECTION apply. */ +#undef TARGET_USE_JCR_SECTION + #define HAVE_ENABLE_EXECUTE_STACK #undef CHECK_EXECUTE_STACK_ENABLED #define CHECK_EXECUTE_STACK_ENABLED flag_setstackexecutable diff --git a/gcc/config/pa/pa64-hpux.h b/gcc/config/pa/pa64-hpux.h index a35f428bb44..8cb9bef520f 100644 --- a/gcc/config/pa/pa64-hpux.h +++ b/gcc/config/pa/pa64-hpux.h @@ -164,6 +164,8 @@ along with GCC; see the file COPYING3. If not see #define DATA_SECTION_ASM_OP "\t.data" #define BSS_SECTION_ASM_OP "\t.section\t.bss" +#define JCR_SECTION_NAME ".jcr" + #define HP_INIT_ARRAY_SECTION_ASM_OP "\t.section\t.init" #define GNU_INIT_ARRAY_SECTION_ASM_OP "\t.section\t.init_array" #define HP_FINI_ARRAY_SECTION_ASM_OP "\t.section\t.fini" diff --git a/gcc/config/rs6000/aix71.h b/gcc/config/rs6000/aix71.h index 323d7c884d1..0f1db9b07fc 100644 --- a/gcc/config/rs6000/aix71.h +++ b/gcc/config/rs6000/aix71.h @@ -277,6 +277,8 @@ extern long long int atoll(const char *); /* This target defines SUPPORTS_WEAK and TARGET_ASM_NAMED_SECTION, but does not have crtbegin/end. */ +#define TARGET_USE_JCR_SECTION 0 + #define TARGET_AIX_VERSION 71 /* AIX 7.1 supports DWARF3+ debugging. */ diff --git a/gcc/defaults.h b/gcc/defaults.h index 376687d91b1..f2a61fabfbc 100644 --- a/gcc/defaults.h +++ b/gcc/defaults.h @@ -402,6 +402,27 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define MASK_RETURN_ADDR NULL_RTX #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 + +/* This decision to use a .jcr section can be overridden by defining + USE_JCR_SECTION to 0 in target file. This is necessary if target + can define JCR_SECTION_NAME but does not have crtstuff or + linker support for .jcr section. */ +#ifndef TARGET_USE_JCR_SECTION +#ifdef JCR_SECTION_NAME +#define TARGET_USE_JCR_SECTION 1 +#else +#define TARGET_USE_JCR_SECTION 0 +#endif +#endif + /* Number of hardware registers that go into the DWARF-2 unwind info. If not defined, equals FIRST_PSEUDO_REGISTER */ diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index c370c34b584..f8350ec0a23 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -12159,6 +12159,12 @@ default to false and also handles @code{error_mark_node}. The default implementation always returns true. @end deftypefn +@defmac TARGET_USE_JCR_SECTION +This macro determines whether to use the JCR section to register Java +classes. By default, TARGET_USE_JCR_SECTION is defined to 1 if both +SUPPORTS_WEAK and TARGET_HAVE_NAMED_SECTIONS are true, else 0. +@end defmac + @defmac OBJC_JBLEN This macro determines the size of the objective C jump buffer for the NeXT runtime. By default, OBJC_JBLEN is defined to an innocuous value. diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in index 1ec14c27b40..35d527ecb83 100644 --- a/gcc/doc/tm.texi.in +++ b/gcc/doc/tm.texi.in @@ -7889,6 +7889,12 @@ and scanf formatter settings. @hook TARGET_VERIFY_TYPE_CONTEXT +@defmac TARGET_USE_JCR_SECTION +This macro determines whether to use the JCR section to register Java +classes. By default, TARGET_USE_JCR_SECTION is defined to 1 if both +SUPPORTS_WEAK and TARGET_HAVE_NAMED_SECTIONS are true, else 0. +@end defmac + @defmac OBJC_JBLEN This macro determines the size of the objective C jump buffer for the NeXT runtime. By default, OBJC_JBLEN is defined to an innocuous value. diff --git a/gcc/system.h b/gcc/system.h index 4f9256efbcf..767d3881615 100644 --- a/gcc/system.h +++ b/gcc/system.h @@ -1077,8 +1077,7 @@ extern void fancy_abort (const char *, int, const char *) ROUND_TOWARDS_ZERO SF_SIZE DF_SIZE XF_SIZE TF_SIZE LIBGCC2_TF_CEXT \ LIBGCC2_LONG_DOUBLE_TYPE_SIZE STRUCT_VALUE \ EH_FRAME_IN_DATA_SECTION TARGET_FLT_EVAL_METHOD_NON_DEFAULT \ - JCR_SECTION_NAME TARGET_USE_JCR_SECTION SDB_DEBUGGING_INFO \ - SDB_DEBUG NO_IMPLICIT_EXTERN_C NOTICE_UPDATE_CC \ + SDB_DEBUGGING_INFO SDB_DEBUG NO_IMPLICIT_EXTERN_C NOTICE_UPDATE_CC \ CC_STATUS_MDEP_INIT CC_STATUS_MDEP CC_STATUS SLOW_SHORT_ACCESS /* Hooks that are no longer used. */ diff --git a/libgcc/config/i386/cygming-crtbegin.c b/libgcc/config/i386/cygming-crtbegin.c index 43096c7813f..c9b101abf5f 100644 --- a/libgcc/config/i386/cygming-crtbegin.c +++ b/libgcc/config/i386/cygming-crtbegin.c @@ -73,6 +73,18 @@ __deregister_frame_info (__attribute__((unused)) const void *p) #endif #endif /* DWARF2_UNWIND_INFO */ +#if TARGET_USE_JCR_SECTION +extern void _Jv_RegisterClasses (__attribute__((unused)) const void *) + TARGET_ATTRIBUTE_WEAK; + +#ifdef __x86_64__ +TARGET_ATTRIBUTE_WEAK void +_Jv_RegisterClasses (__attribute__((unused)) const void *p) +{ +} +#endif +#endif /* TARGET_USE_JCR_SECTION */ + #if defined(HAVE_LD_RO_RW_SECTION_MIXING) # define EH_FRAME_SECTION_CONST const #else diff --git a/libgcc/config/i386/cygming-crtend.c b/libgcc/config/i386/cygming-crtend.c index 095df3244aa..3fd428f115d 100644 --- a/libgcc/config/i386/cygming-crtend.c +++ b/libgcc/config/i386/cygming-crtend.c @@ -53,6 +53,14 @@ static EH_FRAME_SECTION_CONST int __FRAME_END__[] = { 0 }; #endif +#if TARGET_USE_JCR_SECTION +/* Null terminate the .jcr section array. */ +static void *__JCR_END__[1] + __attribute__ ((used, section(__LIBGCC_JCR_SECTION_NAME__), + aligned(sizeof(void *)))) + = { 0 }; +#endif + extern void __gcc_register_frame (void); extern void __gcc_deregister_frame (void); diff --git a/libgcc/config/ia64/crtbegin.S b/libgcc/config/ia64/crtbegin.S index c3b7afbe5fc..ba673c16725 100644 --- a/libgcc/config/ia64/crtbegin.S +++ b/libgcc/config/ia64/crtbegin.S @@ -34,6 +34,10 @@ __CTOR_LIST__: __DTOR_LIST__: data8 -1 +.section .jcr,"aw","progbits" + .align 8 +__JCR_LIST__: + .section .sdata .type dtor_ptr,@object .size dtor_ptr,8 diff --git a/libgcc/config/ia64/crtend.S b/libgcc/config/ia64/crtend.S index 4491bbebb80..5229f1b6c29 100644 --- a/libgcc/config/ia64/crtend.S +++ b/libgcc/config/ia64/crtend.S @@ -34,6 +34,11 @@ __CTOR_END__: __DTOR_END__: data8 0 +.section .jcr,"aw","progbits" + .align 8 +__JCR_END__: + data8 0 + #if HAVE_INITFINI_ARRAY_SUPPORT .global __do_global_ctors_aux .hidden __do_global_ctors_aux diff --git a/libgcc/config/pa/pa64-hpux-lib.h b/libgcc/config/pa/pa64-hpux-lib.h index 2530e9e2134..6737c961791 100644 --- a/libgcc/config/pa/pa64-hpux-lib.h +++ b/libgcc/config/pa/pa64-hpux-lib.h @@ -52,8 +52,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see initializers specified here. */ /* We need to add frame_dummy to the initializer list if EH_FRAME_SECTION_NAME - is defined. */ -#if defined(__LIBGCC_EH_FRAME_SECTION_NAME__) + or JCR_SECTION_NAME is defined. */ +#if defined(__LIBGCC_EH_FRAME_SECTION_NAME__) || defined(JCR_SECTION_NAME) #define PA_INIT_FRAME_DUMMY_ASM_OP ".dword P%frame_dummy" #else #define PA_INIT_FRAME_DUMMY_ASM_OP "" diff --git a/libgcc/crtstuff.c b/libgcc/crtstuff.c index b0d0062ad5b..2e9491ac9ed 100644 --- a/libgcc/crtstuff.c +++ b/libgcc/crtstuff.c @@ -190,6 +190,9 @@ extern void *__deregister_frame_info_bases (const void *) TARGET_ATTRIBUTE_WEAK; extern void __do_global_ctors_1 (void); +/* Likewise for _Jv_RegisterClasses. */ +extern void _Jv_RegisterClasses (void *) TARGET_ATTRIBUTE_WEAK; + /* Likewise for transactional memory clone tables. */ extern void _ITM_registerTMCloneTable (void *, size_t) TARGET_ATTRIBUTE_WEAK; extern void _ITM_deregisterTMCloneTable (void *) TARGET_ATTRIBUTE_WEAK; @@ -266,6 +269,15 @@ STATIC EH_FRAME_SECTION_CONST char __EH_FRAME_BEGIN__[] = { }; #endif /* USE_EH_FRAME_REGISTRY */ +#ifdef __LIBGCC_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__ ((used, section(__LIBGCC_JCR_SECTION_NAME__), + aligned(sizeof(void*)))) + = { }; +#endif /* __LIBGCC_JCR_SECTION_NAME__ */ + #if USE_TM_CLONE_REGISTRY STATIC func_ptr __TMC_LIST__[] __attribute__((used, section(".tm_clone_table"), aligned(__alignof__(void*)))) @@ -465,7 +477,8 @@ CRT_CALL_STATIC_FUNCTION (__LIBGCC_INIT_SECTION_ASM_OP__, #endif /* defined(CRTSTUFFS_O) || !defined(FINI_ARRAY_SECTION_ASM_OP) || USE_TM_CLONE_REGISTRY || defined(USE_EH_FRAME_REGISTRY) */ -#if defined(USE_EH_FRAME_REGISTRY) || USE_TM_CLONE_REGISTRY +#if defined(USE_EH_FRAME_REGISTRY) || USE_TM_CLONE_REGISTRY \ + || defined(__LIBGCC_JCR_SECTION_NAME__) /* Stick a call to __register_frame_info into the .init section. For some reason calls with no arguments work more reliably in .init, so stick the call in another function. */ @@ -487,6 +500,18 @@ frame_dummy (void) #endif /* CRT_GET_RFIB_DATA */ #endif /* USE_EH_FRAME_REGISTRY */ +#ifdef __LIBGCC_JCR_SECTION_NAME__ + void **jcr_list; + __asm ("" : "=g" (jcr_list) : "0" (__JCR_LIST__)); + if (__builtin_expect (*jcr_list != NULL, 0)) + { + void (*register_classes) (void *) = _Jv_RegisterClasses; + __asm ("" : "+r" (register_classes)); + if (register_classes) + register_classes (jcr_list); + } +#endif /* __LIBGCC_JCR_SECTION_NAME__ */ + #if USE_TM_CLONE_REGISTRY register_tm_clones (); #endif /* USE_TM_CLONE_REGISTRY */ @@ -507,7 +532,7 @@ static func_ptr __frame_dummy_init_array_entry[] aligned(__alignof__(func_ptr)))) = { frame_dummy }; #endif /* defined(__FDPIC__) */ #endif /* !defined(__LIBGCC_INIT_SECTION_ASM_OP__) */ -#endif /* USE_EH_FRAME_REGISTRY || USE_TM_CLONE_REGISTRY */ +#endif /* USE_EH_FRAME_REGISTRY || __LIBGCC_JCR_SECTION_NAME__ || USE_TM_CLONE_REGISTRY */ #else /* OBJECT_FORMAT_ELF */ @@ -574,7 +599,8 @@ __do_global_dtors (void) #endif } -#if defined(USE_EH_FRAME_REGISTRY) || USE_TM_CLONE_REGISTRY +#if defined(USE_EH_FRAME_REGISTRY) || USE_TM_CLONE_REGISTRY \ + || defined(__LIBGCC_JCR_SECTION_NAME__) /* A helper function for __do_global_ctors, which is in crtend.o. Here in crtbegin.o, we can reference a couple of symbols not visible there. Plus, since we're before libgcc.a, we have no problems referencing @@ -588,11 +614,23 @@ __do_global_ctors_1(void) __register_frame_info (__EH_FRAME_BEGIN__, &object); #endif +#ifdef __LIBGCC_JCR_SECTION_NAME__ + void **jcr_list; + __asm ("" : "=g" (jcr_list) : "0" (__JCR_LIST__)); + if (__builtin_expect (*jcr_list != NULL, 0)) + { + void (*register_classes) (void *) = _Jv_RegisterClasses; + __asm ("" : "+r" (register_classes)); + if (register_classes) + register_classes (jcr_list); + } +#endif + #if USE_TM_CLONE_REGISTRY register_tm_clones (); #endif /* USE_TM_CLONE_REGISTRY */ } -#endif /* USE_EH_FRAME_REGISTRY || USE_TM_CLONE_REGISTRY */ +#endif /* USE_EH_FRAME_REGISTRY || __LIBGCC_JCR_SECTION_NAME__ || USE_TM_CLONE_REGISTRY */ #else /* ! __LIBGCC_INIT_SECTION_ASM_OP__ && ! HAS_INIT_SECTION */ #error "What are you doing with crtstuff.c, then?" @@ -668,6 +706,14 @@ STATIC EH_FRAME_SECTION_CONST int32 __FRAME_END__[] = { 0 }; #endif /* __LIBGCC_EH_FRAME_SECTION_NAME__ */ +#ifdef __LIBGCC_JCR_SECTION_NAME__ +/* Null terminate the .jcr section array. */ +STATIC void *__JCR_END__[1] + __attribute__ ((used, section(__LIBGCC_JCR_SECTION_NAME__), + aligned(sizeof(void *)))) + = { 0 }; +#endif /* __LIBGCC_JCR_SECTION_NAME__ */ + #if USE_TM_CLONE_REGISTRY # ifndef HAVE_GAS_HIDDEN static @@ -746,7 +792,8 @@ void __do_global_ctors (void) { func_ptr *p; -#if defined(USE_EH_FRAME_REGISTRY) || USE_TM_CLONE_REGISTRY +#if defined(USE_EH_FRAME_REGISTRY) || USE_TM_CLONE_REGISTRY \ + || defined(__LIBGCC_JCR_SECTION_NAME__) __do_global_ctors_1(); #endif for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--) -- 2.38.1