varasm.c (default_exception_section): Move to...
authorJakub Jelinek <jakub@redhat.com>
Tue, 26 Nov 2002 12:34:25 +0000 (13:34 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 26 Nov 2002 12:34:25 +0000 (13:34 +0100)
* varasm.c (default_exception_section): Move to...
* except.c (default_exception_section): ... here. Make
.gcc_except_table read-only if it is not expected to have any
dynamic relocations and linker handles it.
* dwarf2out.c (default_eh_frame_section): Make .eh_frame read-only
if it is not expected to have any dynamic relocations and linker
handles it.
* configure.in (HAVE_LD_RO_RW_SECTION_MIXING): Check what ld does
when linking read-only and read-write sections together.
* configure, config.in: Rebuilt.
* crtstuff.c (EH_FRAME_SECTION_CONST): Define.
(__EH_FRAME_BEGIN__, __FRAME_END__): Add it.

From-SVN: r59507

gcc/ChangeLog
gcc/config.in
gcc/configure
gcc/configure.in
gcc/crtstuff.c
gcc/dwarf2out.c
gcc/except.c
gcc/varasm.c

index 95683954718ff01791b8460d0bb80cc058cd4df6..5884c5fb0e6895d674e6d3005168853470f354d7 100644 (file)
@@ -1,3 +1,18 @@
+2002-11-26  Jakub Jelinek  <jakub@redhat.com>
+
+       * varasm.c (default_exception_section): Move to...
+       * except.c (default_exception_section): ... here. Make
+       .gcc_except_table read-only if it is not expected to have any
+       dynamic relocations and linker handles it.
+       * dwarf2out.c (default_eh_frame_section): Make .eh_frame read-only
+       if it is not expected to have any dynamic relocations and linker
+       handles it.
+       * configure.in (HAVE_LD_RO_RW_SECTION_MIXING): Check what ld does
+       when linking read-only and read-write sections together.
+       * configure, config.in: Rebuilt.
+       * crtstuff.c (EH_FRAME_SECTION_CONST): Define.
+       (__EH_FRAME_BEGIN__, __FRAME_END__): Add it.
+
 2002-11-25  Aldy Hernandez  <aldyh@redhat.com>
 
         * config/rs6000/spe.h (__ev_create_sfix32_fs): Change macro into
index 6c6a74dffd987d220f0e2ec063f6731be2944315..d26ddfe23d8cd9ae60b0323df96cb41ea04cee52 100644 (file)
 /* Define if your assembler supports the --gstabs option. */
 #undef HAVE_AS_GSTABS_DEBUG_FLAG
 
+/* Define if your linker links a mix of read-only
+   and read-write sections into a read-write section. */
+#undef HAVE_LD_RO_RW_SECTION_MIXING
+
 /* Define if your linker supports --eh-frame-hdr option. */
 #undef HAVE_LD_EH_FRAME_HDR
 
index 8d75a25934c9509fc154bd04c2a40140f1933ad3..c041d8d59c53b360e2bf47de2b8efff1cc82ec94 100755 (executable)
@@ -8113,6 +8113,44 @@ EOF
 fi
 echo "$ac_t""$gcc_cv_as_gstabs_flag" 1>&6
 
+echo $ac_n "checking linker read-only and read-write section mixing""... $ac_c" 1>&6
+echo "configure:8118: checking linker read-only and read-write section mixing" >&5
+gcc_cv_ld_ro_rw_mix=unknown
+if test x$gcc_cv_gld_major_version != x -a x$gcc_cv_gld_minor_version != x; then
+  if test "$gcc_cv_gld_major_version" -eq 2 -a "$gcc_cv_gld_minor_version" -ge 10 -o "$gcc_cv_gld_major_version" -gt 2 && grep 'EMUL = elf' ../ld/Makefile > /dev/null; then
+    gcc_cv_ld_ro_rw_mix=read-write
+  fi
+elif test x$gcc_cv_as != x -a x$gcc_cv_ld != x -a x$gcc_cv_objdump != x ; then
+  echo '.section "myfoosect", "a"' > conftest1.s
+  echo '.section "myfoosect", "aw"' > conftest2.s
+  echo '.byte 1' >> conftest2.s
+  echo '.section "myfoosect", "a"' > conftest3.s
+  echo '.byte 0' >> conftest3.s
+  if $gcc_cv_as -o conftest1.o conftest1.s \
+     && $gcc_cv_as -o conftest2.o conftest2.s \
+     && $gcc_cv_as -o conftest3.o conftest3.s \
+     && $gcc_cv_ld -shared -o conftest1.so conftest1.o \
+       conftest2.o conftest3.o; then
+    gcc_cv_ld_ro_rw_mix=`$gcc_cv_objdump -h conftest1.so \
+                        | grep -A1 myfoosect`
+    if echo "$gcc_cv_ld_ro_rw_mix" | grep CONTENTS > /dev/null; then
+      if echo "$gcc_cv_ld_ro_rw_mix" | grep READONLY > /dev/null; then
+       gcc_cv_ld_ro_rw_mix=read-only
+      else
+       gcc_cv_ld_ro_rw_mix=read-write
+      fi
+    fi
+  fi
+  rm -f conftest.* conftest[123].*
+fi
+if test x$gcc_cv_ld_ro_rw_mix = xread-write; then
+       cat >> confdefs.h <<\EOF
+#define HAVE_LD_RO_RW_SECTION_MIXING 1
+EOF
+
+fi
+echo "$ac_t""$gcc_cv_ld_ro_rw_mix" 1>&6
+
 echo $ac_n "checking linker PT_GNU_EH_FRAME support""... $ac_c" 1>&6
 echo "configure:8118: checking linker PT_GNU_EH_FRAME support" >&5
 gcc_cv_ld_eh_frame_hdr=no
index efc9924070655d8efd130e460ef28f7c4eeee144..7e1628091a3f081fbac55c425368344558055281 100644 (file)
@@ -2209,6 +2209,44 @@ if test x"$gcc_cv_as_gstabs_flag" = xyes; then
 fi
 AC_MSG_RESULT($gcc_cv_as_gstabs_flag)
 
+AC_MSG_CHECKING(linker read-only and read-write section mixing)
+gcc_cv_ld_ro_rw_mix=unknown
+if test x$gcc_cv_gld_major_version != x -a x$gcc_cv_gld_minor_version != x; then
+  if test "$gcc_cv_gld_major_version" -eq 2 -a "$gcc_cv_gld_minor_version" -ge 10 -o "$gcc_cv_gld_major_version" -gt 2 && grep 'EMUL = elf' ../ld/Makefile > /dev/null; then
+    gcc_cv_ld_ro_rw_mix=read-write
+  fi
+elif test x$gcc_cv_as != x -a x$gcc_cv_ld != x -a x$gcc_cv_objdump != x ; then
+  echo '.section "myfoosect", "a"' > conftest1.s
+  echo '.section "myfoosect", "aw"' > conftest2.s
+  echo '.byte 1' >> conftest2.s
+  echo '.section "myfoosect", "a"' > conftest3.s
+  echo '.byte 0' >> conftest3.s
+  if $gcc_cv_as -o conftest1.o conftest1.s \
+     && $gcc_cv_as -o conftest2.o conftest2.s \
+     && $gcc_cv_as -o conftest3.o conftest3.s \
+     && $gcc_cv_ld -shared -o conftest1.so conftest1.o \
+       conftest2.o conftest3.o; then
+    gcc_cv_ld_ro_rw_mix=`$gcc_cv_objdump -h conftest1.so \
+                        | grep -A1 myfoosect`
+    if echo "$gcc_cv_ld_ro_rw_mix" | grep CONTENTS > /dev/null; then
+      if echo "$gcc_cv_ld_ro_rw_mix" | grep READONLY > /dev/null; then
+       gcc_cv_ld_ro_rw_mix=read-only
+      else
+       gcc_cv_ld_ro_rw_mix=read-write
+      fi
+    fi
+  fi
+changequote(,)dnl
+  rm -f conftest.* conftest[123].*
+changequote([,])dnl
+fi
+if test x$gcc_cv_ld_ro_rw_mix = xread-write; then
+       AC_DEFINE(HAVE_LD_RO_RW_SECTION_MIXING, 1,
+  [Define if your linker links a mix of read-only
+   and read-write sections into a read-write section.])
+fi
+AC_MSG_RESULT($gcc_cv_ld_ro_rw_mix)
+
 AC_MSG_CHECKING(linker PT_GNU_EH_FRAME support)
 gcc_cv_ld_eh_frame_hdr=no
 if test x$gcc_cv_gld_major_version != x -a x$gcc_cv_gld_minor_version != x; then
index e5f5d78aeea83bea230429d55611cdd6335ae859..cdc447d248d718c9d90fa237d3fb2ece84e2b8b4 100644 (file)
@@ -90,6 +90,11 @@ 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)
+# define EH_FRAME_SECTION_CONST const
+#else
+# define EH_FRAME_SECTION_CONST
+#endif
 
 /* We do not want to add the weak attribute to the declarations of these
    routines in unwind-dw2-fde.h because that will cause the definition of
@@ -188,7 +193,7 @@ STATIC func_ptr __DTOR_LIST__[1]
 #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 char __EH_FRAME_BEGIN__[]
+STATIC EH_FRAME_SECTION_CONST char __EH_FRAME_BEGIN__[]
      __attribute__((section(EH_FRAME_SECTION_NAME), aligned(4)))
      = { };
 #endif /* USE_EH_FRAME_REGISTRY */
@@ -453,7 +458,7 @@ STATIC func_ptr __DTOR_END__[1]
 #ifdef EH_FRAME_SECTION_NAME
 /* Terminate the frame unwind info section with a 4byte 0 as a sentinel;
    this would be the 'length' field in a real FDE.  */
-STATIC int __FRAME_END__[]
+STATIC EH_FRAME_SECTION_CONST int __FRAME_END__[]
      __attribute__ ((unused, mode(SI), section(EH_FRAME_SECTION_NAME),
                     aligned(4)))
      = { 0 };
index ed2a0ecd00e9ebe9df6cafba310fe553ef9c8085..2e8fe614188f58fa2776169b52cca4274746af03 100644 (file)
@@ -117,7 +117,24 @@ void
 default_eh_frame_section ()
 {
 #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;
+  named_section_flags (EH_FRAME_SECTION_NAME, flags);
+#else
   named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE);
+#endif
 #else
   tree label = get_file_function_name ('F');
 
index 08c0aa27ab240a48a9d8d359df6fad96e40703e1..0a5e49fa813c964e2ee84a332ae6df46c78f2225 100644 (file)
@@ -3589,6 +3589,33 @@ sjlj_output_call_site_table ()
   call_site_base += n;
 }
 
+/* Tell assembler to switch to the section for the exception handling
+   table.  */
+
+void
+default_exception_section ()
+{
+  if (targetm.have_named_sections)
+    {
+      int tt_format = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/1);
+      int flags;
+
+#ifdef HAVE_LD_RO_RW_SECTION_MIXING
+      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
+      named_section_flags (".gcc_except_table", flags);
+    }
+  else if (flag_pic)
+    data_section ();
+  else
+    readonly_data_section ();
+}
+
 void
 output_function_exception_table ()
 {
index b158b92a9b980a9220c8b2d0dfe38f88325d17ad..a3d283a8b56290c95642da5c2fdd14072807821f 100644 (file)
@@ -582,20 +582,6 @@ variable_section (decl, reloc)
     (*targetm.asm_out.select_section) (decl, reloc, DECL_ALIGN (decl));
 }
 
-/* Tell assembler to switch to the section for the exception handling
-   table.  */
-
-void
-default_exception_section ()
-{
-  if (targetm.have_named_sections)
-    named_section (NULL_TREE, ".gcc_except_table", 0);
-  else if (flag_pic)
-    data_section ();
-  else
-    readonly_data_section ();
-}
-
 /* Tell assembler to switch to the section for string merging.  */
 
 void