@@ -45,6 +45,14 @@ along with GCC; see the file COPYING3. If not see
#undef CC1_SPEC
#define CC1_SPEC GNU_USER_TARGET_CC1_SPEC
+#undef USE_CRT_BEGIN1
+#define USE_CRT_BEGIN1
+#define GNU_USER_TARGET_BEGIN1_SPEC \
+ "%{static:crtbeginT1.o%s;shared|pie:crtbeginS1.o%s;:crtbegin1.o%s}"
+#undef STARTFILE_SPEC
+#define STARTFILE_SPEC GNU_USER_TARGET_BEGIN1_SPEC " " \
+ GNU_USER_TARGET_STARTFILE_SPEC
+
/* Similar to standard GNU userspace, but adding -ffast-math support. */
#define GNU_USER_TARGET_MATHFILE_SPEC \
"%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \
@@ -44,7 +44,8 @@ along with GCC; see the file COPYING3. If not see
#undef STARTFILE_SPEC
#define STARTFILE_SPEC \
- LINUX_OR_ANDROID_LD (GNU_USER_TARGET_STARTFILE_SPEC, \
+ LINUX_OR_ANDROID_LD (GNU_USER_TARGET_BEGIN1_SPEC " " \
+ GNU_USER_TARGET_STARTFILE_SPEC, \
ANDROID_STARTFILE_SPEC)
#undef ENDFILE_SPEC
@@ -56,8 +56,8 @@ Special flags used when compiling @file{crtstuff.c}.
@findex CRTSTUFF_T_CFLAGS_S
@item CRTSTUFF_T_CFLAGS_S
Special flags used when compiling @file{crtstuff.c} for shared
-linking. Used if you use @file{crtbeginS.o} and @file{crtendS.o}
-in @code{EXTRA-PARTS}.
+linking. Used if you use @file{crtbeginS.o}, @file{crtendS.o} and
+possibly @file{crtbeginS1.o} in @code{EXTRA-PARTS}.
@xref{Initialization}.
@findex MULTILIB_OPTIONS
@@ -8186,7 +8186,8 @@ parts of @file{crtstuff.c} are compiled into that section. The
program is linked by the @command{gcc} driver like this:
@smallexample
-ld -o @var{output_file} crti.o crtbegin.o @dots{} -lgcc crtend.o crtn.o
+ld -o @var{output_file} crtbegin1.o crti.o crtbegin.o @dots{} \
+ -lgcc crtend.o crtn.o
@end smallexample
The prologue of a function (@code{__init}) appears in the @code{.init}
@@ -8195,12 +8196,13 @@ for the function @code{__fini} in the @dfn{.fini} section. Normally these
files are provided by the operating system or by the GNU C library, but
are provided by GCC for a few targets.
-The objects @file{crtbegin.o} and @file{crtend.o} are (for most targets)
-compiled from @file{crtstuff.c}. They contain, among other things, code
-fragments within the @code{.init} and @code{.fini} sections that branch
-to routines in the @code{.text} section. The linker will pull all parts
-of a section together, which results in a complete @code{__init} function
-that invokes the routines we need at startup.
+The objects @file{crtbegin1.o}, @file{crtbegin.o} and @file{crtend.o}
+are (for most targets) compiled from @file{crtstuff.c}. They contain,
+among other things, code fragments within the @code{.init} and
+@code{.fini} sections that branch to routines in the @code{.text}
+section. The linker will pull all parts of a section together, which
+results in a complete @code{__init} function that invokes the routines
+we need at startup.
To use this variant, you must define the @code{INIT_SECTION_ASM_OP}
macro properly.
@@ -8765,6 +8767,15 @@ runtime relocation, but the linker may not support merging read-only
and read-write sections into a single read-write section.
@end defmac
+@defmac USE_CRT_BEGIN1
+If defined, exception handling frame unwind information start marker
+will be placed in separate file @file{crtbeginS1.o}.
+@file{crtbeginS1.o} needs to be also requested in @code{EXTRA-PARTS} of
+the libgcc @file{config.host}. @file{crtbeginS1.o} should be linked as
+the very first file before startup files like @file{crti.o} so that they
+can also produce frame unwind information.
+@end defmac
+
@defmac MASK_RETURN_ADDR
An rtx used to mask the return address found via @code{RETURN_ADDR_RTX}, so
that it does not contain any extraneous set bits in it.
@@ -953,6 +953,9 @@ ifeq ($(CUSTOM_CRTSTUFF),)
# Compile two additional files that are linked with every program
# linked using GCC on systems using COFF or ELF, for the sake of C++
# constructors.
+crtbegin1$(objext): $(srcdir)/crtstuff.c
+ $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN1
+
crtbegin$(objext): $(srcdir)/crtstuff.c
$(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN
@@ -960,6 +963,9 @@ crtend$(objext): $(srcdir)/crtstuff.c
$(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_END
# These are versions of crtbegin and crtend for shared libraries.
+crtbeginS1$(objext): $(srcdir)/crtstuff.c
+ $(crt_compile) $(CRTSTUFF_T_CFLAGS_S) -c $< -DCRT_BEGIN1 -DCRTSTUFFS_O
+
crtbeginS$(objext): $(srcdir)/crtstuff.c
$(crt_compile) $(CRTSTUFF_T_CFLAGS_S) -c $< -DCRT_BEGIN -DCRTSTUFFS_O
@@ -967,6 +973,9 @@ crtendS$(objext): $(srcdir)/crtstuff.c
$(crt_compile) $(CRTSTUFF_T_CFLAGS_S) -c $< -DCRT_END -DCRTSTUFFS_O
# This is a version of crtbegin for -static links.
+crtbeginT1$(objext): $(srcdir)/crtstuff.c
+ $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN1 -DCRTSTUFFT_O
+
crtbeginT$(objext): $(srcdir)/crtstuff.c
$(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN -DCRTSTUFFT_O
endif
@@ -520,20 +520,24 @@ x86_64-*-openbsd*)
;;
i[34567]86-*-linux*)
extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o"
+ extra_parts="$extra_parts crtbegin1.o crtbeginS1.o crtbeginT1.o"
tmake_file="${tmake_file} i386/t-crtpc i386/t-crtfm i386/t-crtstuff t-dfprules"
md_unwind_header=i386/linux-unwind.h
;;
i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-knetbsd*-gnu | i[34567]86-*-gnu* | i[34567]86-*-kopensolaris*-gnu)
extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o"
+ extra_parts="$extra_parts crtbegin1.o crtbeginS1.o crtbeginT1.o"
tmake_file="${tmake_file} i386/t-crtpc i386/t-crtfm i386/t-crtstuff t-dfprules"
;;
x86_64-*-linux*)
extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o"
+ extra_parts="$extra_parts crtbegin1.o crtbeginS1.o crtbeginT1.o"
tmake_file="${tmake_file} i386/t-crtpc i386/t-crtfm i386/t-crtstuff t-dfprules"
md_unwind_header=i386/linux-unwind.h
;;
x86_64-*-kfreebsd*-gnu | x86_64-*-knetbsd*-gnu)
extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o"
+ extra_parts="$extra_parts crtbegin1.o crtbeginS1.o crtbeginT1.o"
tmake_file="${tmake_file} i386/t-crtpc i386/t-crtfm i386/t-crtstuff t-dfprules"
;;
i[34567]86-pc-msdosdjgpp*)
@@ -197,7 +197,34 @@ typedef void (*func_ptr) (void);
#endif /* OBJECT_FORMAT_ELF */
-#ifdef CRT_BEGIN
+#ifdef CRT_BEGIN1
+
+#ifndef USE_CRT_BEGIN1
+# error "USE_CRT_BEGIN1 must be defined if CRT_BEGIN1 is in use."
+#endif /* ! USE_CRT_BEGIN1 */
+
+#ifdef USE_EH_FRAME_REGISTRY
+EH_FRAME_SECTION_CONST char __EH_FRAME_BEGIN__[]
+ __attribute__((section(EH_FRAME_SECTION_NAME), aligned(4),
+ __visibility__ ("hidden")))
+ = { };
+#endif /* USE_EH_FRAME_REGISTRY */
+
+#elif defined(CRT_BEGIN) /* ! CRT_BEGIN1 */
+
+#ifndef USE_CRT_BEGIN1
+# ifdef USE_EH_FRAME_REGISTRY
+/* Stick a label at the beginning of the frame unwind info so we can register
+ and deregister it with the exception handling library code. */
+STATIC EH_FRAME_SECTION_CONST char __EH_FRAME_BEGIN__[]
+ __attribute__((section(EH_FRAME_SECTION_NAME), aligned(4)))
+ = { };
+# endif /* USE_EH_FRAME_REGISTRY */
+#else /* USE_CRT_BEGIN1 */
+# ifdef USE_EH_FRAME_REGISTRY
+extern EH_FRAME_SECTION_CONST char __EH_FRAME_BEGIN__[];
+# endif /* USE_EH_FRAME_REGISTRY */
+#endif /* USE_CRT_BEGIN1 */
/* NOTE: In order to be able to support SVR4 shared libraries, we arrange
to have one set of symbols { __CTOR_LIST__, __DTOR_LIST__, __CTOR_END__,
@@ -246,14 +273,6 @@ STATIC func_ptr __DTOR_LIST__[1]
#endif /* __DTOR_LIST__ alternatives */
#endif /* USE_INITFINI_ARRAY */
-#ifdef USE_EH_FRAME_REGISTRY
-/* Stick a label at the beginning of the frame unwind info so we can register
- and deregister it with the exception handling library code. */
-STATIC EH_FRAME_SECTION_CONST char __EH_FRAME_BEGIN__[]
- __attribute__((section(EH_FRAME_SECTION_NAME), aligned(4)))
- = { };
-#endif /* USE_EH_FRAME_REGISTRY */
-
#ifdef JCR_SECTION_NAME
/* Stick a label at the beginning of the java class registration info
so we can register them properly. */
@@ -584,7 +603,7 @@ __do_global_ctors_1(void)
#error "What are you doing with crtstuff.c, then?"
#endif
-#elif defined(CRT_END) /* ! CRT_BEGIN */
+#elif defined(CRT_END) /* ! CRT_BEGIN1 && ! CRT_BEGIN */
/* No need for .ctors/.dtors section if linker can place them in
.init_array/.fini_array section. */
@@ -752,6 +771,6 @@ __do_global_ctors (void)
#error "What are you doing with crtstuff.c, then?"
#endif
-#else /* ! CRT_BEGIN && ! CRT_END */
-#error "One of CRT_BEGIN or CRT_END must be defined."
+#else /* ! CRT_BEGIN1 && ! CRT_BEGIN && ! CRT_END */
+#error "One of CRT_BEGIN1, CRT_BEGIN or CRT_END must be defined."
#endif