dwarf2 exception fix for djgpp (and possibly others)

Laszlo Molnar laszlo.molnar@eth.ericsson.se
Mon Feb 22 04:07:00 GMT 1999


Hi,

The problem: dwarf2 exception handling was working very unreliably
under ix86-pc-msdosdjgpp since egcs v1.0. After some (lots of :-)
debugging I've found the problem.

It's caused by a strange interaction between egcs and gas. Djgpp uses
the COFF format, and gas from binutils 2.9.1 is compiled without
--enable-bfd-assembler. So, the problem is that the size of the CIE and
FDE structures in the dwarf2 output are always a multiple of 4, so
sometimes padding is needed. Egcs assumes that the padding bytes in
that section are always 0x00 (NOP) bytes. But unfortunately gas handles
this section ("eh_frame") as code (the section is not called "data" nor
"bss"), and uses other aligment bytes (like 0x90). Unfortunately these
bytes are valid byte codes in the dwarf2 byte code interpreter, and it
causes the exception stuff to abort.

A possible solution to this problem is to make sure that 0x00 bytes are
used in this section for padding. Below is a patch by me and Andris
Pavenis <pavenis@lanet.lv> (against egcs 1.1.1) 

Laszlo

--- gcc/dwarf2out.c~1   Thu Jul 30 12:52:18 1998
+++ gcc/dwarf2out.c     Mon Jan 25 15:46:16 1999
@@ -53,6 +53,10 @@
 # define assert(e) do { if (! (e)) abort (); } while (0)
 #endif

+#ifndef ASM_OUTPUT_ALIGN_Z
+#define ASM_OUTPUT_ALIGN_Z(FILE,LOG) ASM_OUTPUT_ALIGN(FILE,LOG)
+#endif
+
 /* Decide whether we want to emit frame unwind information for the current
    translation unit.  */

@@ -1770,7 +1774,7 @@
     output_cfi (cfi, NULL);

   /* Pad the CIE out to an address sized boundary.  */
-  ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
+  ASM_OUTPUT_ALIGN_Z (asm_out_file, floor_log2 (PTR_SIZE));
   ASM_OUTPUT_LABEL (asm_out_file, l2);
 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
   ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
@@ -1830,7 +1834,7 @@
        output_cfi (cfi, fde);

       /* Pad the FDE out to an address sized boundary.  */
-      ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
+      ASM_OUTPUT_ALIGN_Z (asm_out_file, floor_log2 (PTR_SIZE));
       ASM_OUTPUT_LABEL (asm_out_file, l2);
 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
       ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
--- gcc/config/i386/go32.h~1    Mon Jan 25 15:42:40 1999
+++ gcc/config/i386/go32.h      Mon Jan 25 15:47:36 1999
@@ -146,3 +146,9 @@
 /* djgpp automatically calls its own version of __main, so don't define one
    in libgcc, nor call one in main().  */
 #define HAS_INIT_SECTION
+
+/*  alignment to be used in .eh_frame section */
+#undef ASM_OUTPUT_ALIGN_Z
+#define ASM_OUTPUT_ALIGN_Z(FILE,LOG) \
+  if ((LOG) != 0) fprintf ((FILE), "\t.p2align %d,0\n", LOG)
+




More information about the Gcc-patches mailing list