This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch for read-only EH tables for AMD64 Solaris 10
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 18 Nov 2004 21:14:07 +0000 (UTC)
- Subject: Patch for read-only EH tables for AMD64 Solaris 10
AMD64 Solaris 10 uses a .eh_frame format that does not require runtime
relocations, but the Solaris linker will not merge read-only and
read/write sections. This patch adds EH_TABLES_CAN_BE_READ_ONLY,
default based on HAVE_LD_RO_RW_SECTION_MIXING, so that the .eh_frame
sections can be read-only. This patch should have no effect on
targets other than AMD64 Solaris 10.
Bootstrapped with no regressions on i386-pc-solaris2.10. OK to
commit?
2004-11-18 Mark Mitchell <mark@codesourcery.com>
Joseph Myers <joseph@codesourcery.com>
* crtstuff.c (IN_LIBGCC2): Define it.
(EH_FRAME_SECTION_CONST): Check EH_TABLES_CAN_BE_READ_ONLY
instead of HAVE_LD_RO_RW_SECTION_MIXING.
* defaults.h (EH_TABLES_CAN_BE_READ_ONLY): New macro.
* dwarf2out.c (named_section_eh_frame_section): Check
EH_TABLES_CAN_BE_READ_ONLY.
* except.c (default_exception_section): Likewise.
* config/i386/sol2.h (EH_TABLES_CAN_BE_READ_ONLY): Define.
* doc/tm.texi (EH_TABLES_CAN_BE_READ_ONLY): Document.
diff -rupN -x CVS gcc-merge-HEAD-csl-sol210-1/gcc/config/i386/sol2.h gcc-sol210/gcc/config/i386/sol2.h
--- gcc-merge-HEAD-csl-sol210-1/gcc/config/i386/sol2.h 2004-07-25 11:10:03.000000000 -0700
+++ gcc-sol210/gcc/config/i386/sol2.h 2004-10-26 10:56:37.000000000 -0700
@@ -40,6 +40,15 @@
: DW_EH_PE_datarel)) \
: DW_EH_PE_absptr)
+/* The Solaris linker will not merge a read-only .eh_frame section
+ with a read-write .eh_frame section. None of the encodings used
+ with non-PIC code require runtime relocations. In 64-bit mode,
+ since there is no backwards compatibility issue, we use a read-only
+ section for .eh_frame. In 32-bit mode, we use a writable .eh_frame
+ section in order to be compatible with G++ for Solaris x86. */
+#undef EH_TABLES_CAN_BE_READ_ONLY
+#define EH_TABLES_CAN_BE_READ_ONLY (TARGET_64BIT)
+
/* Solaris 2/Intel as chokes on #line directives. */
#undef CPP_SPEC
#define CPP_SPEC "%{.S:-P} %(cpp_subtarget)"
diff -rupN -x CVS gcc-merge-HEAD-csl-sol210-1/gcc/crtstuff.c gcc-sol210/gcc/crtstuff.c
--- gcc-merge-HEAD-csl-sol210-1/gcc/crtstuff.c 2004-09-18 12:47:09.000000000 -0700
+++ gcc-sol210/gcc/crtstuff.c 2004-10-25 20:16:13.000000000 -0700
@@ -55,6 +55,8 @@ Software Foundation, 59 Temple Place - S
compiled for the target, and hence definitions concerning only the host
do not apply. */
+#define IN_LIBGCC2
+
/* We include auto-host.h here to get HAVE_GAS_HIDDEN. This is
supposedly valid even though this is a "target" file. */
#include "auto-host.h"
@@ -92,7 +94,7 @@ call_ ## FUNC (void) \
#if defined(EH_FRAME_SECTION_NAME) && !defined(USE_PT_GNU_EH_FRAME)
# define USE_EH_FRAME_REGISTRY
#endif
-#if defined(EH_FRAME_SECTION_NAME) && defined(HAVE_LD_RO_RW_SECTION_MIXING)
+#if defined(EH_FRAME_SECTION_NAME) && EH_TABLES_CAN_BE_READ_ONLY
# define EH_FRAME_SECTION_CONST const
#else
# define EH_FRAME_SECTION_CONST
diff -rupN -x CVS gcc-merge-HEAD-csl-sol210-1/gcc/defaults.h gcc-sol210/gcc/defaults.h
--- gcc-merge-HEAD-csl-sol210-1/gcc/defaults.h 2004-09-10 03:44:45.000000000 -0700
+++ gcc-sol210/gcc/defaults.h 2004-10-25 20:16:13.000000000 -0700
@@ -325,6 +325,26 @@ do { fputs (integer_asm_op (POINTER_SIZE
#endif
#endif
+/* On many systems, different EH table encodings are used under
+ difference circumstances. Some will require runtime relocations;
+ some will not. For those that do not require runtime relocations,
+ we would like to make the table read-only. However, since the
+ read-only tables may need to be combined with read-write tables
+ that do require runtime relocation, it is not safe to make the
+ tables read-only unless the linker will merge read-only and
+ read-write sections into a single read-write section. If your
+ linker does not have this ability, but your system is such that no
+ encoding used with non-PIC code will ever require a runtime
+ relocation, then you can define EH_TABLES_CAN_BE_READ_ONLY to 1 in
+ your target configuration file. */
+#ifndef EH_TABLES_CAN_BE_READ_ONLY
+#ifdef HAVE_LD_RO_RW_SECTION_MIXING
+#define EH_TABLES_CAN_BE_READ_ONLY 1
+#else
+#define EH_TABLES_CAN_BE_READ_ONLY 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. */
diff -rupN -x CVS gcc-merge-HEAD-csl-sol210-1/gcc/dwarf2out.c gcc-sol210/gcc/dwarf2out.c
--- gcc-merge-HEAD-csl-sol210-1/gcc/dwarf2out.c 2004-09-22 17:51:36.000000000 -0700
+++ gcc-sol210/gcc/dwarf2out.c 2004-10-25 20:16:13.000000000 -0700
@@ -121,24 +121,29 @@ void
named_section_eh_frame_section (void)
{
#ifdef EH_FRAME_SECTION_NAME
-#ifdef HAVE_LD_RO_RW_SECTION_MIXING
- int fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
- int per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
- int lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
int flags;
- flags = (! flag_pic
- || ((fde_encoding & 0x70) != DW_EH_PE_absptr
- && (fde_encoding & 0x70) != DW_EH_PE_aligned
- && (per_encoding & 0x70) != DW_EH_PE_absptr
- && (per_encoding & 0x70) != DW_EH_PE_aligned
- && (lsda_encoding & 0x70) != DW_EH_PE_absptr
- && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
- ? 0 : SECTION_WRITE;
+ if (EH_TABLES_CAN_BE_READ_ONLY)
+ {
+ int fde_encoding;
+ int per_encoding;
+ int lsda_encoding;
+
+ fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
+ per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
+ lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
+ flags = (! flag_pic
+ || ((fde_encoding & 0x70) != DW_EH_PE_absptr
+ && (fde_encoding & 0x70) != DW_EH_PE_aligned
+ && (per_encoding & 0x70) != DW_EH_PE_absptr
+ && (per_encoding & 0x70) != DW_EH_PE_aligned
+ && (lsda_encoding & 0x70) != DW_EH_PE_absptr
+ && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
+ ? 0 : SECTION_WRITE;
+ }
+ else
+ flags = SECTION_WRITE;
named_section_flags (EH_FRAME_SECTION_NAME, flags);
-#else
- named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE);
-#endif
#endif
}
diff -rupN -x CVS gcc-merge-HEAD-csl-sol210-1/gcc/except.c gcc-sol210/gcc/except.c
--- gcc-merge-HEAD-csl-sol210-1/gcc/except.c 2004-09-15 13:47:39.000000000 -0700
+++ gcc-sol210/gcc/except.c 2004-10-25 20:16:13.000000000 -0700
@@ -3555,16 +3555,18 @@ default_exception_section (void)
if (targetm.have_named_sections)
{
int flags;
-#ifdef HAVE_LD_RO_RW_SECTION_MIXING
- int tt_format = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/1);
- flags = (! flag_pic
- || ((tt_format & 0x70) != DW_EH_PE_absptr
- && (tt_format & 0x70) != DW_EH_PE_aligned))
- ? 0 : SECTION_WRITE;
-#else
- flags = SECTION_WRITE;
-#endif
+ if (EH_TABLES_CAN_BE_READ_ONLY)
+ {
+ int tt_format = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/1);
+
+ flags = (! flag_pic
+ || ((tt_format & 0x70) != DW_EH_PE_absptr
+ && (tt_format & 0x70) != DW_EH_PE_aligned))
+ ? 0 : SECTION_WRITE;
+ }
+ else
+ flags = SECTION_WRITE;
named_section_flags (".gcc_except_table", flags);
}
else if (flag_pic)
--- GCC.orig/gcc/doc/tm.texi 2004-11-18 09:38:16.000000000 +0000
+++ GCC/gcc/doc/tm.texi 2004-11-18 16:15:14.000000000 +0000
@@ -7606,6 +7606,13 @@
also defined.
@end defmac
+@defmac EH_TABLES_CAN_BE_READ_ONLY
+Define this macro to 1 if your target is such that no frame unwind
+information encoding used with non-PIC code will ever require a
+runtime relocation, but the linker may not support merging read-only
+and read-write sections into a single read-write section.
+@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.
--
Joseph S. Myers http://www.srcf.ucam.org/~jsm28/gcc/
jsm@polyomino.org.uk (personal mail)
joseph@codesourcery.com (CodeSourcery mail)
jsm28@gcc.gnu.org (Bugzilla assignments and CCs)