public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [patch ld bfd gas]: Handle linkonce for cfi generated debug_frame and eh_frame data
@ 2011-04-18  9:34 Kai Tietz
  2011-04-18 12:43 ` H.J. Lu
  0 siblings, 1 reply; 12+ messages in thread
From: Kai Tietz @ 2011-04-18  9:34 UTC (permalink / raw)
  To: Binutils; +Cc: Alan Modra, Nick Clifton

[-- Attachment #1: Type: text/plain, Size: 3133 bytes --]

Hello,

The recent patch about this subject I withdraw and replace it by the
more enhanced version.  I noticed that a bit more checkings and a
different approach on writing eh_frame/debug_frame sections out, was
necessary.  Additionally this patch allows for PE-COFF targets, that
debugging sections can have link-once flags active.


ChangeLog bfd/

2011-04-18  Kai Tietz

	* coffcode.h (sec_to_styp_flags): Allow linkonce for
	debugging sections.

ChangeLog gas/

2011-04-18  Kai Tietz

       * dw2gencfi.c (dwcfi_seg_list): New struct.
       (dwcfi_hash): New static hash variable.
       (get_debugseg_name): New.
       (alloc_debugseg_item): New.
       (make_debug_seg): New.
       (dwcfi_hash_insert): New.
       (dwcfi_hash_find): New.
       (dwcfi_hash_find_or_make): New.
       (cfi_insn_data): New member cur_seg.
       (cie_entry): Likewise.
       (fde_entry): New cseg and handled members.
       (alloc_fde_entry): Initialize cseg member.
       (alloc_cfi_insn_data): Initialize cur_seg member.
       (dot_cfi_sections): Compare for beginning of
       section names via strncmp.
       (get_cfi_seg): New.
       (cfi_finish): Treat link-once sections.
       (is_now_linkonce_segment): New local helper.
       (output_cie): Ignore cie entries not member of current
       segment.
       (output_fde): Likewise.
       (select_cie_for_fde): Likewise.
       (cfi_change_reg_numbers): Add new argument for current segment
       and ignore insn elements, if not part of current segment.
       * ehopt.c (get_cie_info): Use strncmp for
       section name matching.
       (heck_eh_frame): Likewise.

ChangeLog ld/

2011-04-18  Kai Tietz

       * scripttempl/alphavms.sc: Handle .eh_frame($|.)* sections.
       * scripttempl/armbpabi.sc: Likewise.
       * scripttempl/avr.sc: Likewise.
       * scripttempl/crisaout.sc: Likewise.
       * scripttempl/elf.sc: Likewise.
       * scripttempl/elf32cr16.sc: Likewise.
       * scripttempl/elf32crx.sc: Likewise.
       * scripttempl/elf32msp430.sc: Likewise.
       * scripttempl/elf32msp430_3.sc: Likewise.
       * scripttempl/elf32sh-symbian.sc: Likewise.
       * scripttempl/elf64hppa.sc: Likewise.
       * scripttempl/elf_chaos.sc: Likewise.
       * scripttempl/elfd10v.sc: Likewise.
       * scripttempl/elfd30v.sc: Likewise.
       * scripttempl/elfi370.sc: Likewise.
       * scripttempl/elfm68hc11.sc: Likewise.
       * scripttempl/elfm68hc12.sc: Likewise.
       * scripttempl/elfmicroblaze.sc: Likewise.
       * scripttempl/elfxtensa.sc: Likewise.
       * scripttempl/epocpe.sc: Likewise.
       * scripttempl/i386beos.sc: Likewise.
       * scripttempl/i386go32.sc: Likewise.
       * scripttempl/ip2k.sc: Likewise.
       * scripttempl/iq2000.sc: Likewise.
       * scripttempl/mcorepe.sc: Likewise.
       * scripttempl/mep.sc: Likewise.
       * scripttempl/mmo.sc: Likewise.
       * scripttempl/pe.sc: Likewise.
       * scripttempl/pep.sc: Likewise.
       * scripttempl/v850.sc: Likewise.
       * scripttempl/xstormy16.sc: Likewise.

Tested for x86_64-w64-mingw32, i686-w64-mingw32, and i686-pc-cygwin.
Ok for apply?

Regards,
Kai

[-- Attachment #2: cfi_lonce.txt --]
[-- Type: text/plain, Size: 44410 bytes --]

Index: src/gas/dw2gencfi.c
===================================================================
--- src.orig/gas/dw2gencfi.c	2011-04-16 12:06:37.722473700 +0200
+++ src/gas/dw2gencfi.c	2011-04-18 09:02:12.640362500 +0200
@@ -76,6 +76,147 @@
 # define DWARF2_ADDR_SIZE(bfd) (bfd_arch_bits_per_address (bfd) / 8)
 #endif
 
+/* Private segment collection list.  */
+struct dwcfi_seg_list {
+  segT seg;
+  int subseg;
+  char *seg_name;
+};
+
+static struct hash_control *dwcfi_hash;
+
+/* Build based on segment the derived .debug_...
+   segment name containing origin segment's postfix name part.  */
+static char *
+get_debugseg_name (segT seg, const char *base_name)
+{
+  const char *name,*dollar, *dot;
+  char *sname;
+
+  if (!seg)
+    name = "";
+  else
+    name = bfd_get_section_name (stdoutput, seg);
+
+  dollar = strchr (name, '$');
+  dot = strchr (name + 1, '.');
+
+  if (!dollar && !dot)
+    name = "";
+  else if (!dollar)
+    name = dot;
+  else if (!dot)
+    name = dollar;
+  else if (dot < dollar)
+    name = dot;
+  else
+    name = dollar;
+
+  sname = concat (base_name, name, NULL);
+
+  return sname;
+}
+
+/* Allocate a dwcfi_seg_list structure.  */
+static struct dwcfi_seg_list *
+alloc_debugseg_item (segT seg, int subseg, char *name)
+{
+  struct dwcfi_seg_list *r;
+
+  r = (struct dwcfi_seg_list *)
+    xmalloc (sizeof (struct dwcfi_seg_list) + strlen (name));
+  r->seg = seg;
+  r->subseg = subseg;
+  r->seg_name = name;
+  return r;
+}
+
+static segT
+is_now_linkonce_segment (void)
+{
+  if ((bfd_get_section_flags (stdoutput, now_seg)
+       & (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
+	  | SEC_LINK_DUPLICATES_ONE_ONLY | SEC_LINK_DUPLICATES_SAME_SIZE
+	  | SEC_LINK_DUPLICATES_SAME_CONTENTS)) != 0)
+    return now_seg;
+  return NULL;
+}
+
+/* Generate debug... segment with same linkonce properties
+   of based segment.  */
+static segT
+make_debug_seg (segT cseg, char *name, int sflags)
+{
+  segT save_seg = now_seg;
+  int save_subseg = now_subseg;
+  segT r;
+  flagword flags;
+
+  r = subseg_new (name, 0);
+  /* Check if code segment is marked as linked once.  */
+  if (!cseg)
+    flags = 0;
+  else
+    flags = bfd_get_section_flags (stdoutput, cseg)
+      & (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
+         | SEC_LINK_DUPLICATES_ONE_ONLY | SEC_LINK_DUPLICATES_SAME_SIZE
+         | SEC_LINK_DUPLICATES_SAME_CONTENTS);
+
+  /* Add standard section flags.  */
+  flags |= sflags;
+
+  /* Apply possibly linked once flags to new generated segment, too.  */
+  if (!bfd_set_section_flags (stdoutput, r, flags))
+    as_bad (_("bfd_set_section_flags: %s"),
+	    bfd_errmsg (bfd_get_error ()));
+
+  /* Restore to previous segment.  */
+  if (save_seg != NULL)
+    subseg_set (save_seg, save_subseg);
+  return r;
+}
+
+static void
+dwcfi_hash_insert (const char *name, struct dwcfi_seg_list *item)
+{
+  const char *error_string;
+
+  if ((error_string = hash_jam (dwcfi_hash, name, (char *) item)))
+    as_fatal (_("Inserting \"%s\" into structure table failed: %s"),
+	      name, error_string);
+}
+
+static struct dwcfi_seg_list *
+dwcfi_hash_find (char *name)
+{
+  return (struct dwcfi_seg_list *) hash_find (dwcfi_hash, name);
+}
+
+static struct dwcfi_seg_list *
+dwcfi_hash_find_or_make (segT cseg, const char *base_name, int flags)
+{
+  struct dwcfi_seg_list *item;
+  char *name;
+
+  /* Initialize dwcfi_hash once.  */
+  if (!dwcfi_hash)
+    dwcfi_hash = hash_new ();
+
+  name = get_debugseg_name (cseg, base_name);
+
+  item = dwcfi_hash_find (name);
+  if (!item)
+    {
+      item = alloc_debugseg_item (make_debug_seg (cseg, name, flags), 0, name);
+
+      dwcfi_hash_insert (item->seg_name, item);
+    }
+  else
+    free (name);
+
+  return item;
+}
+
 /* ??? Share this with dwarf2cfg.c.  */
 #ifndef TC_DWARF2_EMIT_OFFSET
 #define TC_DWARF2_EMIT_OFFSET  generic_dwarf2_emit_offset
@@ -102,6 +243,7 @@ struct cfi_escape_data {
 struct cfi_insn_data
 {
   struct cfi_insn_data *next;
+  segT cur_seg;
   int insn;
   union {
     struct {
@@ -134,6 +276,7 @@ struct cfi_insn_data
 struct fde_entry
 {
   struct fde_entry *next;
+  segT cseg;
   symbolS *start_address;
   symbolS *end_address;
   struct cfi_insn_data *data;
@@ -144,11 +287,13 @@ struct fde_entry
   expressionS lsda;
   unsigned int return_column;
   unsigned int signal_frame;
+  int handled;
 };
 
 struct cie_entry
 {
   struct cie_entry *next;
+  segT cur_seg;
   symbolS *start_address;
   unsigned int return_column;
   unsigned int signal_frame;
@@ -195,7 +340,8 @@ alloc_fde_entry (void)
   frchain_now->frch_cfi_data->cur_fde_data = fde;
   *last_fde_data = fde;
   last_fde_data = &fde->next;
-
+  fde->cseg = is_now_linkonce_segment ();
+  fde->handled = 0;
   fde->last = &fde->data;
   fde->return_column = DWARF2_DEFAULT_RETURN_COLUMN;
   fde->per_encoding = DW_EH_PE_omit;
@@ -219,6 +365,7 @@ alloc_cfi_insn_data (void)
 
   *cur_fde_data->last = insn;
   cur_fde_data->last = &insn->next;
+  insn->cur_seg = is_now_linkonce_segment ();
 
   return insn;
 }
@@ -254,7 +401,7 @@ cfi_set_return_column (unsigned regno)
 /* Universal functions to store new instructions.  */
 
 static void
-cfi_add_CFA_insn(int insn)
+cfi_add_CFA_insn (int insn)
 {
   struct cfi_insn_data *insn_ptr = alloc_cfi_insn_data ();
 
@@ -916,9 +1063,9 @@ dot_cfi_sections (int ignored ATTRIBUTE_
 	name = input_line_pointer;
 	c = get_symbol_end ();
 
-	if (strcmp (name, ".eh_frame") == 0)
+	if (strncmp (name, ".eh_frame", 9) == 0)
 	  sections |= CFI_EMIT_eh_frame;
-	else if (strcmp (name, ".debug_frame") == 0)
+	else if (strncmp (name, ".debug_frame", 12) == 0)
 	  sections |= CFI_EMIT_debug_frame;
 	else
 	  {
@@ -1384,8 +1531,14 @@ output_cie (struct cie_entry *cie, bfd_b
     out_one (enc);
 
   if (cie->first)
-    for (i = cie->first; i != cie->last; i = i->next)
-      output_cfi_insn (i);
+    {
+      for (i = cie->first; i != cie->last; i = i->next)
+        {
+	  if (i->cur_seg != cie->cur_seg)
+	    continue;
+	  output_cfi_insn (i);
+	}
+    }
 
   frag_align (align, DW_CFA_nop, 0);
   symbol_set_value_now (end_address);
@@ -1492,7 +1645,10 @@ output_fde (struct fde_entry *fde, struc
     }
 
   for (; first; first = first->next)
-    output_cfi_insn (first);
+    {
+      if (first->cur_seg == fde->cseg)
+        output_cfi_insn (first);
+    }
 
   frag_align (align, DW_CFA_nop, 0);
   symbol_set_value_now (end_address);
@@ -1507,7 +1663,8 @@ select_cie_for_fde (struct fde_entry *fd
 
   for (cie = cie_root; cie; cie = cie->next)
     {
-      if (cie->return_column != fde->return_column
+      if (cie->cur_seg != fde->cseg
+          || cie->return_column != fde->return_column
 	  || cie->signal_frame != fde->signal_frame
 	  || cie->per_encoding != fde->per_encoding
 	  || cie->lsda_encoding != fde->lsda_encoding)
@@ -1605,6 +1762,7 @@ select_cie_for_fde (struct fde_entry *fd
   cie = (struct cie_entry *) xmalloc (sizeof (struct cie_entry));
   cie->next = cie_root;
   cie_root = cie;
+  cie->cur_seg = fde->cseg;
   cie->return_column = fde->return_column;
   cie->signal_frame = fde->signal_frame;
   cie->per_encoding = fde->per_encoding;
@@ -1629,130 +1787,183 @@ select_cie_for_fde (struct fde_entry *fd
 
 #ifdef md_reg_eh_frame_to_debug_frame
 static void
-cfi_change_reg_numbers (struct cfi_insn_data *insn)
+cfi_change_reg_numbers (struct cfi_insn_data *insn, segT ccseg)
 {
   for (; insn; insn = insn->next)
-    switch (insn->insn)
-      {
-      case DW_CFA_advance_loc:
-      case DW_CFA_def_cfa_offset:
-      case DW_CFA_remember_state:
-      case DW_CFA_restore_state:
-      case DW_CFA_GNU_window_save:
-      case CFI_escape:
-	break;
+    {
+      if (insn->cur_seg != ccseg)
+        continue;
+      switch (insn->insn)
+	{
+	case DW_CFA_advance_loc:
+	case DW_CFA_def_cfa_offset:
+	case DW_CFA_remember_state:
+	case DW_CFA_restore_state:
+	case DW_CFA_GNU_window_save:
+	case CFI_escape:
+	  break;
 
-      case DW_CFA_def_cfa:
-      case DW_CFA_offset:
-	insn->u.ri.reg = md_reg_eh_frame_to_debug_frame (insn->u.ri.reg);
-	break;
+	case DW_CFA_def_cfa:
+	case DW_CFA_offset:
+	  insn->u.ri.reg = md_reg_eh_frame_to_debug_frame (insn->u.ri.reg);
+	  break;
 
-      case DW_CFA_def_cfa_register:
-      case DW_CFA_undefined:
-      case DW_CFA_same_value:
-      case DW_CFA_restore:
-	insn->u.r = md_reg_eh_frame_to_debug_frame (insn->u.r);
-	break;
+	case DW_CFA_def_cfa_register:
+	case DW_CFA_undefined:
+	case DW_CFA_same_value:
+	case DW_CFA_restore:
+	  insn->u.r = md_reg_eh_frame_to_debug_frame (insn->u.r);
+	  break;
 
-      case DW_CFA_register:
-	insn->u.rr.reg1 = md_reg_eh_frame_to_debug_frame (insn->u.rr.reg1);
-	insn->u.rr.reg2 = md_reg_eh_frame_to_debug_frame (insn->u.rr.reg2);
-	break;
+	case DW_CFA_register:
+	  insn->u.rr.reg1 = md_reg_eh_frame_to_debug_frame (insn->u.rr.reg1);
+	  insn->u.rr.reg2 = md_reg_eh_frame_to_debug_frame (insn->u.rr.reg2);
+	  break;
 
-      case CFI_val_encoded_addr:
-	insn->u.ea.reg = md_reg_eh_frame_to_debug_frame (insn->u.ea.reg);
-	break;
+	case CFI_val_encoded_addr:
+	  insn->u.ea.reg = md_reg_eh_frame_to_debug_frame (insn->u.ea.reg);
+	  break;
 
-      default:
-	abort ();
-      }
+	default:
+	  abort ();
+	}
+    }
 }
 #else
-#define cfi_change_reg_numbers(insn) do { } while (0)
+#define cfi_change_reg_numbers(insn, cseg) do { } while (0)
 #endif
 
+static segT
+get_cfi_seg (segT cseg, const char *base, flagword flags, int align)
+{
+  struct dwcfi_seg_list *l;
+
+  l = dwcfi_hash_find_or_make (cseg, base, flags);
+
+  subseg_set (l->seg, l->subseg);
+  record_alignment (l->seg, align);
+  return l->seg;
+}
+
 void
 cfi_finish (void)
 {
-  segT cfi_seg;
+  struct cie_entry *cie, *cie_next;
+  segT cfi_seg, ccseg;
   struct fde_entry *fde;
-  int save_flag_traditional_format;
+  struct cfi_insn_data *first;
+  int save_flag_traditional_format, seek_next_seg;
 
   if (all_fde_data == 0)
     return;
 
   if ((cfi_sections & CFI_EMIT_eh_frame) != 0)
     {
-      /* Open .eh_frame section.  */
-      cfi_seg = subseg_new (".eh_frame", 0);
-      bfd_set_section_flags (stdoutput, cfi_seg,
-			     SEC_ALLOC | SEC_LOAD | SEC_DATA
-			     | DWARF2_EH_FRAME_READ_ONLY);
-      subseg_set (cfi_seg, 0);
-      record_alignment (cfi_seg, EH_FRAME_ALIGNMENT);
-
-#ifdef md_fix_up_eh_frame
-      md_fix_up_eh_frame (cfi_seg);
-#endif
-
       /* Make sure check_eh_frame doesn't do anything with our output.  */
       save_flag_traditional_format = flag_traditional_format;
       flag_traditional_format = 1;
 
-      for (fde = all_fde_data; fde ; fde = fde->next)
-	{
-	  struct cfi_insn_data *first;
-	  struct cie_entry *cie;
-
-	  if (fde->end_address == NULL)
+      do
+        {
+	  ccseg = NULL;
+	  cfi_seg = NULL;
+	  seek_next_seg = 0;
+	  for (cie = cie_root; cie; cie = cie_next)
 	    {
-	      as_bad (_("open CFI at the end of file; missing .cfi_endproc directive"));
-	      fde->end_address = fde->start_address;
+	      cie_next = cie->next;
+	      free ((void *) cie);
 	    }
+	  cie_root = NULL;
 
-	  cie = select_cie_for_fde (fde, TRUE, &first, 2);
-	  output_fde (fde, cie, TRUE, first,
-		      fde->next == NULL ? EH_FRAME_ALIGNMENT : 2);
+	  for (fde = all_fde_data; fde ; fde = fde->next)
+	    {
+	      if (fde->handled != 0)
+	        continue;
+	      if (seek_next_seg && fde->cseg != ccseg)
+	        continue;
+	      if (!seek_next_seg)
+	        {
+		  ccseg = fde->cseg;
+		  /* Open .eh_frame section.  */
+		  cfi_seg = get_cfi_seg (ccseg, ".eh_frame",
+					 SEC_ALLOC | SEC_LOAD | SEC_DATA
+					 | DWARF2_EH_FRAME_READ_ONLY,
+					 EH_FRAME_ALIGNMENT);
+#ifdef md_fix_up_eh_frame
+		  md_fix_up_eh_frame (cfi_seg);
+#endif
+		}
+	      fde->handled = 1;
+	      seek_next_seg = 1;
+
+	      if (fde->end_address == NULL)
+		{
+		  as_bad (_("open CFI at the end of file; missing .cfi_endproc directive"));
+		  fde->end_address = fde->start_address;
+		}
+
+	      cie = select_cie_for_fde (fde, TRUE, &first, 2);
+	      output_fde (fde, cie, TRUE, first,
+			  fde->next == NULL ? EH_FRAME_ALIGNMENT : 2);
+	    }
 	}
+      while (seek_next_seg != 0);
+
+      for (fde = all_fde_data; fde ; fde = fde->next)
+        fde->handled = 0;
 
       flag_traditional_format = save_flag_traditional_format;
     }
 
   if ((cfi_sections & CFI_EMIT_debug_frame) != 0)
     {
-      struct cie_entry *cie, *cie_next;
       int alignment = ffs (DWARF2_ADDR_SIZE (stdoutput)) - 1;
 
-      for (cie = cie_root; cie; cie = cie_next)
-	{
-	  cie_next = cie->next;
-	  free ((void *) cie);
-	}
-      cie_root = NULL;
-
-      /* Open .debug_frame section.  */
-      cfi_seg = subseg_new (".debug_frame", 0);
-      bfd_set_section_flags (stdoutput, cfi_seg,
-			     SEC_READONLY | SEC_DEBUGGING);
-      subseg_set (cfi_seg, 0);
-      record_alignment (cfi_seg, alignment);
-
-      for (fde = all_fde_data; fde ; fde = fde->next)
-	{
-	  struct cfi_insn_data *first;
-
-	  if (fde->end_address == NULL)
+      do
+        {
+	  ccseg = NULL;
+	  cfi_seg = NULL;
+	  seek_next_seg = 0;
+	  for (cie = cie_root; cie; cie = cie_next)
 	    {
-	      as_bad (_("open CFI at the end of file; missing .cfi_endproc directive"));
-	      fde->end_address = fde->start_address;
+	      cie_next = cie->next;
+	      free ((void *) cie);
 	    }
+	  cie_root = NULL;
 
-	  fde->per_encoding = DW_EH_PE_omit;
-	  fde->lsda_encoding = DW_EH_PE_omit;
-	  cfi_change_reg_numbers (fde->data);
-	  cie = select_cie_for_fde (fde, FALSE, &first, alignment);
-	  output_fde (fde, cie, FALSE, first, alignment);
+	  for (fde = all_fde_data; fde ; fde = fde->next)
+	    {
+	      if (fde->handled != 0)
+	        continue;
+	      if (seek_next_seg && fde->cseg != ccseg)
+	        continue;
+	      if (!seek_next_seg)
+	        {
+		  ccseg = fde->cseg;
+		  /* Open .debug_frame section.  */
+		  cfi_seg = get_cfi_seg (ccseg, ".debug_frame",
+					 SEC_READONLY | SEC_DEBUGGING,
+					 alignment);
+		}
+	      fde->handled = 1;
+	      seek_next_seg = 1;
+	      if (fde->end_address == NULL)
+		{
+		  as_bad (_("open CFI at the end of file; missing .cfi_endproc directive"));
+		  fde->end_address = fde->start_address;
+		}
+
+	      fde->per_encoding = DW_EH_PE_omit;
+	      fde->lsda_encoding = DW_EH_PE_omit;
+	      cfi_change_reg_numbers (fde->data, ccseg);
+	      cie = select_cie_for_fde (fde, FALSE, &first, alignment);
+	      output_fde (fde, cie, FALSE, first, alignment);
+	    }
 	}
+      while (seek_next_seg != 0);
+
+      for (fde = all_fde_data; fde ; fde = fde->next)
+        fde->handled = 0;
     }
 }
 
Index: src/gas/ehopt.c
===================================================================
--- src.orig/gas/ehopt.c	2011-04-16 12:06:37.754473700 +0200
+++ src/gas/ehopt.c	2011-04-16 12:09:55.252923900 +0200
@@ -120,7 +120,7 @@ get_cie_info (struct cie_info *info)
 
   /* First make sure that the CIE Identifier Tag is 0/-1.  */
 
-  if (strcmp (segment_name (now_seg), ".debug_frame") == 0)
+  if (strncmp (segment_name (now_seg), ".debug_frame", 12) == 0)
     CIE_id = (char)0xff;
   else
     CIE_id = 0;
@@ -285,9 +285,9 @@ check_eh_frame (expressionS *exp, unsign
 #endif
 
   /* Select the proper section data.  */
-  if (strcmp (segment_name (now_seg), ".eh_frame") == 0)
+  if (strncmp (segment_name (now_seg), ".eh_frame", 9) == 0)
     d = &eh_frame_data;
-  else if (strcmp (segment_name (now_seg), ".debug_frame") == 0)
+  else if (strncmp (segment_name (now_seg), ".debug_frame", 12) == 0)
     d = &debug_frame_data;
   else
     return 0;
Index: src/ld/scripttempl/alphavms.sc
===================================================================
--- src.orig/ld/scripttempl/alphavms.sc	2011-04-16 12:06:37.771473700 +0200
+++ src/ld/scripttempl/alphavms.sc	2011-04-16 12:09:55.254924000 +0200
@@ -29,7 +29,7 @@ SECTIONS
     *(\$LITERAL\$)
     *(\$READONLY\$)
     *(\$READONLY_ADDR\$)
-    *(eh_frame)
+    *(eh_frame) *(eh_frame\$*) *(eh_frame.*)
     *(jcr)
     *(ctors)
     *(dtors)
Index: src/ld/scripttempl/armbpabi.sc
===================================================================
--- src.orig/ld/scripttempl/armbpabi.sc	2011-04-16 12:06:37.784473700 +0200
+++ src/ld/scripttempl/armbpabi.sc	2011-04-16 12:09:55.257924200 +0200
@@ -241,7 +241,7 @@ cat <<EOF
 
   ${OTHER_READONLY_SECTIONS}
   .eh_frame_hdr : { *(.eh_frame_hdr) }
-  .eh_frame     ${RELOCATING-0} : ONLY_IF_RO { KEEP (*(.eh_frame)) }
+  .eh_frame     ${RELOCATING-0} : ONLY_IF_RO { KEEP (*(.eh_frame) *(.eh_frame\$*) *(.eh_frame.*)) }
   .gcc_except_table ${RELOCATING-0} : ONLY_IF_RO { KEEP (*(.gcc_except_table)) *(.gcc_except_table.*) }
 
   /* Adjust the address for the data segment.  We want to adjust up to
@@ -251,7 +251,7 @@ cat <<EOF
   ${CREATE_PIE+${RELOCATING+. = ${SHLIB_DATA_ADDR};}}
 
   /* Exception handling  */
-  .eh_frame     ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.eh_frame)) }
+  .eh_frame     ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.eh_frame) *(.eh_frame\$*) *(.eh_frame.*)) }
   .gcc_except_table ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.gcc_except_table)) *(.gcc_except_table.*) }
 
   /* Thread Local Storage sections  */
@@ -346,7 +346,7 @@ cat <<EOF
   .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }
   .debug_abbrev   0 : { *(.debug_abbrev) }
   .debug_line     0 : { *(.debug_line) }
-  .debug_frame    0 : { *(.debug_frame) }
+  .debug_frame    0 : { *(.debug_frame*) }
   .debug_str      0 : { *(.debug_str) }
   .debug_loc      0 : { *(.debug_loc) }
   .debug_macinfo  0 : { *(.debug_macinfo) }
Index: src/ld/scripttempl/avr.sc
===================================================================
--- src.orig/ld/scripttempl/avr.sc	2011-04-16 12:06:37.786473700 +0200
+++ src/ld/scripttempl/avr.sc	2011-04-16 12:09:55.259924300 +0200
@@ -246,7 +246,7 @@ SECTIONS
   .debug_info     0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }
   .debug_abbrev   0 : { *(.debug_abbrev) }
   .debug_line     0 : { *(.debug_line) }
-  .debug_frame    0 : { *(.debug_frame) }
+  .debug_frame    0 : { *(.debug_frame*) }
   .debug_str      0 : { *(.debug_str) }
   .debug_loc      0 : { *(.debug_loc) }
   .debug_macinfo  0 : { *(.debug_macinfo) }
Index: src/ld/scripttempl/crisaout.sc
===================================================================
--- src.orig/ld/scripttempl/crisaout.sc	2011-04-16 12:06:37.796473700 +0200
+++ src/ld/scripttempl/crisaout.sc	2011-04-16 12:09:55.261924400 +0200
@@ -90,7 +90,7 @@ SECTIONS
     *(.data);
     ${RELOCATING+*(.data.*)}
     ${RELOCATING+*(.gnu.linkonce.d*)}
-    ${RELOCATING+*(.eh_frame) /* FIXME: Make .text */}
+    ${RELOCATING+*(.eh_frame) *(.eh_frame\$*) *(.eh_frame.*) /* FIXME: Make .text */}
     ${RELOCATING+*(.gcc_except_table)}
 
     /* See comment at ALIGN before __Etext.  */
Index: src/ld/scripttempl/elf32cr16.sc
===================================================================
--- src.orig/ld/scripttempl/elf32cr16.sc	2011-04-16 12:06:37.814473700 +0200
+++ src/ld/scripttempl/elf32cr16.sc	2011-04-16 12:09:55.264924600 +0200
@@ -159,7 +159,7 @@ SECTIONS
   .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }
   .debug_abbrev   0 : { *(.debug_abbrev) }
   .debug_line     0 : { *(.debug_line) }
-  .debug_frame    0 : { *(.debug_frame) }
+  .debug_frame    0 : { *(.debug_frame*) }
   .debug_str      0 : { *(.debug_str) }
   .debug_loc      0 : { *(.debug_loc) }
   .debug_macinfo  0 : { *(.debug_macinfo) }
Index: src/ld/scripttempl/elf32crx.sc
===================================================================
--- src.orig/ld/scripttempl/elf32crx.sc	2011-04-16 12:06:37.821473700 +0200
+++ src/ld/scripttempl/elf32crx.sc	2011-04-16 12:09:55.266924700 +0200
@@ -161,7 +161,7 @@ SECTIONS
   .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }
   .debug_abbrev   0 : { *(.debug_abbrev) }
   .debug_line     0 : { *(.debug_line) }
-  .debug_frame    0 : { *(.debug_frame) }
+  .debug_frame    0 : { *(.debug_frame*) }
   .debug_str      0 : { *(.debug_str) }
   .debug_loc      0 : { *(.debug_loc) }
   .debug_macinfo  0 : { *(.debug_macinfo) }
Index: src/ld/scripttempl/elf32msp430.sc
===================================================================
--- src.orig/ld/scripttempl/elf32msp430.sc	2011-04-16 12:06:37.824473700 +0200
+++ src/ld/scripttempl/elf32msp430.sc	2011-04-16 12:09:55.268924800 +0200
@@ -234,7 +234,7 @@ SECTIONS
   .debug_info     0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }
   .debug_abbrev   0 : { *(.debug_abbrev) }
   .debug_line     0 : { *(.debug_line) }
-  .debug_frame    0 : { *(.debug_frame) }
+  .debug_frame    0 : { *(.debug_frame*) }
   .debug_str      0 : { *(.debug_str) }
   .debug_loc      0 : { *(.debug_loc) }
   .debug_macinfo  0 : { *(.debug_macinfo) }
Index: src/ld/scripttempl/elf32msp430_3.sc
===================================================================
--- src.orig/ld/scripttempl/elf32msp430_3.sc	2011-04-16 12:06:37.836473700 +0200
+++ src/ld/scripttempl/elf32msp430_3.sc	2011-04-16 12:09:55.270924900 +0200
@@ -178,7 +178,7 @@ SECTIONS
   .debug_info     0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }
   .debug_abbrev   0 : { *(.debug_abbrev) }
   .debug_line     0 : { *(.debug_line) }
-  .debug_frame    0 : { *(.debug_frame) }
+  .debug_frame    0 : { *(.debug_frame*) }
   .debug_str      0 : { *(.debug_str) }
   .debug_loc      0 : { *(.debug_loc) }
   .debug_macinfo  0 : { *(.debug_macinfo) }
Index: src/ld/scripttempl/elf32sh-symbian.sc
===================================================================
--- src.orig/ld/scripttempl/elf32sh-symbian.sc	2011-04-16 12:06:37.844473700 +0200
+++ src/ld/scripttempl/elf32sh-symbian.sc	2011-04-16 12:09:55.272925000 +0200
@@ -245,7 +245,7 @@ SECTIONS
   .data1            ALIGN(4) : { *(.data1) } :data
   .tdata	    ALIGN(4) : { *(.tdata${RELOCATING+ .tdata.* .gnu.linkonce.td.*}) } :data
   .tbss		    ALIGN(4) : { *(.tbss${RELOCATING+ .tbss.* .gnu.linkonce.tb.*})${RELOCATING+ *(.tcommon)} } :data
-  .eh_frame         ALIGN(4) : { KEEP (*(.eh_frame)) } :data
+  .eh_frame         ALIGN(4) : { KEEP (*(.eh_frame) *(.eh_frame\$*) *(.eh_frame.*)) } :data
   .gcc_except_table ALIGN(4) : { *(.gcc_except_table) } :data
   ${WRITABLE_RODATA+${RODATA}}
   ${OTHER_READWRITE_SECTIONS}
@@ -367,7 +367,7 @@ cat <<EOF
   .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }
   .debug_abbrev   0 : { *(.debug_abbrev) }
   .debug_line     0 : { *(.debug_line) }
-  .debug_frame    0 : { *(.debug_frame) }
+  .debug_frame    0 : { *(.debug_frame*) }
   .debug_str      0 : { *(.debug_str) }
   .debug_loc      0 : { *(.debug_loc) }
   .debug_macinfo  0 : { *(.debug_macinfo) }
Index: src/ld/scripttempl/elf64hppa.sc
===================================================================
--- src.orig/ld/scripttempl/elf64hppa.sc	2011-04-16 12:06:37.851473700 +0200
+++ src/ld/scripttempl/elf64hppa.sc	2011-04-16 12:09:55.275925200 +0200
@@ -420,7 +420,7 @@ cat <<EOF
   ${CREATE_SHLIB-${SBSS2}}
   ${OTHER_READONLY_SECTIONS}
   .eh_frame_hdr : { *(.eh_frame_hdr) }
-  .eh_frame     ${RELOCATING-0} : ONLY_IF_RO { KEEP (*(.eh_frame)) }
+  .eh_frame     ${RELOCATING-0} : ONLY_IF_RO { KEEP (*(.eh_frame) *(.eh_frame\$*) *(.eh_frame.*)) }
   .gcc_except_table ${RELOCATING-0} : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
 
   /* Adjust the address for the data segment.  We want to adjust up to
@@ -430,7 +430,7 @@ cat <<EOF
   ${CREATE_PIE+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
 
   /* Exception handling  */
-  .eh_frame     ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.eh_frame)) }
+  .eh_frame     ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.eh_frame) *(.eh_frame\$*) *(.eh_frame.*)) }
   .gcc_except_table ${RELOCATING-0} : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
 
   /* Thread Local Storage sections  */
@@ -549,7 +549,7 @@ cat <<EOF
   .debug_info     0 : { *(.debug_info${RELOCATING+ .gnu.linkonce.wi.*}) }
   .debug_abbrev   0 : { *(.debug_abbrev) }
   .debug_line     0 : { *(.debug_line) }
-  .debug_frame    0 : { *(.debug_frame) }
+  .debug_frame    0 : { *(.debug_frame*) }
   .debug_str      0 : { *(.debug_str) }
   .debug_loc      0 : { *(.debug_loc) }
   .debug_macinfo  0 : { *(.debug_macinfo) }
Index: src/ld/scripttempl/elf_chaos.sc
===================================================================
--- src.orig/ld/scripttempl/elf_chaos.sc	2011-04-16 12:06:37.945473700 +0200
+++ src/ld/scripttempl/elf_chaos.sc	2011-04-16 12:09:55.277925300 +0200
@@ -264,7 +264,7 @@ cat <<EOF
     ${RELOCATING+${DATA_START_SYMBOLS}}
     *(.data${RELOCATING+ .data.* .gnu.linkonce.d.*})
     ${CONSTRUCTING+SORT(CONSTRUCTORS)}
-    KEEP (*(.eh_frame))
+    KEEP (*(.eh_frame) *(.eh_frame\$*) *(.eh_frame.*))
     *(.gcc_except_table)
     ${CTOR}
     ${DTOR}
@@ -339,7 +339,7 @@ cat <<EOF
   .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }
   .debug_abbrev   0 : { *(.debug_abbrev) }
   .debug_line     0 : { *(.debug_line) }
-  .debug_frame    0 : { *(.debug_frame) }
+  .debug_frame    0 : { *(.debug_frame*) }
   .debug_str      0 : { *(.debug_str) }
   .debug_loc      0 : { *(.debug_loc) }
   .debug_macinfo  0 : { *(.debug_macinfo) }
Index: src/ld/scripttempl/elfd10v.sc
===================================================================
--- src.orig/ld/scripttempl/elfd10v.sc	2011-04-16 12:06:37.863473700 +0200
+++ src/ld/scripttempl/elfd10v.sc	2011-04-16 12:09:55.279925400 +0200
@@ -184,7 +184,7 @@ SECTIONS
   .debug_info     0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }
   .debug_abbrev   0 : { *(.debug_abbrev) }
   .debug_line     0 : { *(.debug_line) }
-  .debug_frame    0 : { *(.debug_frame) }
+  .debug_frame    0 : { *(.debug_frame*) }
   .debug_str      0 : { *(.debug_str) }
   .debug_loc      0 : { *(.debug_loc) }
   .debug_macinfo  0 : { *(.debug_macinfo) }
Index: src/ld/scripttempl/elfd30v.sc
===================================================================
--- src.orig/ld/scripttempl/elfd30v.sc	2011-04-16 12:06:37.878473700 +0200
+++ src/ld/scripttempl/elfd30v.sc	2011-04-16 12:09:55.281925600 +0200
@@ -123,7 +123,7 @@ SECTIONS
   .rodata	${RELOCATING-0} : { *(.rodata) }	${RELOCATING+ > ${DATA_MEMORY}}
 
   /* C++ exception support.  */
-  .eh_frame	${RELOCATING-0} : { KEEP (*(.eh_frame)) }	${RELOCATING+ > ${DATA_MEMORY}}
+  .eh_frame	${RELOCATING-0} : { KEEP (*(.eh_frame) *(.eh_frame\$*) *(.eh_frame.*)) }	${RELOCATING+ > ${DATA_MEMORY}}
   .gcc_except_table ${RELOCATING-0} : { *(.gcc_except_table) }	${RELOCATING+ > ${DATA_MEMORY}}
 
   /* Java class registration support.  */
@@ -211,7 +211,7 @@ SECTIONS
   .debug_info     0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }
   .debug_abbrev   0 : { *(.debug_abbrev) }
   .debug_line     0 : { *(.debug_line) }
-  .debug_frame    0 : { *(.debug_frame) }
+  .debug_frame    0 : { *(.debug_frame*) }
   .debug_str      0 : { *(.debug_str) }
   .debug_loc      0 : { *(.debug_loc) }
   .debug_macinfo  0 : { *(.debug_macinfo) }
Index: src/ld/scripttempl/elfi370.sc
===================================================================
--- src.orig/ld/scripttempl/elfi370.sc	2011-04-16 12:06:37.886473700 +0200
+++ src/ld/scripttempl/elfi370.sc	2011-04-16 12:09:55.284925700 +0200
@@ -203,7 +203,7 @@ SECTIONS
   .debug_info     0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }
   .debug_abbrev   0 : { *(.debug_abbrev) }
   .debug_line     0 : { *(.debug_line) }
-  .debug_frame    0 : { *(.debug_frame) }
+  .debug_frame    0 : { *(.debug_frame*) }
   .debug_str      0 : { *(.debug_str) }
   .debug_loc      0 : { *(.debug_loc) }
   .debug_macinfo  0 : { *(.debug_macinfo) }
Index: src/ld/scripttempl/elfm68hc11.sc
===================================================================
--- src.orig/ld/scripttempl/elfm68hc11.sc	2011-04-16 12:06:37.898473700 +0200
+++ src/ld/scripttempl/elfm68hc11.sc	2011-04-16 12:09:55.286925800 +0200
@@ -325,7 +325,7 @@ SECTIONS
 
   .eh_frame ${RELOCATING-0} :
   {
-    KEEP (*(.eh_frame))
+    KEEP (*(.eh_frame) *(.eh_frame\$*) *(.eh_frame.*))
   } ${RELOCATING+ > ${TEXT_MEMORY}}
 
   .gcc_except_table ${RELOCATING-0} :
@@ -452,7 +452,7 @@ SECTIONS
   .debug_info     0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }
   .debug_abbrev   0 : { *(.debug_abbrev) }
   .debug_line     0 : { *(.debug_line) }
-  .debug_frame    0 : { *(.debug_frame) }
+  .debug_frame    0 : { *(.debug_frame*) }
   .debug_str      0 : { *(.debug_str) }
   .debug_loc      0 : { *(.debug_loc) }
   .debug_macinfo  0 : { *(.debug_macinfo) }
Index: src/ld/scripttempl/elfm68hc12.sc
===================================================================
--- src.orig/ld/scripttempl/elfm68hc12.sc	2011-04-16 12:06:37.905473700 +0200
+++ src/ld/scripttempl/elfm68hc12.sc	2011-04-16 12:09:55.288926000 +0200
@@ -324,7 +324,7 @@ SECTIONS
 
   .eh_frame ${RELOCATING-0} :
   {
-    KEEP (*(.eh_frame))
+    KEEP (*(.eh_frame) *(.eh_frame\$*) *(.eh_frame.*))
   } ${RELOCATING+ > ${TEXT_MEMORY}}
 
   .gcc_except_table ${RELOCATING-0} :
@@ -455,7 +455,7 @@ SECTIONS
   .debug_info     0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }
   .debug_abbrev   0 : { *(.debug_abbrev) }
   .debug_line     0 : { *(.debug_line) }
-  .debug_frame    0 : { *(.debug_frame) }
+  .debug_frame    0 : { *(.debug_frame*) }
   .debug_str      0 : { *(.debug_str) }
   .debug_loc      0 : { *(.debug_loc) }
   .debug_macinfo  0 : { *(.debug_macinfo) }
Index: src/ld/scripttempl/elfmicroblaze.sc
===================================================================
--- src.orig/ld/scripttempl/elfmicroblaze.sc	2011-04-16 12:06:37.918473700 +0200
+++ src/ld/scripttempl/elfmicroblaze.sc	2011-04-16 12:09:55.290926100 +0200
@@ -142,7 +142,7 @@ SECTIONS
 
   /* Added by Sathya to handle C++ exceptions */
   .eh_frame : {  
-    ${RELOCATING+*(.eh_frame)}
+    ${RELOCATING+*(.eh_frame) *(.eh_frame\$*) *(.eh_frame.*)}
   }
   
   .jcr : {  
Index: src/ld/scripttempl/elfxtensa.sc
===================================================================
--- src.orig/ld/scripttempl/elfxtensa.sc	2011-04-16 12:06:37.935473700 +0200
+++ src/ld/scripttempl/elfxtensa.sc	2011-04-16 12:09:55.293926200 +0200
@@ -429,7 +429,7 @@ cat <<EOF
   ${CREATE_SHLIB-${SBSS2}}
   ${OTHER_READONLY_SECTIONS}
   .eh_frame_hdr : { *(.eh_frame_hdr) }
-  .eh_frame     ${RELOCATING-0} : ONLY_IF_RO { KEEP (*(.eh_frame)) }
+  .eh_frame     ${RELOCATING-0} : ONLY_IF_RO { KEEP (*(.eh_frame) *(.eh_frame\$*) *(.eh_frame.*)) }
   .gcc_except_table ${RELOCATING-0} : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
 
   /* Adjust the address for the data segment.  We want to adjust up to
@@ -439,7 +439,7 @@ cat <<EOF
   ${CREATE_PIE+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
 
   /* Exception handling  */
-  .eh_frame     ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.eh_frame)) }
+  .eh_frame     ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.eh_frame) *(.eh_frame\$*) *(.eh_frame.*)) }
   .gcc_except_table ${RELOCATING-0} : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
 
   /* Thread Local Storage sections  */
@@ -559,7 +559,7 @@ cat <<EOF
   .debug_info     0 : { *(.debug_info${RELOCATING+ .gnu.linkonce.wi.*}) }
   .debug_abbrev   0 : { *(.debug_abbrev) }
   .debug_line     0 : { *(.debug_line) }
-  .debug_frame    0 : { *(.debug_frame) }
+  .debug_frame    0 : { *(.debug_frame*) }
   .debug_str      0 : { *(.debug_str) }
   .debug_loc      0 : { *(.debug_loc) }
   .debug_macinfo  0 : { *(.debug_macinfo) }
Index: src/ld/scripttempl/epocpe.sc
===================================================================
--- src.orig/ld/scripttempl/epocpe.sc	2011-04-16 12:06:37.957473700 +0200
+++ src/ld/scripttempl/epocpe.sc	2011-04-16 12:09:55.295926400 +0200
@@ -67,7 +67,7 @@ SECTIONS
     section */
     *(.rdata)
     ${R_RDATA}
-    *(.eh_frame)
+    *(.eh_frame) *(.eh_frame\$*) *(.eh_frame.*)
   }
 
   /* The Cygwin32 library uses a section to avoid copying certain data
Index: src/ld/scripttempl/i386beos.sc
===================================================================
--- src.orig/ld/scripttempl/i386beos.sc	2011-04-16 12:06:37.965473700 +0200
+++ src/ld/scripttempl/i386beos.sc	2011-04-16 12:09:55.297926500 +0200
@@ -98,7 +98,7 @@ SECTIONS
   {
     *(.rdata)
     ${R_RDATA}
-    *(.eh_frame)
+    *(.eh_frame) *(.eh_frame\$*) *(.eh_frame.*)
   }
 
   .edata ${RELOCATING+BLOCK(__section_alignment__)} :
@@ -180,7 +180,7 @@ SECTIONS
   .debug_info     0 ${RELOCATING+(NOLOAD)} : { *(.debug_info) *(.gnu.linkonce.wi.*) }
   .debug_abbrev   0 ${RELOCATING+(NOLOAD)} : { *(.debug_abbrev) }
   .debug_line     0 ${RELOCATING+(NOLOAD)} : { *(.debug_line) }
-  .debug_frame    0 ${RELOCATING+(NOLOAD)} : { *(.debug_frame) }
+  .debug_frame    0 ${RELOCATING+(NOLOAD)} : { *(.debug_frame*) }
   .debug_str      0 ${RELOCATING+(NOLOAD)} : { *(.debug_str) }
   .debug_loc      0 ${RELOCATING+(NOLOAD)} : { *(.debug_loc) }
   .debug_macinfo  0 ${RELOCATING+(NOLOAD)} : { *(.debug_macinfo) }
Index: src/ld/scripttempl/i386go32.sc
===================================================================
--- src.orig/ld/scripttempl/i386go32.sc	2011-04-16 12:06:37.974473700 +0200
+++ src/ld/scripttempl/i386go32.sc	2011-04-16 12:09:55.299926600 +0200
@@ -71,7 +71,7 @@ SECTIONS
   .debug_info     0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }
   .debug_abbrev   0 : { *(.debug_abbrev) }
   .debug_line     0 : { *(.debug_line) }
-  .debug_frame    0 : { *(.debug_frame) }
+  .debug_frame    0 : { *(.debug_frame*) }
   .debug_str      0 : { *(.debug_str) }
   .debug_loc      0 : { *(.debug_loc) }
   .debug_macinfo  0 : { *(.debug_macinfo) }
Index: src/ld/scripttempl/ip2k.sc
===================================================================
--- src.orig/ld/scripttempl/ip2k.sc	2011-04-16 12:06:37.989473700 +0200
+++ src/ld/scripttempl/ip2k.sc	2011-04-16 12:09:55.301926700 +0200
@@ -142,7 +142,7 @@ SECTIONS
 	.debug_info     0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }
 	.debug_abbrev   0 : { *(.debug_abbrev) }
 	.debug_line     0 : { *(.debug_line) }
-	.debug_frame    0 : { *(.debug_frame) }
+	.debug_frame    0 : { *(.debug_frame*) }
 	.debug_str      0 : { *(.debug_str) }
 	.debug_loc      0 : { *(.debug_loc) }
 	.debug_macinfo  0 : { *(.debug_macinfo) }
Index: src/ld/scripttempl/iq2000.sc
===================================================================
--- src.orig/ld/scripttempl/iq2000.sc	2011-04-16 12:06:38.001473700 +0200
+++ src/ld/scripttempl/iq2000.sc	2011-04-16 12:09:55.303926800 +0200
@@ -321,7 +321,7 @@ cat <<EOF
   .eh_frame ${RELOCATING-0} : 
   { 
     ${RELOCATING+PROVIDE (__eh_frame_begin = .);}
-    *(.eh_frame) 
+    *(.eh_frame) *(.eh_frame\$*) *(.eh_frame.*)
     LONG (0);
     ${RELOCATING+PROVIDE (__eh_frame_end = .);}
   } ${RELOCATING+}
@@ -425,7 +425,7 @@ cat <<EOF
   .debug_info     0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }
   .debug_abbrev   0 : { *(.debug_abbrev) }
   .debug_line     0 : { *(.debug_line) }
-  .debug_frame    0 : { *(.debug_frame) }
+  .debug_frame    0 : { *(.debug_frame*) }
   .debug_str      0 : { *(.debug_str) }
   .debug_loc      0 : { *(.debug_loc) }
   .debug_macinfo  0 : { *(.debug_macinfo) }
Index: src/ld/scripttempl/mcorepe.sc
===================================================================
--- src.orig/ld/scripttempl/mcorepe.sc	2011-04-16 12:06:38.016473700 +0200
+++ src/ld/scripttempl/mcorepe.sc	2011-04-16 12:09:55.306927000 +0200
@@ -98,7 +98,7 @@ SECTIONS
   {
     *(.rdata)
     ${R_RDATA}
-    *(.eh_frame)
+    *(.eh_frame) *(.eh_frame\$*) *(.eh_frame.*)
   }
 
   .edata ${RELOCATING+BLOCK(__section_alignment__)} :
Index: src/ld/scripttempl/mep.sc
===================================================================
--- src.orig/ld/scripttempl/mep.sc	2011-04-16 12:06:38.019473700 +0200
+++ src/ld/scripttempl/mep.sc	2011-04-16 12:09:55.308927100 +0200
@@ -319,7 +319,7 @@ cat <<EOF
   ${CREATE_SHLIB-${SBSS2}}
   ${OTHER_READONLY_SECTIONS}
   .eh_frame_hdr : { *(.eh_frame_hdr) }
-  .eh_frame     ${RELOCATING-0} : ONLY_IF_RO { KEEP (*(.eh_frame)) }
+  .eh_frame     ${RELOCATING-0} : ONLY_IF_RO { KEEP (*(.eh_frame) *(.eh_frame\$*) *(.eh_frame.*)) }
   .gcc_except_table ${RELOCATING-0} : ONLY_IF_RO { KEEP (*(.gcc_except_table)) *(.gcc_except_table.*) }
 
   /* Adjust the address for the data segment.  We want to adjust up to
@@ -329,7 +329,7 @@ cat <<EOF
   ${CREATE_PIE+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
 
   /* Exception handling  */
-  .eh_frame     ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.eh_frame)) }
+  .eh_frame     ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.eh_frame) *(.eh_frame\$*) *(.eh_frame.*)) }
   .gcc_except_table ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.gcc_except_table)) *(.gcc_except_table.*) }
 
   /* Thread Local Storage sections  */
@@ -425,7 +425,7 @@ cat <<EOF
   .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }
   .debug_abbrev   0 : { *(.debug_abbrev) }
   .debug_line     0 : { *(.debug_line) }
-  .debug_frame    0 : { *(.debug_frame) }
+  .debug_frame    0 : { *(.debug_frame*) }
   .debug_str      0 : { *(.debug_str) }
   .debug_loc      0 : { *(.debug_loc) }
   .debug_macinfo  0 : { *(.debug_macinfo) }
Index: src/ld/scripttempl/mmo.sc
===================================================================
--- src.orig/ld/scripttempl/mmo.sc	2011-04-16 12:06:38.033473700 +0200
+++ src/ld/scripttempl/mmo.sc	2011-04-16 12:09:55.311927300 +0200
@@ -54,7 +54,7 @@ SECTIONS
     ${RELOCATING+ PROVIDE (__dtors_end = .);}
 
     ${RELOCATING+KEEP (*(.jcr))}
-    ${RELOCATING+KEEP (*(.eh_frame))}
+    ${RELOCATING+KEEP (*(.eh_frame) *(.eh_frame\$*) *(.eh_frame.*))}
     ${RELOCATING+*(.gcc_except_table)}
 
     ${RELOCATING+ PROVIDE(etext = .);}
@@ -74,7 +74,7 @@ SECTIONS
   .debug_info     0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }
   .debug_abbrev   0 : { *(.debug_abbrev) }
   .debug_line     0 : { *(.debug_line) }
-  .debug_frame    0 : { *(.debug_frame) }
+  .debug_frame    0 : { *(.debug_frame*) }
   .debug_str      0 : { *(.debug_str) }
   .debug_loc      0 : { *(.debug_loc) }
   .debug_macinfo  0 : { *(.debug_macinfo) }
Index: src/ld/scripttempl/pe.sc
===================================================================
--- src.orig/ld/scripttempl/pe.sc	2011-04-16 12:06:38.047473700 +0200
+++ src/ld/scripttempl/pe.sc	2011-04-16 12:09:55.313927400 +0200
@@ -115,7 +115,7 @@ SECTIONS
 
   .eh_frame ${RELOCATING+BLOCK(__section_alignment__)} :
   {
-    *(.eh_frame)
+    *(.eh_frame) *(.eh_frame\$*) *(.eh_frame.*)
   }
 
   .pdata ${RELOCATING+BLOCK(__section_alignment__)} :
@@ -250,7 +250,7 @@ SECTIONS
 
   .debug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
   {
-    *(.debug_frame)
+    *(.debug_frame*)
   }
 
   .debug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
Index: src/ld/scripttempl/pep.sc
===================================================================
--- src.orig/ld/scripttempl/pep.sc	2011-04-16 12:06:38.055473700 +0200
+++ src/ld/scripttempl/pep.sc	2011-04-16 12:09:55.316927600 +0200
@@ -116,7 +116,7 @@ SECTIONS
 
   .eh_frame ${RELOCATING+BLOCK(__section_alignment__)} :
   {
-    *(.eh_frame)
+    *(.eh_frame*)
   }
 
   .pdata ${RELOCATING+BLOCK(__section_alignment__)} :
@@ -256,7 +256,7 @@ SECTIONS
 
   .debug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
   {
-    *(.debug_frame)
+    *(.debug_frame*)
   }
 
   .debug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
@@ -271,40 +271,40 @@ SECTIONS
 
   .debug_macinfo ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
   {
-    *(.debug_macinfo)
+    *(.debug_macinfo*)
   }
 
   /* SGI/MIPS DWARF 2 extensions.  */
   .debug_weaknames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
   {
-    *(.debug_weaknames)
+    *(.debug_weaknames*)
   }
 
   .debug_funcnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
   {
-    *(.debug_funcnames)
+    *(.debug_funcnames*)
   }
 
   .debug_typenames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
   {
-    *(.debug_typenames)
+    *(.debug_typenames*)
   }
 
   .debug_varnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
   {
-    *(.debug_varnames)
+    *(.debug_varnames*)
   }
 
   /* DWARF 3.  */
   .debug_ranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
   {
-    *(.debug_ranges)
+    *(.debug_ranges*)
   }
 
   /* DWARF 4.  */
   .debug_types ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
   {
-    *(.debug_types) *(.gnu.linkonce.wt.*)
+    *(.debug_types*) *(.gnu.linkonce.wt.*)
   }
 }
 EOF
Index: src/ld/scripttempl/v850.sc
===================================================================
--- src.orig/ld/scripttempl/v850.sc	2011-04-16 12:06:38.058473700 +0200
+++ src/ld/scripttempl/v850.sc	2011-04-16 12:09:55.318927700 +0200
@@ -210,7 +210,7 @@ SECTIONS
   .debug_info     0	: { *(.debug_info) *(.gnu.linkonce.wi.*) }
   .debug_abbrev   0	: { *(.debug_abbrev) }
   .debug_line     0	: { *(.debug_line) }
-  .debug_frame    0	: { *(.debug_frame) }
+  .debug_frame    0	: { *(.debug_frame*) }
   .debug_str      0	: { *(.debug_str) }
   .debug_loc      0	: { *(.debug_loc) }
   .debug_macinfo  0	: { *(.debug_macinfo) }
Index: src/ld/scripttempl/xstormy16.sc
===================================================================
--- src.orig/ld/scripttempl/xstormy16.sc	2011-04-16 12:06:38.112473700 +0200
+++ src/ld/scripttempl/xstormy16.sc	2011-04-16 12:09:55.321927800 +0200
@@ -159,7 +159,7 @@ SECTIONS
   ${RELOCATING+${CTOR}}
   ${RELOCATING+${DTOR}}
   .jcr : { KEEP (*(.jcr)) } ${RELOCATING+> ROM}
-  .eh_frame : { KEEP (*(.eh_frame)) } ${RELOCATING+> ROM}
+  .eh_frame : { KEEP (*(.eh_frame) *(.eh_frame\$*) *(.eh_frame.*)) } ${RELOCATING+> ROM}
   .gcc_except_table : { *(.gcc_except_table) *(.gcc_except_table.*) } ${RELOCATING+> ROM}
   .plt : { *(.plt) } ${RELOCATING+> ROM}
 
@@ -222,7 +222,7 @@ SECTIONS
   .debug_info     0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }
   .debug_abbrev   0 : { *(.debug_abbrev) }
   .debug_line     0 : { *(.debug_line) }
-  .debug_frame    0 : { *(.debug_frame) }
+  .debug_frame    0 : { *(.debug_frame*) }
   .debug_str      0 : { *(.debug_str) }
   .debug_loc      0 : { *(.debug_loc) }
   .debug_macinfo  0 : { *(.debug_macinfo) }
Index: src/bfd/coffcode.h
===================================================================
--- src.orig/bfd/coffcode.h	2011-04-16 12:06:37.720473700 +0200
+++ src/bfd/coffcode.h	2011-04-17 10:45:28.910093500 +0200
@@ -658,7 +658,10 @@ sec_to_styp_flags (const char *sec_name,
 
   /* FIXME: There is no gas syntax to specify the debug section flag.  */
   if (is_dbg)
-      sec_flags = SEC_DEBUGGING | SEC_READONLY;
+    {
+      sec_flags &= (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD);
+      sec_flags |= SEC_DEBUGGING | SEC_READONLY;
+    }
 
   /* skip LOAD */
   /* READONLY later */
Index: src/ld/scripttempl/elf.sc
===================================================================
--- src.orig/ld/scripttempl/elf.sc	2011-04-16 12:06:37.798473700 +0200
+++ src/ld/scripttempl/elf.sc	2011-04-16 12:09:55.328928200 +0200
@@ -469,7 +469,7 @@ cat <<EOF
   ${CREATE_SHLIB-${SBSS2}}
   ${OTHER_READONLY_SECTIONS}
   .eh_frame_hdr : { *(.eh_frame_hdr) }
-  .eh_frame     ${RELOCATING-0} : ONLY_IF_RO { KEEP (*(.eh_frame)) }
+  .eh_frame     ${RELOCATING-0} : ONLY_IF_RO { KEEP (*(.eh_frame) *(.eh_frame\$*) *(.eh_frame.*)) }
   .gcc_except_table ${RELOCATING-0} : ONLY_IF_RO { *(.gcc_except_table
   .gcc_except_table.*) }
   /* These sections are generated by the Sun/Oracle C++ compiler.  */
@@ -483,7 +483,7 @@ cat <<EOF
   ${CREATE_PIE+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
 
   /* Exception handling  */
-  .eh_frame     ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.eh_frame)) }
+  .eh_frame     ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.eh_frame) *(.eh_frame\$*) *(.eh_frame.*)) }
   .gcc_except_table ${RELOCATING-0} : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
   .exception_ranges ${RELOCATING-0} : ONLY_IF_RW { *(.exception_ranges .exception_ranges*) }
 
@@ -604,7 +604,7 @@ cat <<EOF
   .debug_info     0 : { *(.debug_info${RELOCATING+ .gnu.linkonce.wi.*}) }
   .debug_abbrev   0 : { *(.debug_abbrev) }
   .debug_line     0 : { *(.debug_line) }
-  .debug_frame    0 : { *(.debug_frame) }
+  .debug_frame    0 : { *(.debug_frame*) }
   .debug_str      0 : { *(.debug_str) }
   .debug_loc      0 : { *(.debug_loc) }
   .debug_macinfo  0 : { *(.debug_macinfo) }

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [patch ld bfd gas]: Handle linkonce for cfi generated debug_frame and eh_frame data
  2011-04-18  9:34 [patch ld bfd gas]: Handle linkonce for cfi generated debug_frame and eh_frame data Kai Tietz
@ 2011-04-18 12:43 ` H.J. Lu
  2011-04-18 20:04   ` Kai Tietz
  0 siblings, 1 reply; 12+ messages in thread
From: H.J. Lu @ 2011-04-18 12:43 UTC (permalink / raw)
  To: Kai Tietz; +Cc: Binutils, Alan Modra, Nick Clifton

On Mon, Apr 18, 2011 at 2:33 AM, Kai Tietz <ktietz70@googlemail.com> wrote:
> Hello,
>
> The recent patch about this subject I withdraw and replace it by the
> more enhanced version.  I noticed that a bit more checkings and a
> different approach on writing eh_frame/debug_frame sections out, was
> necessary.  Additionally this patch allows for PE-COFF targets, that
> debugging sections can have link-once flags active.
>
>
> ChangeLog bfd/
>
> 2011-04-18  Kai Tietz
>
>        * coffcode.h (sec_to_styp_flags): Allow linkonce for
>        debugging sections.
>
> ChangeLog gas/
>
> 2011-04-18  Kai Tietz
>
>       * dw2gencfi.c (dwcfi_seg_list): New struct.
>       (dwcfi_hash): New static hash variable.
>       (get_debugseg_name): New.
>       (alloc_debugseg_item): New.
>       (make_debug_seg): New.
>       (dwcfi_hash_insert): New.
>       (dwcfi_hash_find): New.
>       (dwcfi_hash_find_or_make): New.
>       (cfi_insn_data): New member cur_seg.
>       (cie_entry): Likewise.
>       (fde_entry): New cseg and handled members.
>       (alloc_fde_entry): Initialize cseg member.
>       (alloc_cfi_insn_data): Initialize cur_seg member.
>       (dot_cfi_sections): Compare for beginning of
>       section names via strncmp.
>       (get_cfi_seg): New.
>       (cfi_finish): Treat link-once sections.
>       (is_now_linkonce_segment): New local helper.
>       (output_cie): Ignore cie entries not member of current
>       segment.
>       (output_fde): Likewise.
>       (select_cie_for_fde): Likewise.
>       (cfi_change_reg_numbers): Add new argument for current segment
>       and ignore insn elements, if not part of current segment.
>       * ehopt.c (get_cie_info): Use strncmp for
>       section name matching.
>       (heck_eh_frame): Likewise.
>
> ChangeLog ld/
>
> 2011-04-18  Kai Tietz
>
>       * scripttempl/alphavms.sc: Handle .eh_frame($|.)* sections.
>       * scripttempl/armbpabi.sc: Likewise.
>       * scripttempl/avr.sc: Likewise.
>       * scripttempl/crisaout.sc: Likewise.
>       * scripttempl/elf.sc: Likewise.
>       * scripttempl/elf32cr16.sc: Likewise.
>       * scripttempl/elf32crx.sc: Likewise.
>       * scripttempl/elf32msp430.sc: Likewise.
>       * scripttempl/elf32msp430_3.sc: Likewise.
>       * scripttempl/elf32sh-symbian.sc: Likewise.
>       * scripttempl/elf64hppa.sc: Likewise.
>       * scripttempl/elf_chaos.sc: Likewise.
>       * scripttempl/elfd10v.sc: Likewise.
>       * scripttempl/elfd30v.sc: Likewise.
>       * scripttempl/elfi370.sc: Likewise.
>       * scripttempl/elfm68hc11.sc: Likewise.
>       * scripttempl/elfm68hc12.sc: Likewise.
>       * scripttempl/elfmicroblaze.sc: Likewise.
>       * scripttempl/elfxtensa.sc: Likewise.
>       * scripttempl/epocpe.sc: Likewise.
>       * scripttempl/i386beos.sc: Likewise.
>       * scripttempl/i386go32.sc: Likewise.
>       * scripttempl/ip2k.sc: Likewise.
>       * scripttempl/iq2000.sc: Likewise.
>       * scripttempl/mcorepe.sc: Likewise.
>       * scripttempl/mep.sc: Likewise.
>       * scripttempl/mmo.sc: Likewise.
>       * scripttempl/pe.sc: Likewise.
>       * scripttempl/pep.sc: Likewise.
>       * scripttempl/v850.sc: Likewise.
>       * scripttempl/xstormy16.sc: Likewise.
>
> Tested for x86_64-w64-mingw32, i686-w64-mingw32, and i686-pc-cygwin.
> Ok for apply?

2 comments:

1. You should test Linux/x86 since you change ELF targets.
2. You should add some testcases to show gas/ld work correctly.


-- 
H.J.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [patch ld bfd gas]: Handle linkonce for cfi generated debug_frame and eh_frame data
  2011-04-18 12:43 ` H.J. Lu
@ 2011-04-18 20:04   ` Kai Tietz
  2011-04-24 10:20     ` Kai Tietz
  0 siblings, 1 reply; 12+ messages in thread
From: Kai Tietz @ 2011-04-18 20:04 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Binutils, Alan Modra, Nick Clifton

[-- Attachment #1: Type: text/plain, Size: 5735 bytes --]

2011/4/18 H.J. Lu <hjl.tools@gmail.com>:
> On Mon, Apr 18, 2011 at 2:33 AM, Kai Tietz <ktietz70@googlemail.com> wrote:
>> Hello,
>>
>> The recent patch about this subject I withdraw and replace it by the
>> more enhanced version.  I noticed that a bit more checkings and a
>> different approach on writing eh_frame/debug_frame sections out, was
>> necessary.  Additionally this patch allows for PE-COFF targets, that
>> debugging sections can have link-once flags active.
>>
>>
>> ChangeLog bfd/
>>
>> 2011-04-18  Kai Tietz
>>
>>        * coffcode.h (sec_to_styp_flags): Allow linkonce for
>>        debugging sections.
>>
>> ChangeLog gas/
>>
>> 2011-04-18  Kai Tietz
>>
>>       * dw2gencfi.c (dwcfi_seg_list): New struct.
>>       (dwcfi_hash): New static hash variable.
>>       (get_debugseg_name): New.
>>       (alloc_debugseg_item): New.
>>       (make_debug_seg): New.
>>       (dwcfi_hash_insert): New.
>>       (dwcfi_hash_find): New.
>>       (dwcfi_hash_find_or_make): New.
>>       (cfi_insn_data): New member cur_seg.
>>       (cie_entry): Likewise.
>>       (fde_entry): New cseg and handled members.
>>       (alloc_fde_entry): Initialize cseg member.
>>       (alloc_cfi_insn_data): Initialize cur_seg member.
>>       (dot_cfi_sections): Compare for beginning of
>>       section names via strncmp.
>>       (get_cfi_seg): New.
>>       (cfi_finish): Treat link-once sections.
>>       (is_now_linkonce_segment): New local helper.
>>       (output_cie): Ignore cie entries not member of current
>>       segment.
>>       (output_fde): Likewise.
>>       (select_cie_for_fde): Likewise.
>>       (cfi_change_reg_numbers): Add new argument for current segment
>>       and ignore insn elements, if not part of current segment.
>>       * ehopt.c (get_cie_info): Use strncmp for
>>       section name matching.
>>       (heck_eh_frame): Likewise.
>>
>> ChangeLog ld/
>>
>> 2011-04-18  Kai Tietz
>>
>>       * scripttempl/alphavms.sc: Handle .eh_frame($|.)* sections.
>>       * scripttempl/armbpabi.sc: Likewise.
>>       * scripttempl/avr.sc: Likewise.
>>       * scripttempl/crisaout.sc: Likewise.
>>       * scripttempl/elf.sc: Likewise.
>>       * scripttempl/elf32cr16.sc: Likewise.
>>       * scripttempl/elf32crx.sc: Likewise.
>>       * scripttempl/elf32msp430.sc: Likewise.
>>       * scripttempl/elf32msp430_3.sc: Likewise.
>>       * scripttempl/elf32sh-symbian.sc: Likewise.
>>       * scripttempl/elf64hppa.sc: Likewise.
>>       * scripttempl/elf_chaos.sc: Likewise.
>>       * scripttempl/elfd10v.sc: Likewise.
>>       * scripttempl/elfd30v.sc: Likewise.
>>       * scripttempl/elfi370.sc: Likewise.
>>       * scripttempl/elfm68hc11.sc: Likewise.
>>       * scripttempl/elfm68hc12.sc: Likewise.
>>       * scripttempl/elfmicroblaze.sc: Likewise.
>>       * scripttempl/elfxtensa.sc: Likewise.
>>       * scripttempl/epocpe.sc: Likewise.
>>       * scripttempl/i386beos.sc: Likewise.
>>       * scripttempl/i386go32.sc: Likewise.
>>       * scripttempl/ip2k.sc: Likewise.
>>       * scripttempl/iq2000.sc: Likewise.
>>       * scripttempl/mcorepe.sc: Likewise.
>>       * scripttempl/mep.sc: Likewise.
>>       * scripttempl/mmo.sc: Likewise.
>>       * scripttempl/pe.sc: Likewise.
>>       * scripttempl/pep.sc: Likewise.
>>       * scripttempl/v850.sc: Likewise.
>>       * scripttempl/xstormy16.sc: Likewise.
>>
>> Tested for x86_64-w64-mingw32, i686-w64-mingw32, and i686-pc-cygwin.
>> Ok for apply?
>
> 2 comments:
>
> 1. You should test Linux/x86 since you change ELF targets.
> 2. You should add some testcases to show gas/ld work correctly.
>
>
> --
> H.J.
>

I tested things for x86_64-pc-linux-gnu and found that the linkonce
code collides with eh_frame_hdr code in bfd. So I removed complete ELF
handling here and just enable cfi linkonce handling for PE-COFF
targets.

ChangeLog bfd/

2011-04-18  Kai Tietz

	* coffcode.h (sec_to_styp_flags): Allow linkonce for
	debugging sections.

ChangeLog gas/

2011-04-18  Kai Tietz

       * dw2gencfi.c (dwcfi_seg_list): New struct.
       (dwcfi_hash): New static hash variable.
       (get_debugseg_name): New.
       (alloc_debugseg_item): New.
       (make_debug_seg): New.
       (dwcfi_hash_insert): New.
       (dwcfi_hash_find): New.
       (dwcfi_hash_find_or_make): New.
       (cfi_insn_data): New member cur_seg.
       (cie_entry): Likewise.
       (fde_entry): New cseg and handled members.
       (alloc_fde_entry): Initialize cseg member.
       (alloc_cfi_insn_data): Initialize cur_seg member.
       (dot_cfi_sections): Compare for beginning of
       section names via strncmp.
       (get_cfi_seg): New.
       (cfi_finish): Treat link-once sections.
       (is_now_linkonce_segment): New local helper.
       (output_cie): Ignore cie entries not member of current
       segment.
       (output_fde): Likewise.
       (select_cie_for_fde): Likewise.
       (cfi_change_reg_numbers): Add new argument for current segment
       and ignore insn elements, if not part of current segment.
       * ehopt.c (get_cie_info): Use strncmp for
       section name matching.
       (heck_eh_frame): Likewise.

ChangeLog ld/

2011-04-18  Kai Tietz

       * scripttempl/pe.sc: Likewise.
       * scripttempl/pep.sc: Likewise.

ChangeLog ld/testsuite/

2011-04-18  Kai Tietz

	* ld-pe/pe.exp: Add cfi/cfi32 tests.
	* ld-pe/cfi.d: New.
	* ld-pe/cfi32.d: New.
	* ld-pe/cfia.s: New.
	* ld-pe/cfib.s: New.

I added a testcase for pe and pe+ and regression tested it for
i686-w64-mingw32, i686-pc-cygwin, x86_64-w64-mingw32, and
x86_64-pc-linux-gnu. Ok for apply?

Regards,
Kai

[-- Attachment #2: cfi_lonce.txt --]
[-- Type: text/plain, Size: 21410 bytes --]

Index: src/gas/dw2gencfi.c
===================================================================
--- src.orig/gas/dw2gencfi.c	2011-04-18 20:36:41.472870500 +0200
+++ src/gas/dw2gencfi.c	2011-04-18 20:47:32.521804900 +0200
@@ -76,6 +76,149 @@
 # define DWARF2_ADDR_SIZE(bfd) (bfd_arch_bits_per_address (bfd) / 8)
 #endif
 
+/* Private segment collection list.  */
+struct dwcfi_seg_list {
+  segT seg;
+  int subseg;
+  char *seg_name;
+};
+
+static struct hash_control *dwcfi_hash;
+
+/* Build based on segment the derived .debug_...
+   segment name containing origin segment's postfix name part.  */
+static char *
+get_debugseg_name (segT seg, const char *base_name)
+{
+  const char *name,*dollar, *dot;
+  char *sname;
+
+  if (!seg)
+    name = "";
+  else
+    name = bfd_get_section_name (stdoutput, seg);
+
+  dollar = strchr (name, '$');
+  dot = strchr (name + 1, '.');
+
+  if (!dollar && !dot)
+    name = "";
+  else if (!dollar)
+    name = dot;
+  else if (!dot)
+    name = dollar;
+  else if (dot < dollar)
+    name = dot;
+  else
+    name = dollar;
+
+  sname = concat (base_name, name, NULL);
+
+  return sname;
+}
+
+/* Allocate a dwcfi_seg_list structure.  */
+static struct dwcfi_seg_list *
+alloc_debugseg_item (segT seg, int subseg, char *name)
+{
+  struct dwcfi_seg_list *r;
+
+  r = (struct dwcfi_seg_list *)
+    xmalloc (sizeof (struct dwcfi_seg_list) + strlen (name));
+  r->seg = seg;
+  r->subseg = subseg;
+  r->seg_name = name;
+  return r;
+}
+
+static segT
+is_now_linkonce_segment (void)
+{
+#if defined (TE_PE) || defined (TE_PEP)
+  if ((bfd_get_section_flags (stdoutput, now_seg)
+       & (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
+	  | SEC_LINK_DUPLICATES_ONE_ONLY | SEC_LINK_DUPLICATES_SAME_SIZE
+	  | SEC_LINK_DUPLICATES_SAME_CONTENTS)) != 0)
+    return now_seg;
+#endif
+  return NULL;
+}
+
+/* Generate debug... segment with same linkonce properties
+   of based segment.  */
+static segT
+make_debug_seg (segT cseg, char *name, int sflags)
+{
+  segT save_seg = now_seg;
+  int save_subseg = now_subseg;
+  segT r;
+  flagword flags;
+
+  r = subseg_new (name, 0);
+  /* Check if code segment is marked as linked once.  */
+  if (!cseg)
+    flags = 0;
+  else
+    flags = bfd_get_section_flags (stdoutput, cseg)
+      & (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
+         | SEC_LINK_DUPLICATES_ONE_ONLY | SEC_LINK_DUPLICATES_SAME_SIZE
+         | SEC_LINK_DUPLICATES_SAME_CONTENTS);
+
+  /* Add standard section flags.  */
+  flags |= sflags;
+
+  /* Apply possibly linked once flags to new generated segment, too.  */
+  if (!bfd_set_section_flags (stdoutput, r, flags))
+    as_bad (_("bfd_set_section_flags: %s"),
+	    bfd_errmsg (bfd_get_error ()));
+
+  /* Restore to previous segment.  */
+  if (save_seg != NULL)
+    subseg_set (save_seg, save_subseg);
+  return r;
+}
+
+static void
+dwcfi_hash_insert (const char *name, struct dwcfi_seg_list *item)
+{
+  const char *error_string;
+
+  if ((error_string = hash_jam (dwcfi_hash, name, (char *) item)))
+    as_fatal (_("Inserting \"%s\" into structure table failed: %s"),
+	      name, error_string);
+}
+
+static struct dwcfi_seg_list *
+dwcfi_hash_find (char *name)
+{
+  return (struct dwcfi_seg_list *) hash_find (dwcfi_hash, name);
+}
+
+static struct dwcfi_seg_list *
+dwcfi_hash_find_or_make (segT cseg, const char *base_name, int flags)
+{
+  struct dwcfi_seg_list *item;
+  char *name;
+
+  /* Initialize dwcfi_hash once.  */
+  if (!dwcfi_hash)
+    dwcfi_hash = hash_new ();
+
+  name = get_debugseg_name (cseg, base_name);
+
+  item = dwcfi_hash_find (name);
+  if (!item)
+    {
+      item = alloc_debugseg_item (make_debug_seg (cseg, name, flags), 0, name);
+
+      dwcfi_hash_insert (item->seg_name, item);
+    }
+  else
+    free (name);
+
+  return item;
+}
+
 /* ??? Share this with dwarf2cfg.c.  */
 #ifndef TC_DWARF2_EMIT_OFFSET
 #define TC_DWARF2_EMIT_OFFSET  generic_dwarf2_emit_offset
@@ -102,6 +245,7 @@ struct cfi_escape_data {
 struct cfi_insn_data
 {
   struct cfi_insn_data *next;
+  segT cur_seg;
   int insn;
   union {
     struct {
@@ -134,6 +278,7 @@ struct cfi_insn_data
 struct fde_entry
 {
   struct fde_entry *next;
+  segT cseg;
   symbolS *start_address;
   symbolS *end_address;
   struct cfi_insn_data *data;
@@ -144,11 +289,13 @@ struct fde_entry
   expressionS lsda;
   unsigned int return_column;
   unsigned int signal_frame;
+  int handled;
 };
 
 struct cie_entry
 {
   struct cie_entry *next;
+  segT cur_seg;
   symbolS *start_address;
   unsigned int return_column;
   unsigned int signal_frame;
@@ -195,7 +342,8 @@ alloc_fde_entry (void)
   frchain_now->frch_cfi_data->cur_fde_data = fde;
   *last_fde_data = fde;
   last_fde_data = &fde->next;
-
+  fde->cseg = is_now_linkonce_segment ();
+  fde->handled = 0;
   fde->last = &fde->data;
   fde->return_column = DWARF2_DEFAULT_RETURN_COLUMN;
   fde->per_encoding = DW_EH_PE_omit;
@@ -219,6 +367,7 @@ alloc_cfi_insn_data (void)
 
   *cur_fde_data->last = insn;
   cur_fde_data->last = &insn->next;
+  insn->cur_seg = is_now_linkonce_segment ();
 
   return insn;
 }
@@ -254,7 +403,7 @@ cfi_set_return_column (unsigned regno)
 /* Universal functions to store new instructions.  */
 
 static void
-cfi_add_CFA_insn(int insn)
+cfi_add_CFA_insn (int insn)
 {
   struct cfi_insn_data *insn_ptr = alloc_cfi_insn_data ();
 
@@ -916,9 +1065,10 @@ dot_cfi_sections (int ignored ATTRIBUTE_
 	name = input_line_pointer;
 	c = get_symbol_end ();
 
-	if (strcmp (name, ".eh_frame") == 0)
+	if (strncmp (name, ".eh_frame", 9) == 0
+	    && name[9] != '_')
 	  sections |= CFI_EMIT_eh_frame;
-	else if (strcmp (name, ".debug_frame") == 0)
+	else if (strncmp (name, ".debug_frame", 12) == 0)
 	  sections |= CFI_EMIT_debug_frame;
 	else
 	  {
@@ -1384,8 +1534,14 @@ output_cie (struct cie_entry *cie, bfd_b
     out_one (enc);
 
   if (cie->first)
-    for (i = cie->first; i != cie->last; i = i->next)
-      output_cfi_insn (i);
+    {
+      for (i = cie->first; i != cie->last; i = i->next)
+        {
+	  if (i->cur_seg != cie->cur_seg)
+	    continue;
+	  output_cfi_insn (i);
+	}
+    }
 
   frag_align (align, DW_CFA_nop, 0);
   symbol_set_value_now (end_address);
@@ -1492,7 +1648,10 @@ output_fde (struct fde_entry *fde, struc
     }
 
   for (; first; first = first->next)
-    output_cfi_insn (first);
+    {
+      if (first->cur_seg == fde->cseg)
+        output_cfi_insn (first);
+    }
 
   frag_align (align, DW_CFA_nop, 0);
   symbol_set_value_now (end_address);
@@ -1507,7 +1666,8 @@ select_cie_for_fde (struct fde_entry *fd
 
   for (cie = cie_root; cie; cie = cie->next)
     {
-      if (cie->return_column != fde->return_column
+      if (cie->cur_seg != fde->cseg
+          || cie->return_column != fde->return_column
 	  || cie->signal_frame != fde->signal_frame
 	  || cie->per_encoding != fde->per_encoding
 	  || cie->lsda_encoding != fde->lsda_encoding)
@@ -1605,6 +1765,7 @@ select_cie_for_fde (struct fde_entry *fd
   cie = (struct cie_entry *) xmalloc (sizeof (struct cie_entry));
   cie->next = cie_root;
   cie_root = cie;
+  cie->cur_seg = fde->cseg;
   cie->return_column = fde->return_column;
   cie->signal_frame = fde->signal_frame;
   cie->per_encoding = fde->per_encoding;
@@ -1629,130 +1790,189 @@ select_cie_for_fde (struct fde_entry *fd
 
 #ifdef md_reg_eh_frame_to_debug_frame
 static void
-cfi_change_reg_numbers (struct cfi_insn_data *insn)
+cfi_change_reg_numbers (struct cfi_insn_data *insn, segT ccseg)
 {
   for (; insn; insn = insn->next)
-    switch (insn->insn)
-      {
-      case DW_CFA_advance_loc:
-      case DW_CFA_def_cfa_offset:
-      case DW_CFA_remember_state:
-      case DW_CFA_restore_state:
-      case DW_CFA_GNU_window_save:
-      case CFI_escape:
-	break;
+    {
+      if (insn->cur_seg != ccseg)
+        continue;
+      switch (insn->insn)
+	{
+	case DW_CFA_advance_loc:
+	case DW_CFA_def_cfa_offset:
+	case DW_CFA_remember_state:
+	case DW_CFA_restore_state:
+	case DW_CFA_GNU_window_save:
+	case CFI_escape:
+	  break;
 
-      case DW_CFA_def_cfa:
-      case DW_CFA_offset:
-	insn->u.ri.reg = md_reg_eh_frame_to_debug_frame (insn->u.ri.reg);
-	break;
+	case DW_CFA_def_cfa:
+	case DW_CFA_offset:
+	  insn->u.ri.reg = md_reg_eh_frame_to_debug_frame (insn->u.ri.reg);
+	  break;
 
-      case DW_CFA_def_cfa_register:
-      case DW_CFA_undefined:
-      case DW_CFA_same_value:
-      case DW_CFA_restore:
-	insn->u.r = md_reg_eh_frame_to_debug_frame (insn->u.r);
-	break;
+	case DW_CFA_def_cfa_register:
+	case DW_CFA_undefined:
+	case DW_CFA_same_value:
+	case DW_CFA_restore:
+	  insn->u.r = md_reg_eh_frame_to_debug_frame (insn->u.r);
+	  break;
 
-      case DW_CFA_register:
-	insn->u.rr.reg1 = md_reg_eh_frame_to_debug_frame (insn->u.rr.reg1);
-	insn->u.rr.reg2 = md_reg_eh_frame_to_debug_frame (insn->u.rr.reg2);
-	break;
+	case DW_CFA_register:
+	  insn->u.rr.reg1 = md_reg_eh_frame_to_debug_frame (insn->u.rr.reg1);
+	  insn->u.rr.reg2 = md_reg_eh_frame_to_debug_frame (insn->u.rr.reg2);
+	  break;
 
-      case CFI_val_encoded_addr:
-	insn->u.ea.reg = md_reg_eh_frame_to_debug_frame (insn->u.ea.reg);
-	break;
+	case CFI_val_encoded_addr:
+	  insn->u.ea.reg = md_reg_eh_frame_to_debug_frame (insn->u.ea.reg);
+	  break;
 
-      default:
-	abort ();
-      }
+	default:
+	  abort ();
+	}
+    }
 }
 #else
-#define cfi_change_reg_numbers(insn) do { } while (0)
+#define cfi_change_reg_numbers(insn, cseg) do { } while (0)
 #endif
 
+static segT
+get_cfi_seg (segT cseg, const char *base, flagword flags, int align)
+{
+  struct dwcfi_seg_list *l;
+
+  l = dwcfi_hash_find_or_make (cseg, base, flags);
+
+  subseg_set (l->seg, l->subseg);
+  record_alignment (l->seg, align);
+  return l->seg;
+}
+
 void
 cfi_finish (void)
 {
-  segT cfi_seg;
+  struct cie_entry *cie, *cie_next;
+  segT cfi_seg, ccseg;
   struct fde_entry *fde;
-  int save_flag_traditional_format;
+  struct cfi_insn_data *first;
+  int save_flag_traditional_format, seek_next_seg;
 
   if (all_fde_data == 0)
     return;
 
   if ((cfi_sections & CFI_EMIT_eh_frame) != 0)
     {
-      /* Open .eh_frame section.  */
-      cfi_seg = subseg_new (".eh_frame", 0);
-      bfd_set_section_flags (stdoutput, cfi_seg,
-			     SEC_ALLOC | SEC_LOAD | SEC_DATA
-			     | DWARF2_EH_FRAME_READ_ONLY);
-      subseg_set (cfi_seg, 0);
-      record_alignment (cfi_seg, EH_FRAME_ALIGNMENT);
-
-#ifdef md_fix_up_eh_frame
-      md_fix_up_eh_frame (cfi_seg);
-#endif
-
       /* Make sure check_eh_frame doesn't do anything with our output.  */
       save_flag_traditional_format = flag_traditional_format;
       flag_traditional_format = 1;
 
-      for (fde = all_fde_data; fde ; fde = fde->next)
-	{
-	  struct cfi_insn_data *first;
-	  struct cie_entry *cie;
-
-	  if (fde->end_address == NULL)
+      do
+        {
+	  ccseg = NULL;
+	  cfi_seg = NULL;
+	  seek_next_seg = 0;
+	  for (cie = cie_root; cie; cie = cie_next)
 	    {
-	      as_bad (_("open CFI at the end of file; missing .cfi_endproc directive"));
-	      fde->end_address = fde->start_address;
+	      cie_next = cie->next;
+	      free ((void *) cie);
 	    }
+	  cie_root = NULL;
 
-	  cie = select_cie_for_fde (fde, TRUE, &first, 2);
-	  output_fde (fde, cie, TRUE, first,
-		      fde->next == NULL ? EH_FRAME_ALIGNMENT : 2);
+	  for (fde = all_fde_data; fde ; fde = fde->next)
+	    {
+	      if (fde->handled != 0)
+	        continue;
+	      if (seek_next_seg && fde->cseg != ccseg)
+	        {
+		  seek_next_seg = 2;
+		  continue;
+		}
+	      if (!seek_next_seg)
+	        {
+		  ccseg = fde->cseg;
+		  /* Open .eh_frame section.  */
+		  cfi_seg = get_cfi_seg (ccseg, ".eh_frame",
+					 SEC_ALLOC | SEC_LOAD | SEC_DATA
+					 | DWARF2_EH_FRAME_READ_ONLY,
+					 EH_FRAME_ALIGNMENT);
+#ifdef md_fix_up_eh_frame
+		  md_fix_up_eh_frame (cfi_seg);
+#endif
+		  seek_next_seg = 1;
+		}
+	      fde->handled = 1;
+
+	      if (fde->end_address == NULL)
+		{
+		  as_bad (_("open CFI at the end of file; missing .cfi_endproc directive"));
+		  fde->end_address = fde->start_address;
+		}
+
+	      cie = select_cie_for_fde (fde, TRUE, &first, 2);
+	      output_fde (fde, cie, TRUE, first,
+			  fde->next == NULL ? EH_FRAME_ALIGNMENT : 2);
+	    }
 	}
+      while (seek_next_seg == 2);
+
+      for (fde = all_fde_data; fde ; fde = fde->next)
+        fde->handled = 0;
 
       flag_traditional_format = save_flag_traditional_format;
     }
 
   if ((cfi_sections & CFI_EMIT_debug_frame) != 0)
     {
-      struct cie_entry *cie, *cie_next;
       int alignment = ffs (DWARF2_ADDR_SIZE (stdoutput)) - 1;
 
-      for (cie = cie_root; cie; cie = cie_next)
-	{
-	  cie_next = cie->next;
-	  free ((void *) cie);
-	}
-      cie_root = NULL;
-
-      /* Open .debug_frame section.  */
-      cfi_seg = subseg_new (".debug_frame", 0);
-      bfd_set_section_flags (stdoutput, cfi_seg,
-			     SEC_READONLY | SEC_DEBUGGING);
-      subseg_set (cfi_seg, 0);
-      record_alignment (cfi_seg, alignment);
-
-      for (fde = all_fde_data; fde ; fde = fde->next)
-	{
-	  struct cfi_insn_data *first;
-
-	  if (fde->end_address == NULL)
+      do
+        {
+	  ccseg = NULL;
+	  cfi_seg = NULL;
+	  seek_next_seg = 0;
+	  for (cie = cie_root; cie; cie = cie_next)
 	    {
-	      as_bad (_("open CFI at the end of file; missing .cfi_endproc directive"));
-	      fde->end_address = fde->start_address;
+	      cie_next = cie->next;
+	      free ((void *) cie);
 	    }
+	  cie_root = NULL;
 
-	  fde->per_encoding = DW_EH_PE_omit;
-	  fde->lsda_encoding = DW_EH_PE_omit;
-	  cfi_change_reg_numbers (fde->data);
-	  cie = select_cie_for_fde (fde, FALSE, &first, alignment);
-	  output_fde (fde, cie, FALSE, first, alignment);
+	  for (fde = all_fde_data; fde ; fde = fde->next)
+	    {
+	      if (fde->handled != 0)
+	        continue;
+	      if (seek_next_seg && fde->cseg != ccseg)
+	        {
+		  seek_next_seg = 2;
+		  continue;
+		}
+	      if (!seek_next_seg)
+	        {
+		  ccseg = fde->cseg;
+		  /* Open .debug_frame section.  */
+		  cfi_seg = get_cfi_seg (ccseg, ".debug_frame",
+					 SEC_READONLY | SEC_DEBUGGING,
+					 alignment);
+		  seek_next_seg = 1;
+		}
+	      fde->handled = 1;
+	      if (fde->end_address == NULL)
+		{
+		  as_bad (_("open CFI at the end of file; missing .cfi_endproc directive"));
+		  fde->end_address = fde->start_address;
+		}
+
+	      fde->per_encoding = DW_EH_PE_omit;
+	      fde->lsda_encoding = DW_EH_PE_omit;
+	      cfi_change_reg_numbers (fde->data, ccseg);
+	      cie = select_cie_for_fde (fde, FALSE, &first, alignment);
+	      output_fde (fde, cie, FALSE, first, alignment);
+	    }
 	}
+      while (seek_next_seg == 2);
+
+      for (fde = all_fde_data; fde ; fde = fde->next)
+        fde->handled = 0;
     }
 }
 
Index: src/gas/ehopt.c
===================================================================
--- src.orig/gas/ehopt.c	2011-04-18 20:36:41.483870500 +0200
+++ src/gas/ehopt.c	2011-04-18 20:47:32.525305400 +0200
@@ -120,7 +120,7 @@ get_cie_info (struct cie_info *info)
 
   /* First make sure that the CIE Identifier Tag is 0/-1.  */
 
-  if (strcmp (segment_name (now_seg), ".debug_frame") == 0)
+  if (strncmp (segment_name (now_seg), ".debug_frame", 12) == 0)
     CIE_id = (char)0xff;
   else
     CIE_id = 0;
@@ -285,9 +285,10 @@ check_eh_frame (expressionS *exp, unsign
 #endif
 
   /* Select the proper section data.  */
-  if (strcmp (segment_name (now_seg), ".eh_frame") == 0)
+  if (strncmp (segment_name (now_seg), ".eh_frame", 9) == 0
+      && segment_name (now_seg)[9] != '_')
     d = &eh_frame_data;
-  else if (strcmp (segment_name (now_seg), ".debug_frame") == 0)
+  else if (strncmp (segment_name (now_seg), ".debug_frame", 12) == 0)
     d = &debug_frame_data;
   else
     return 0;
Index: src/ld/scripttempl/pe.sc
===================================================================
--- src.orig/ld/scripttempl/pe.sc	2011-04-18 20:36:41.513870500 +0200
+++ src/ld/scripttempl/pe.sc	2011-04-18 20:47:32.527805700 +0200
@@ -115,7 +115,7 @@ SECTIONS
 
   .eh_frame ${RELOCATING+BLOCK(__section_alignment__)} :
   {
-    *(.eh_frame)
+    *(.eh_frame*)
   }
 
   .pdata ${RELOCATING+BLOCK(__section_alignment__)} :
@@ -250,7 +250,7 @@ SECTIONS
 
   .debug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
   {
-    *(.debug_frame)
+    *(.debug_frame*)
   }
 
   .debug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
Index: src/ld/scripttempl/pep.sc
===================================================================
--- src.orig/ld/scripttempl/pep.sc	2011-04-18 20:36:41.514870500 +0200
+++ src/ld/scripttempl/pep.sc	2011-04-18 20:47:32.531306100 +0200
@@ -116,7 +116,7 @@ SECTIONS
 
   .eh_frame ${RELOCATING+BLOCK(__section_alignment__)} :
   {
-    *(.eh_frame)
+    *(.eh_frame*)
   }
 
   .pdata ${RELOCATING+BLOCK(__section_alignment__)} :
@@ -256,7 +256,7 @@ SECTIONS
 
   .debug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
   {
-    *(.debug_frame)
+    *(.debug_frame*)
   }
 
   .debug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
Index: src/bfd/coffcode.h
===================================================================
--- src.orig/bfd/coffcode.h	2011-04-18 20:36:41.471870500 +0200
+++ src/bfd/coffcode.h	2011-04-18 20:47:32.535806700 +0200
@@ -658,7 +658,10 @@ sec_to_styp_flags (const char *sec_name,
 
   /* FIXME: There is no gas syntax to specify the debug section flag.  */
   if (is_dbg)
-      sec_flags = SEC_DEBUGGING | SEC_READONLY;
+    {
+      sec_flags &= (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD);
+      sec_flags |= SEC_DEBUGGING | SEC_READONLY;
+    }
 
   /* skip LOAD */
   /* READONLY later */
Index: src/ld/testsuite/ld-pe/cfi.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ src/ld/testsuite/ld-pe/cfi.d	2011-04-18 21:57:41.131230400 +0200
@@ -0,0 +1,36 @@
+#source: cfia.s
+#source: cfib.s
+#ld: --file-align 1 --section-align 1
+#objdump: -Wf
+
+#...
+00000004 00000014 ffffffff CIE
+  Version:               1
+  Augmentation:          ""
+  Code alignment factor: 1
+  Data alignment factor: \-8
+  Return address column: 32
+
+  DW_CFA_def_cfa: r7 \(rsp\) ofs 8
+  DW_CFA_offset: r32 \(xmm15\) at cfa\-8
+  DW_CFA_nop
+  DW_CFA_nop
+  DW_CFA_nop
+  DW_CFA_nop
+  DW_CFA_nop
+  DW_CFA_nop
+
+0000001c 00000024 00000004 FDE cie=00000004 pc=.*
+  DW_CFA_advance_loc: 4 to .*
+  DW_CFA_def_cfa_offset: 16
+  DW_CFA_offset: r6 \(rbp\) at cfa\-16
+  DW_CFA_advance_loc: 4 to .*
+^  DW_CFA_def_cfa: r7 \(rsp\) ofs 8
+  DW_CFA_restore: r6 \(rbp\)
+  DW_CFA_nop
+  DW_CFA_nop
+  DW_CFA_nop
+  DW_CFA_nop
+  DW_CFA_nop
+  DW_CFA_nop
+#pass
Index: src/ld/testsuite/ld-pe/cfi32.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ src/ld/testsuite/ld-pe/cfi32.d	2011-04-18 21:56:42.186245400 +0200
@@ -0,0 +1,28 @@
+#source: cfia.s
+#source: cfib.s
+#ld: --file-align 1 --section-align 1
+#objdump: -Wf
+
+#...
+00000000 00000010 ffffffff CIE
+  Version:               1
+  Augmentation:          ""
+  Code alignment factor: 1
+  Data alignment factor: \-4
+  Return address column: 8
+
+  DW_CFA_def_cfa: r4 \(esp\) ofs 4
+  DW_CFA_offset: r8 \(eip\) at cfa\-4
+  DW_CFA_nop
+  DW_CFA_nop
+
+00000014 00000018 00000000 FDE cie=00000000 pc=.*
+  DW_CFA_advance_loc: 4 to .*
+  DW_CFA_def_cfa_offset: 16
+  DW_CFA_offset: r6 \(esi\) at cfa\-16
+  DW_CFA_advance_loc: 4 to .*
+  DW_CFA_def_cfa: r7 \(edi\) ofs 8
+  DW_CFA_restore: r6 \(esi\)
+  DW_CFA_nop
+  DW_CFA_nop
+#pass
Index: src/ld/testsuite/ld-pe/cfia.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ src/ld/testsuite/ld-pe/cfia.s	2011-04-18 21:37:50.931594300 +0200
@@ -0,0 +1,26 @@
+ .globl _mainCRTStartup
+ .globl _start
+ .text
+_mainCRTStartup:
+mainCRTStartup:
+_start:
+start:
+ .long -1
+
+ .cfi_sections	.debug_frame
+ .section .text$abc,"x"
+ .linkonce discard
+ .align 2
+ .globl _tst
+ .def _tst; .scl 2; .type 32; .endef
+_tst:
+ .cfi_startproc
+ .long 0
+ .cfi_def_cfa_offset 16
+ .cfi_offset 6, -16
+ .long 1
+ .cfi_def_cfa 7, 8
+ .cfi_restore 6
+ .long 2
+ .cfi_endproc
+
Index: src/ld/testsuite/ld-pe/cfib.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ src/ld/testsuite/ld-pe/cfib.s	2011-04-18 21:38:00.620324600 +0200
@@ -0,0 +1,16 @@
+ .cfi_sections	.debug_frame
+ .section .text$abc,"x"
+ .linkonce discard
+ .align 2
+ .globl _tst
+ .def _tst; .scl 2; .type 32; .endef
+_tst:
+ .cfi_startproc
+ .long 0
+ .cfi_def_cfa_offset 16
+ .cfi_offset 6, -16
+ .long 1
+ .cfi_def_cfa 7, 8
+ .cfi_restore 6
+ .long 2
+ .cfi_endproc
Index: src/ld/testsuite/ld-pe/pe.exp
===================================================================
--- src.orig/ld/testsuite/ld-pe/pe.exp	2010-12-21 19:33:26.000000000 +0100
+++ src/ld/testsuite/ld-pe/pe.exp	2011-04-18 21:41:30.042917900 +0200
@@ -77,6 +77,12 @@ run_dump_test "longsecn-5"
 run_dump_test "orphan"
 run_dump_test "orphan_nu"
 
+if {[istarget x86_64-*-mingw*] } {
+	run_dump_test "cfi"
+} elseif {[istarget i*86-*-cygwin*] || [istarget i*86-*-mingw*] } {
+	run_dump_test "cfi32"
+}
+
 set foreign_sym_test {
   {"non-C aligned common" "" "" {non-c-lang-syms.s}
    {{nm -C non-c-lang-syms.d}} "non-c-lang-syms.x"}

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [patch ld bfd gas]: Handle linkonce for cfi generated debug_frame and eh_frame data
  2011-04-18 20:04   ` Kai Tietz
@ 2011-04-24 10:20     ` Kai Tietz
  2011-04-26 15:29       ` Nick Clifton
  0 siblings, 1 reply; 12+ messages in thread
From: Kai Tietz @ 2011-04-24 10:20 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Binutils, Alan Modra, Nick Clifton

2011/4/18 Kai Tietz <ktietz70@googlemail.com>:
> 2011/4/18 H.J. Lu <hjl.tools@gmail.com>:
>> On Mon, Apr 18, 2011 at 2:33 AM, Kai Tietz <ktietz70@googlemail.com> wrote:
>>> Hello,
>>>
>>> The recent patch about this subject I withdraw and replace it by the
>>> more enhanced version.  I noticed that a bit more checkings and a
>>> different approach on writing eh_frame/debug_frame sections out, was
>>> necessary.  Additionally this patch allows for PE-COFF targets, that
>>> debugging sections can have link-once flags active.
>>>
>>>
>>> ChangeLog bfd/
>>>
>>> 2011-04-18  Kai Tietz
>>>
>>>        * coffcode.h (sec_to_styp_flags): Allow linkonce for
>>>        debugging sections.
>>>
>>> ChangeLog gas/
>>>
>>> 2011-04-18  Kai Tietz
>>>
>>>       * dw2gencfi.c (dwcfi_seg_list): New struct.
>>>       (dwcfi_hash): New static hash variable.
>>>       (get_debugseg_name): New.
>>>       (alloc_debugseg_item): New.
>>>       (make_debug_seg): New.
>>>       (dwcfi_hash_insert): New.
>>>       (dwcfi_hash_find): New.
>>>       (dwcfi_hash_find_or_make): New.
>>>       (cfi_insn_data): New member cur_seg.
>>>       (cie_entry): Likewise.
>>>       (fde_entry): New cseg and handled members.
>>>       (alloc_fde_entry): Initialize cseg member.
>>>       (alloc_cfi_insn_data): Initialize cur_seg member.
>>>       (dot_cfi_sections): Compare for beginning of
>>>       section names via strncmp.
>>>       (get_cfi_seg): New.
>>>       (cfi_finish): Treat link-once sections.
>>>       (is_now_linkonce_segment): New local helper.
>>>       (output_cie): Ignore cie entries not member of current
>>>       segment.
>>>       (output_fde): Likewise.
>>>       (select_cie_for_fde): Likewise.
>>>       (cfi_change_reg_numbers): Add new argument for current segment
>>>       and ignore insn elements, if not part of current segment.
>>>       * ehopt.c (get_cie_info): Use strncmp for
>>>       section name matching.
>>>       (heck_eh_frame): Likewise.
>>>
>>> ChangeLog ld/
>>>
>>> 2011-04-18  Kai Tietz
>>>
>>>       * scripttempl/alphavms.sc: Handle .eh_frame($|.)* sections.
>>>       * scripttempl/armbpabi.sc: Likewise.
>>>       * scripttempl/avr.sc: Likewise.
>>>       * scripttempl/crisaout.sc: Likewise.
>>>       * scripttempl/elf.sc: Likewise.
>>>       * scripttempl/elf32cr16.sc: Likewise.
>>>       * scripttempl/elf32crx.sc: Likewise.
>>>       * scripttempl/elf32msp430.sc: Likewise.
>>>       * scripttempl/elf32msp430_3.sc: Likewise.
>>>       * scripttempl/elf32sh-symbian.sc: Likewise.
>>>       * scripttempl/elf64hppa.sc: Likewise.
>>>       * scripttempl/elf_chaos.sc: Likewise.
>>>       * scripttempl/elfd10v.sc: Likewise.
>>>       * scripttempl/elfd30v.sc: Likewise.
>>>       * scripttempl/elfi370.sc: Likewise.
>>>       * scripttempl/elfm68hc11.sc: Likewise.
>>>       * scripttempl/elfm68hc12.sc: Likewise.
>>>       * scripttempl/elfmicroblaze.sc: Likewise.
>>>       * scripttempl/elfxtensa.sc: Likewise.
>>>       * scripttempl/epocpe.sc: Likewise.
>>>       * scripttempl/i386beos.sc: Likewise.
>>>       * scripttempl/i386go32.sc: Likewise.
>>>       * scripttempl/ip2k.sc: Likewise.
>>>       * scripttempl/iq2000.sc: Likewise.
>>>       * scripttempl/mcorepe.sc: Likewise.
>>>       * scripttempl/mep.sc: Likewise.
>>>       * scripttempl/mmo.sc: Likewise.
>>>       * scripttempl/pe.sc: Likewise.
>>>       * scripttempl/pep.sc: Likewise.
>>>       * scripttempl/v850.sc: Likewise.
>>>       * scripttempl/xstormy16.sc: Likewise.
>>>
>>> Tested for x86_64-w64-mingw32, i686-w64-mingw32, and i686-pc-cygwin.
>>> Ok for apply?
>>
>> 2 comments:
>>
>> 1. You should test Linux/x86 since you change ELF targets.
>> 2. You should add some testcases to show gas/ld work correctly.
>>
>>
>> --
>> H.J.
>>
>
> I tested things for x86_64-pc-linux-gnu and found that the linkonce
> code collides with eh_frame_hdr code in bfd. So I removed complete ELF
> handling here and just enable cfi linkonce handling for PE-COFF
> targets.
>
> ChangeLog bfd/
>
> 2011-04-18  Kai Tietz
>
>        * coffcode.h (sec_to_styp_flags): Allow linkonce for
>        debugging sections.
>
> ChangeLog gas/
>
> 2011-04-18  Kai Tietz
>
>       * dw2gencfi.c (dwcfi_seg_list): New struct.
>       (dwcfi_hash): New static hash variable.
>       (get_debugseg_name): New.
>       (alloc_debugseg_item): New.
>       (make_debug_seg): New.
>       (dwcfi_hash_insert): New.
>       (dwcfi_hash_find): New.
>       (dwcfi_hash_find_or_make): New.
>       (cfi_insn_data): New member cur_seg.
>       (cie_entry): Likewise.
>       (fde_entry): New cseg and handled members.
>       (alloc_fde_entry): Initialize cseg member.
>       (alloc_cfi_insn_data): Initialize cur_seg member.
>       (dot_cfi_sections): Compare for beginning of
>       section names via strncmp.
>       (get_cfi_seg): New.
>       (cfi_finish): Treat link-once sections.
>       (is_now_linkonce_segment): New local helper.
>       (output_cie): Ignore cie entries not member of current
>       segment.
>       (output_fde): Likewise.
>       (select_cie_for_fde): Likewise.
>       (cfi_change_reg_numbers): Add new argument for current segment
>       and ignore insn elements, if not part of current segment.
>       * ehopt.c (get_cie_info): Use strncmp for
>       section name matching.
>       (heck_eh_frame): Likewise.
>
> ChangeLog ld/
>
> 2011-04-18  Kai Tietz
>
>       * scripttempl/pe.sc: Likewise.
>       * scripttempl/pep.sc: Likewise.
>
> ChangeLog ld/testsuite/
>
> 2011-04-18  Kai Tietz
>
>        * ld-pe/pe.exp: Add cfi/cfi32 tests.
>        * ld-pe/cfi.d: New.
>        * ld-pe/cfi32.d: New.
>        * ld-pe/cfia.s: New.
>        * ld-pe/cfib.s: New.
>
> I added a testcase for pe and pe+ and regression tested it for
> i686-w64-mingw32, i686-pc-cygwin, x86_64-w64-mingw32, and
> x86_64-pc-linux-gnu. Ok for apply?
>
> Regards,
> Kai
>

PING

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [patch ld bfd gas]: Handle linkonce for cfi generated debug_frame and eh_frame data
  2011-04-24 10:20     ` Kai Tietz
@ 2011-04-26 15:29       ` Nick Clifton
  2011-04-27 20:35         ` gas -Werror compilation break [Re: [patch ld bfd gas]: Handle linkonce for cfi generated debug_frame and eh_frame data] Jan Kratochvil
  0 siblings, 1 reply; 12+ messages in thread
From: Nick Clifton @ 2011-04-26 15:29 UTC (permalink / raw)
  To: Kai Tietz; +Cc: H.J. Lu, Binutils, Alan Modra

Hi Kai,

>> ChangeLog bfd/
>> >  2011-04-18  Kai Tietz
>> >
>> >          * coffcode.h (sec_to_styp_flags): Allow linkonce for
>> >          debugging sections.
>> >
>> >  ChangeLog gas/
>> >  2011-04-18  Kai Tietz
>> >
>> >         * dw2gencfi.c (dwcfi_seg_list): New struct.
>> >         (dwcfi_hash): New static hash variable.
>> >         (get_debugseg_name): New.
>> >         (alloc_debugseg_item): New.
>> >         (make_debug_seg): New.
>> >         (dwcfi_hash_insert): New.
>> >         (dwcfi_hash_find): New.
>> >         (dwcfi_hash_find_or_make): New.
>> >         (cfi_insn_data): New member cur_seg.
>> >         (cie_entry): Likewise.
>> >         (fde_entry): New cseg and handled members.
>> >         (alloc_fde_entry): Initialize cseg member.
>> >         (alloc_cfi_insn_data): Initialize cur_seg member.
>> >         (dot_cfi_sections): Compare for beginning of
>> >         section names via strncmp.
>> >         (get_cfi_seg): New.
>> >         (cfi_finish): Treat link-once sections.
>> >         (is_now_linkonce_segment): New local helper.
>> >         (output_cie): Ignore cie entries not member of current
>> >         segment.
>> >         (output_fde): Likewise.
>> >         (select_cie_for_fde): Likewise.
>> >         (cfi_change_reg_numbers): Add new argument for current segment
>> >         and ignore insn elements, if not part of current segment.
>> >         * ehopt.c (get_cie_info): Use strncmp for
>> >         section name matching.
>> >         (heck_eh_frame): Likewise.
>> >
>> >  ChangeLog ld/
>> >
>> >  2011-04-18  Kai Tietz
>> >
>> >         * scripttempl/pe.sc: Likewise.
>> >         * scripttempl/pep.sc: Likewise.
>> >
>> >  ChangeLog ld/testsuite/
>> >
>> >  2011-04-18  Kai Tietz
>> >
>> >          * ld-pe/pe.exp: Add cfi/cfi32 tests.
>> >          * ld-pe/cfi.d: New.
>> >          * ld-pe/cfi32.d: New.
>> >          * ld-pe/cfia.s: New.
>> >          * ld-pe/cfib.s: New.
>> >

Approved and applied,  Sorry for the delay.

Cheers
   Nick

^ permalink raw reply	[flat|nested] 12+ messages in thread

* gas -Werror compilation break  [Re: [patch ld bfd gas]: Handle linkonce for cfi generated debug_frame and eh_frame data]
  2011-04-26 15:29       ` Nick Clifton
@ 2011-04-27 20:35         ` Jan Kratochvil
  2011-05-05  0:29           ` Dave Korn
  0 siblings, 1 reply; 12+ messages in thread
From: Jan Kratochvil @ 2011-04-27 20:35 UTC (permalink / raw)
  To: Kai Tietz; +Cc: Nick Clifton, Kai Tietz, H.J. Lu, Binutils, Alan Modra

Hi Kai,

On Tue, 26 Apr 2011 17:30:08 +0200, Nick Clifton wrote:
> >>>  ChangeLog gas/
> >>>  2011-04-18  Kai Tietz
> >>>
> >>>         * dw2gencfi.c (dwcfi_seg_list): New struct.
> >>>         (dwcfi_hash): New static hash variable.
> >>>         (get_debugseg_name): New.
> >>>         (alloc_debugseg_item): New.
> >>>         (make_debug_seg): New.
> >>>         (dwcfi_hash_insert): New.
> >>>         (dwcfi_hash_find): New.
> >>>         (dwcfi_hash_find_or_make): New.
> >>>         (cfi_insn_data): New member cur_seg.
> >>>         (cie_entry): Likewise.
> >>>         (fde_entry): New cseg and handled members.
> >>>         (alloc_fde_entry): Initialize cseg member.
> >>>         (alloc_cfi_insn_data): Initialize cur_seg member.
> >>>         (dot_cfi_sections): Compare for beginning of
> >>>         section names via strncmp.
> >>>         (get_cfi_seg): New.
> >>>         (cfi_finish): Treat link-once sections.
> >>>         (is_now_linkonce_segment): New local helper.
> >>>         (output_cie): Ignore cie entries not member of current
> >>>         segment.
> >>>         (output_fde): Likewise.
> >>>         (select_cie_for_fde): Likewise.
> >>>         (cfi_change_reg_numbers): Add new argument for current segment
> >>>         and ignore insn elements, if not part of current segment.
> >>>         * ehopt.c (get_cie_info): Use strncmp for
> >>>         section name matching.
> >>>         (heck_eh_frame): Likewise.

dw2gencfi.c:1870:8: error: variable ‘cfi_seg’ set but not used [-Werror=unused-but-set-variable]
gcc-4.6.0-5.fc15.x86_64

Could you please provide a fix?


Thanks,
Jan

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: gas -Werror compilation break  [Re: [patch ld bfd gas]: Handle linkonce for cfi generated debug_frame and eh_frame data]
  2011-04-27 20:35         ` gas -Werror compilation break [Re: [patch ld bfd gas]: Handle linkonce for cfi generated debug_frame and eh_frame data] Jan Kratochvil
@ 2011-05-05  0:29           ` Dave Korn
  2011-05-05  8:45             ` Alan Modra
  2011-05-05  8:50             ` Kai Tietz
  0 siblings, 2 replies; 12+ messages in thread
From: Dave Korn @ 2011-05-05  0:29 UTC (permalink / raw)
  To: Jan Kratochvil
  Cc: Kai Tietz, Nick Clifton, Kai Tietz, H.J. Lu, Binutils, Alan Modra

[-- Attachment #1: Type: text/plain, Size: 2378 bytes --]

On 27/04/2011 21:34, Jan Kratochvil wrote:
> Hi Kai,
> 
> On Tue, 26 Apr 2011 17:30:08 +0200, Nick Clifton wrote:
>>>>>  ChangeLog gas/
>>>>>  2011-04-18  Kai Tietz
>>>>>
>>>>>         * dw2gencfi.c (dwcfi_seg_list): New struct.
>>>>>         (dwcfi_hash): New static hash variable.
>>>>>         (get_debugseg_name): New.
>>>>>         (alloc_debugseg_item): New.
>>>>>         (make_debug_seg): New.
>>>>>         (dwcfi_hash_insert): New.
>>>>>         (dwcfi_hash_find): New.
>>>>>         (dwcfi_hash_find_or_make): New.
>>>>>         (cfi_insn_data): New member cur_seg.
>>>>>         (cie_entry): Likewise.
>>>>>         (fde_entry): New cseg and handled members.
>>>>>         (alloc_fde_entry): Initialize cseg member.
>>>>>         (alloc_cfi_insn_data): Initialize cur_seg member.
>>>>>         (dot_cfi_sections): Compare for beginning of
>>>>>         section names via strncmp.
>>>>>         (get_cfi_seg): New.
>>>>>         (cfi_finish): Treat link-once sections.
>>>>>         (is_now_linkonce_segment): New local helper.
>>>>>         (output_cie): Ignore cie entries not member of current
>>>>>         segment.
>>>>>         (output_fde): Likewise.
>>>>>         (select_cie_for_fde): Likewise.
>>>>>         (cfi_change_reg_numbers): Add new argument for current segment
>>>>>         and ignore insn elements, if not part of current segment.
>>>>>         * ehopt.c (get_cie_info): Use strncmp for
>>>>>         section name matching.
>>>>>         (heck_eh_frame): Likewise.
> 
> dw2gencfi.c:1870:8: error: variable ‘cfi_seg’ set but not used [-Werror=unused-but-set-variable]
> gcc-4.6.0-5.fc15.x86_64
> 
> Could you please provide a fix?

  This fixes the breakage, but doesn't address the issue that it looks to me
like there's an omitted call to md_fix_up_eh_frame() after the second
invocation of get_cfi_seg().

gas/ChangeLog:

	* dw2gencfi.c (dwcfi_hash): Wrap in #ifdef md_fix_up_eh_frame.
	(get_debugseg_name): Likewise.
	(alloc_debugseg_item): Likewise.
	(make_debug_seg): Likewise.
	(dwcfi_hash_insert): Likewise.
	(dwcfi_hash_find): Likewise.
	(dwcfi_hash_find_or_make): Likewise.
	(get_cfi_seg): Likewise.
	(cfi_finish): Wrap references to cfi_seg and calls to get_cfi_seg()
	in #ifdef md_fix_up_eh_frame likewise.

  Verified that it fixes the build on i686-pc-cygwin and
x86_64-unknown-linux-gnu, OK to install?

    cheers,
      DaveK


[-- Attachment #2: gas-werror.diff --]
[-- Type: text/x-c, Size: 2811 bytes --]

Index: gas/dw2gencfi.c
===================================================================
RCS file: /cvs/src/src/gas/dw2gencfi.c,v
retrieving revision 1.52
diff -p -u -r1.52 dw2gencfi.c
--- gas/dw2gencfi.c	26 Apr 2011 15:28:07 -0000	1.52
+++ gas/dw2gencfi.c	5 May 2011 00:18:58 -0000
@@ -86,6 +86,7 @@ struct dwcfi_seg_list
 
 #define FRAME_NAME ".eh_frame"
 
+#ifdef md_fix_up_eh_frame
 static struct hash_control *dwcfi_hash;
 
 /* Build based on segment the derived .debug_...
@@ -137,6 +138,7 @@ alloc_debugseg_item (segT seg, int subse
   r->seg_name = name;
   return r;
 }
+#endif
 
 static segT
 is_now_linkonce_segment (void)
@@ -151,6 +153,7 @@ is_now_linkonce_segment (void)
   return NULL;
 }
 
+#ifdef md_fix_up_eh_frame
 /* Generate debug... segment with same linkonce properties
    of based segment.  */
 
@@ -227,6 +230,7 @@ dwcfi_hash_find_or_make (segT cseg, cons
 
   return item;
 }
+#endif
 
 /* ??? Share this with dwarf2cfg.c.  */
 #ifndef TC_DWARF2_EMIT_OFFSET
@@ -1851,6 +1855,7 @@ cfi_change_reg_numbers (struct cfi_insn_
 #define cfi_change_reg_numbers(insn, cseg) do { } while (0)
 #endif
 
+#ifdef md_fix_up_eh_frame
 static segT
 get_cfi_seg (segT cseg, const char *base, flagword flags, int align)
 {
@@ -1862,12 +1867,16 @@ get_cfi_seg (segT cseg, const char *base
   record_alignment (l->seg, align);
   return l->seg;
 }
+#endif
 
 void
 cfi_finish (void)
 {
   struct cie_entry *cie, *cie_next;
-  segT cfi_seg, ccseg;
+#ifdef md_fix_up_eh_frame
+  segT cfi_seg;
+#endif
+  segT ccseg;
   struct fde_entry *fde;
   struct cfi_insn_data *first;
   int save_flag_traditional_format, seek_next_seg;
@@ -1884,7 +1893,9 @@ cfi_finish (void)
       do
         {
 	  ccseg = NULL;
+#ifdef md_fix_up_eh_frame
 	  cfi_seg = NULL;
+#endif
 	  seek_next_seg = 0;
 	  for (cie = cie_root; cie; cie = cie_next)
 	    {
@@ -1905,12 +1916,12 @@ cfi_finish (void)
 	      if (!seek_next_seg)
 	        {
 		  ccseg = fde->cseg;
+#ifdef md_fix_up_eh_frame
 		  /* Open .eh_frame section.  */
 		  cfi_seg = get_cfi_seg (ccseg, ".eh_frame",
 					 SEC_ALLOC | SEC_LOAD | SEC_DATA
 					 | DWARF2_EH_FRAME_READ_ONLY,
 					 EH_FRAME_ALIGNMENT);
-#ifdef md_fix_up_eh_frame
 		  md_fix_up_eh_frame (cfi_seg);
 #endif
 		  seek_next_seg = 1;
@@ -1943,7 +1954,9 @@ cfi_finish (void)
       do
         {
 	  ccseg = NULL;
+#ifdef md_fix_up_eh_frame
 	  cfi_seg = NULL;
+#endif
 	  seek_next_seg = 0;
 	  for (cie = cie_root; cie; cie = cie_next)
 	    {
@@ -1964,10 +1977,12 @@ cfi_finish (void)
 	      if (!seek_next_seg)
 	        {
 		  ccseg = fde->cseg;
+#ifdef md_fix_up_eh_frame
 		  /* Open .debug_frame section.  */
 		  cfi_seg = get_cfi_seg (ccseg, ".debug_frame",
 					 SEC_READONLY | SEC_DEBUGGING,
 					 alignment);
+#endif
 		  seek_next_seg = 1;
 		}
 	      fde->handled = 1;

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: gas -Werror compilation break  [Re: [patch ld bfd gas]: Handle linkonce for cfi generated debug_frame and eh_frame data]
  2011-05-05  0:29           ` Dave Korn
@ 2011-05-05  8:45             ` Alan Modra
  2011-05-05 13:21               ` Alan Modra
  2011-05-05  8:50             ` Kai Tietz
  1 sibling, 1 reply; 12+ messages in thread
From: Alan Modra @ 2011-05-05  8:45 UTC (permalink / raw)
  To: Dave Korn
  Cc: Jan Kratochvil, Kai Tietz, Nick Clifton, Kai Tietz, H.J. Lu, Binutils

On Thu, May 05, 2011 at 01:29:20AM +0100, Dave Korn wrote:
>   This fixes the breakage, but doesn't address the issue that it looks to me
> like there's an omitted call to md_fix_up_eh_frame() after the second
> invocation of get_cfi_seg().

The second call is for .debug_frame, so I wouldn't expect that to need
md_fix_up_eh_frame.

>   Verified that it fixes the build on i686-pc-cygwin and
> x86_64-unknown-linux-gnu, OK to install?

No, this will break all targets that don't define md_fix_up_eh_frame.

I'll be committing the following instead, which I wrote a couple of
days ago but didn't get around to installing, or even writing a
changelog.

Index: gas/dw2gencfi.c
===================================================================
RCS file: /cvs/src/src/gas/dw2gencfi.c,v
retrieving revision 1.52
diff -u -p -r1.52 dw2gencfi.c
--- gas/dw2gencfi.c	26 Apr 2011 15:28:07 -0000	1.52
+++ gas/dw2gencfi.c	3 May 2011 07:15:36 -0000
@@ -76,6 +76,13 @@
 #define DWARF2_ADDR_SIZE(bfd) (bfd_arch_bits_per_address (bfd) / 8)
 #endif
 
+#if defined (TE_PE) || defined (TE_PEP)
+#define SUPPORT_FRAME_LINKONCE 1
+#else
+#define SUPPORT_FRAME_LINKONCE 0
+#endif
+
+#if SUPPORT_FRAME_LINKONCE
 /* Private segment collection list.  */
 struct dwcfi_seg_list
 {
@@ -141,13 +148,11 @@ alloc_debugseg_item (segT seg, int subse
 static segT
 is_now_linkonce_segment (void)
 {
-#if defined (TE_PE) || defined (TE_PEP)
   if ((bfd_get_section_flags (stdoutput, now_seg)
        & (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
 	  | SEC_LINK_DUPLICATES_ONE_ONLY | SEC_LINK_DUPLICATES_SAME_SIZE
 	  | SEC_LINK_DUPLICATES_SAME_CONTENTS)) != 0)
     return now_seg;
-#endif
   return NULL;
 }
 
@@ -227,6 +232,7 @@ dwcfi_hash_find_or_make (segT cseg, cons
 
   return item;
 }
+#endif
 
 /* ??? Share this with dwarf2cfg.c.  */
 #ifndef TC_DWARF2_EMIT_OFFSET
@@ -255,7 +261,9 @@ struct cfi_escape_data
 struct cfi_insn_data
 {
   struct cfi_insn_data *next;
+#if SUPPORT_FRAME_LINKONCE
   segT cur_seg;
+#endif
   int insn;
   union
   {
@@ -293,7 +301,9 @@ struct cfi_insn_data
 struct fde_entry
 {
   struct fde_entry *next;
+#if SUPPORT_FRAME_LINKONCE
   segT cseg;
+#endif
   symbolS *start_address;
   symbolS *end_address;
   struct cfi_insn_data *data;
@@ -304,13 +314,17 @@ struct fde_entry
   expressionS lsda;
   unsigned int return_column;
   unsigned int signal_frame;
+#if SUPPORT_FRAME_LINKONCE
   int handled;
+#endif
 };
 
 struct cie_entry
 {
   struct cie_entry *next;
+#if SUPPORT_FRAME_LINKONCE
   segT cur_seg;
+#endif
   symbolS *start_address;
   unsigned int return_column;
   unsigned int signal_frame;
@@ -357,8 +371,10 @@ alloc_fde_entry (void)
   frchain_now->frch_cfi_data->cur_fde_data = fde;
   *last_fde_data = fde;
   last_fde_data = &fde->next;
+#if SUPPORT_FRAME_LINKONCE
   fde->cseg = is_now_linkonce_segment ();
   fde->handled = 0;
+#endif
   fde->last = &fde->data;
   fde->return_column = DWARF2_DEFAULT_RETURN_COLUMN;
   fde->per_encoding = DW_EH_PE_omit;
@@ -382,8 +398,9 @@ alloc_cfi_insn_data (void)
 
   *cur_fde_data->last = insn;
   cur_fde_data->last = &insn->next;
+#if SUPPORT_FRAME_LINKONCE
   insn->cur_seg = is_now_linkonce_segment ();
-
+#endif
   return insn;
 }
 
@@ -1552,8 +1569,10 @@ output_cie (struct cie_entry *cie, bfd_b
     {
       for (i = cie->first; i != cie->last; i = i->next)
         {
+#if SUPPORT_FRAME_LINKONCE
 	  if (i->cur_seg != cie->cur_seg)
 	    continue;
+#endif
 	  output_cfi_insn (i);
 	}
     }
@@ -1663,10 +1682,10 @@ output_fde (struct fde_entry *fde, struc
     }
 
   for (; first; first = first->next)
-    {
-      if (first->cur_seg == fde->cseg)
-        output_cfi_insn (first);
-    }
+#if SUPPORT_FRAME_LINKONCE
+    if (first->cur_seg == fde->cseg)
+#endif
+      output_cfi_insn (first);
 
   frag_align (align, DW_CFA_nop, 0);
   symbol_set_value_now (end_address);
@@ -1681,8 +1700,11 @@ select_cie_for_fde (struct fde_entry *fd
 
   for (cie = cie_root; cie; cie = cie->next)
     {
-      if (cie->cur_seg != fde->cseg
-          || cie->return_column != fde->return_column
+#if SUPPORT_FRAME_LINKONCE
+      if (cie->cur_seg != fde->cseg)
+	continue;
+#endif
+      if (cie->return_column != fde->return_column
 	  || cie->signal_frame != fde->signal_frame
 	  || cie->per_encoding != fde->per_encoding
 	  || cie->lsda_encoding != fde->lsda_encoding)
@@ -1780,7 +1802,9 @@ select_cie_for_fde (struct fde_entry *fd
   cie = (struct cie_entry *) xmalloc (sizeof (struct cie_entry));
   cie->next = cie_root;
   cie_root = cie;
+#if SUPPORT_FRAME_LINKONCE
   cie->cur_seg = fde->cseg;
+#endif
   cie->return_column = fde->return_column;
   cie->signal_frame = fde->signal_frame;
   cie->per_encoding = fde->per_encoding;
@@ -1805,12 +1829,14 @@ select_cie_for_fde (struct fde_entry *fd
 
 #ifdef md_reg_eh_frame_to_debug_frame
 static void
-cfi_change_reg_numbers (struct cfi_insn_data *insn, segT ccseg)
+cfi_change_reg_numbers (struct cfi_insn_data *insn, segT ccseg ATTRIBUTE_UNUSED)
 {
   for (; insn; insn = insn->next)
     {
+#if SUPPORT_FRAME_LINKONCE
       if (insn->cur_seg != ccseg)
         continue;
+#endif
       switch (insn->insn)
 	{
 	case DW_CFA_advance_loc:
@@ -1852,15 +1878,22 @@ cfi_change_reg_numbers (struct cfi_insn_
 #endif
 
 static segT
-get_cfi_seg (segT cseg, const char *base, flagword flags, int align)
+get_cfi_seg (segT cseg ATTRIBUTE_UNUSED,
+	     const char *base, flagword flags, int align)
 {
+#if SUPPORT_FRAME_LINKONCE
   struct dwcfi_seg_list *l;
 
   l = dwcfi_hash_find_or_make (cseg, base, flags);
 
-  subseg_set (l->seg, l->subseg);
-  record_alignment (l->seg, align);
-  return l->seg;
+  cseg = l->seg;
+  subseg_set (cseg, l->subseg);
+#else
+  cseg = subseg_new (base, 0);
+  bfd_set_section_flags (stdoutput, cseg, flags);
+#endif
+  record_alignment (cseg, align);
+  return cseg;
 }
 
 void
@@ -1881,11 +1914,24 @@ cfi_finish (void)
       save_flag_traditional_format = flag_traditional_format;
       flag_traditional_format = 1;
 
+#if !SUPPORT_FRAME_LINKONCE
+      /* Open .eh_frame section.  */
+      cfi_seg = get_cfi_seg (NULL, ".eh_frame",
+			     SEC_ALLOC | SEC_LOAD | SEC_DATA
+			     | DWARF2_EH_FRAME_READ_ONLY,
+			     EH_FRAME_ALIGNMENT);
+#ifdef md_fix_up_eh_frame
+      md_fix_up_eh_frame (cfi_seg);
+#else
+      (void) cfi_seg;
+#endif
+#endif
+
       do
         {
 	  ccseg = NULL;
-	  cfi_seg = NULL;
 	  seek_next_seg = 0;
+
 	  for (cie = cie_root; cie; cie = cie_next)
 	    {
 	      cie_next = cie->next;
@@ -1895,6 +1941,7 @@ cfi_finish (void)
 
 	  for (fde = all_fde_data; fde ; fde = fde->next)
 	    {
+#if SUPPORT_FRAME_LINKONCE
 	      if (fde->handled != 0)
 	        continue;
 	      if (seek_next_seg && fde->cseg != ccseg)
@@ -1912,10 +1959,13 @@ cfi_finish (void)
 					 EH_FRAME_ALIGNMENT);
 #ifdef md_fix_up_eh_frame
 		  md_fix_up_eh_frame (cfi_seg);
+#else
+		  (void) cfi_seg;
 #endif
 		  seek_next_seg = 1;
 		}
 	      fde->handled = 1;
+#endif
 
 	      if (fde->end_address == NULL)
 		{
@@ -1928,10 +1978,12 @@ cfi_finish (void)
 			  fde->next == NULL ? EH_FRAME_ALIGNMENT : 2);
 	    }
 	}
-      while (seek_next_seg == 2);
+      while (SUPPORT_FRAME_LINKONCE && seek_next_seg == 2);
 
+#if SUPPORT_FRAME_LINKONCE
       for (fde = all_fde_data; fde ; fde = fde->next)
         fde->handled = 0;
+#endif
 
       flag_traditional_format = save_flag_traditional_format;
     }
@@ -1940,11 +1992,16 @@ cfi_finish (void)
     {
       int alignment = ffs (DWARF2_ADDR_SIZE (stdoutput)) - 1;
 
+#if !SUPPORT_FRAME_LINKONCE
+      get_cfi_seg (NULL, ".debug_frame",
+		   SEC_READONLY | SEC_DEBUGGING,
+		   alignment);
+#endif
       do
         {
 	  ccseg = NULL;
-	  cfi_seg = NULL;
 	  seek_next_seg = 0;
+
 	  for (cie = cie_root; cie; cie = cie_next)
 	    {
 	      cie_next = cie->next;
@@ -1954,6 +2011,7 @@ cfi_finish (void)
 
 	  for (fde = all_fde_data; fde ; fde = fde->next)
 	    {
+#if SUPPORT_FRAME_LINKONCE
 	      if (fde->handled != 0)
 	        continue;
 	      if (seek_next_seg && fde->cseg != ccseg)
@@ -1965,12 +2023,13 @@ cfi_finish (void)
 	        {
 		  ccseg = fde->cseg;
 		  /* Open .debug_frame section.  */
-		  cfi_seg = get_cfi_seg (ccseg, ".debug_frame",
-					 SEC_READONLY | SEC_DEBUGGING,
-					 alignment);
+		  get_cfi_seg (ccseg, ".debug_frame",
+			       SEC_READONLY | SEC_DEBUGGING,
+			       alignment);
 		  seek_next_seg = 1;
 		}
 	      fde->handled = 1;
+#endif
 	      if (fde->end_address == NULL)
 		{
 		  as_bad (_("open CFI at the end of file; missing .cfi_endproc directive"));
@@ -1984,10 +2043,12 @@ cfi_finish (void)
 	      output_fde (fde, cie, FALSE, first, alignment);
 	    }
 	}
-      while (seek_next_seg == 2);
+      while (SUPPORT_FRAME_LINKONCE && seek_next_seg == 2);
 
+#if SUPPORT_FRAME_LINKONCE
       for (fde = all_fde_data; fde ; fde = fde->next)
         fde->handled = 0;
+#endif
     }
 }
 

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: gas -Werror compilation break  [Re: [patch ld bfd gas]: Handle linkonce for cfi generated debug_frame and eh_frame data]
  2011-05-05  0:29           ` Dave Korn
  2011-05-05  8:45             ` Alan Modra
@ 2011-05-05  8:50             ` Kai Tietz
  1 sibling, 0 replies; 12+ messages in thread
From: Kai Tietz @ 2011-05-05  8:50 UTC (permalink / raw)
  To: Dave Korn
  Cc: Nick Clifton, Kai Tietz, H.J. Lu, Binutils, Alan Modra, Jan Kratochvil

----- Original Message -----
From: "Dave Korn" <dave.korn.cygwin@gmail.com>
To: "Jan Kratochvil" <jan.kratochvil@redhat.com>
Cc: "Kai Tietz" <ktietz@redhat.com>, "Nick Clifton" <nickc@redhat.com>, "Kai Tietz" <ktietz70@googlemail.com>, "H.J. Lu" <hjl.tools@gmail.com>, "Binutils" <binutils@sourceware.org>, "Alan Modra" <amodra@gmail.com>
Sent: Thursday, May 5, 2011 2:29:20 AM
Subject: Re: gas -Werror compilation break  [Re: [patch ld bfd gas]: Handle linkonce for cfi generated debug_frame and eh_frame data]

On 27/04/2011 21:34, Jan Kratochvil wrote:
> Hi Kai,
> 
> On Tue, 26 Apr 2011 17:30:08 +0200, Nick Clifton wrote:
>>>>>  ChangeLog gas/
>>>>>  2011-04-18  Kai Tietz
>>>>>
>>>>>         * dw2gencfi.c (dwcfi_seg_list): New struct.
>>>>>         (dwcfi_hash): New static hash variable.
>>>>>         (get_debugseg_name): New.
>>>>>         (alloc_debugseg_item): New.
>>>>>         (make_debug_seg): New.
>>>>>         (dwcfi_hash_insert): New.
>>>>>         (dwcfi_hash_find): New.
>>>>>         (dwcfi_hash_find_or_make): New.
>>>>>         (cfi_insn_data): New member cur_seg.
>>>>>         (cie_entry): Likewise.
>>>>>         (fde_entry): New cseg and handled members.
>>>>>         (alloc_fde_entry): Initialize cseg member.
>>>>>         (alloc_cfi_insn_data): Initialize cur_seg member.
>>>>>         (dot_cfi_sections): Compare for beginning of
>>>>>         section names via strncmp.
>>>>>         (get_cfi_seg): New.
>>>>>         (cfi_finish): Treat link-once sections.
>>>>>         (is_now_linkonce_segment): New local helper.
>>>>>         (output_cie): Ignore cie entries not member of current
>>>>>         segment.
>>>>>         (output_fde): Likewise.
>>>>>         (select_cie_for_fde): Likewise.
>>>>>         (cfi_change_reg_numbers): Add new argument for current segment
>>>>>         and ignore insn elements, if not part of current segment.
>>>>>         * ehopt.c (get_cie_info): Use strncmp for
>>>>>         section name matching.
>>>>>         (heck_eh_frame): Likewise.
> 
> dw2gencfi.c:1870:8: error: variable ‘cfi_seg’ set but not used [-Werror=unused-but-set-variable]
> gcc-4.6.0-5.fc15.x86_64
> 
> Could you please provide a fix?

  This fixes the breakage, but doesn't address the issue that it looks to me
like there's an omitted call to md_fix_up_eh_frame() after the second
invocation of get_cfi_seg().

gas/ChangeLog:

	* dw2gencfi.c (dwcfi_hash): Wrap in #ifdef md_fix_up_eh_frame.
	(get_debugseg_name): Likewise.
	(alloc_debugseg_item): Likewise.
	(make_debug_seg): Likewise.
	(dwcfi_hash_insert): Likewise.
	(dwcfi_hash_find): Likewise.
	(dwcfi_hash_find_or_make): Likewise.
	(get_cfi_seg): Likewise.
	(cfi_finish): Wrap references to cfi_seg and calls to get_cfi_seg()
	in #ifdef md_fix_up_eh_frame likewise.

  Verified that it fixes the build on i686-pc-cygwin and
x86_64-unknown-linux-gnu, OK to install?

    cheers,
      DaveK

Hmm, I see the issue that cfi_seg might be just set, but not used. This can be fixed by simply adding - after setting of cfi_seg - an check for if (!cfi_seg) abort ();.  This check is superflous as cfi_seg never can be NULL, but it silence this warning.
The missing md_fix_up_eh_frame is used, as it was done in original code. Here just on case (IIRC it is the debug_frame one) uses it.  It might be necessary to add it here for the "eh_frame" case too. But I don't see actual a reason to add all this #ifdef guarding you do.

Regards,
Kai

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: gas -Werror compilation break  [Re: [patch ld bfd gas]: Handle linkonce for cfi generated debug_frame and eh_frame data]
  2011-05-05  8:45             ` Alan Modra
@ 2011-05-05 13:21               ` Alan Modra
  2011-05-06 17:58                 ` Dave Korn
  0 siblings, 1 reply; 12+ messages in thread
From: Alan Modra @ 2011-05-05 13:21 UTC (permalink / raw)
  To: Binutils

On Thu, May 05, 2011 at 06:14:54PM +0930, Alan Modra wrote:
> I'll be committing the following instead, which I wrote a couple of
> days ago but didn't get around to installing, or even writing a
> changelog.

Now committed with this ChangeLog entry.

	* dw2gencfi.c (SUPPORT_FRAME_LINKONCE): Define.  Use throughout
	file to conditionally compile code added 2011-04-26.
	(cfi_change_reg_numbers): Add ATTRIBUTE_UNUSED on params only used
	when SUPPORT_FRAME_LINKONCE.
	(get_cfi_seg): Likewise.  Reintroduce old code for when not
	SUPPORT_FRAME_LINKONCE.
	(cfi_finish): Move get_cfi_seg calls out of loop when not
	SUPPORT_FRAME_LINKONCE.  Avoid unused var warning.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: gas -Werror compilation break  [Re: [patch ld bfd gas]: Handle linkonce for cfi generated debug_frame and eh_frame data]
  2011-05-05 13:21               ` Alan Modra
@ 2011-05-06 17:58                 ` Dave Korn
  2011-05-07  2:53                   ` Alan Modra
  0 siblings, 1 reply; 12+ messages in thread
From: Dave Korn @ 2011-05-06 17:58 UTC (permalink / raw)
  To: Binutils

On 05/05/2011 14:21, Alan Modra wrote:
> On Thu, May 05, 2011 at 06:14:54PM +0930, Alan Modra wrote:
>> I'll be committing the following instead, which I wrote a couple of
>> days ago but didn't get around to installing, or even writing a
>> changelog.
> 
> Now committed with this ChangeLog entry.
> 
> 	* dw2gencfi.c (SUPPORT_FRAME_LINKONCE): Define.  Use throughout
> 	file to conditionally compile code added 2011-04-26.
> 	(cfi_change_reg_numbers): Add ATTRIBUTE_UNUSED on params only used
> 	when SUPPORT_FRAME_LINKONCE.
> 	(get_cfi_seg): Likewise.  Reintroduce old code for when not
> 	SUPPORT_FRAME_LINKONCE.
> 	(cfi_finish): Move get_cfi_seg calls out of loop when not
> 	SUPPORT_FRAME_LINKONCE.  Avoid unused var warning.
> 

  Hmm, still getting this:

> /n/10/davek/binutils/src.clean/gas/dw2gencfi.c: In function 'cfi_finish':
> /n/10/davek/binutils/src.clean/gas/dw2gencfi.c:1903:17: error: variable 'ccseg' set but not used [-Werror=unused-but-set-variable]
> cc1: all warnings being treated as errors
> 
> make[4]: *** [dw2gencfi.o] Error 1

... on x86_64-linux with rev 1.53 of dw2gencfi.c.

    cheers,
      DaveK

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: gas -Werror compilation break  [Re: [patch ld bfd gas]: Handle linkonce for cfi generated debug_frame and eh_frame data]
  2011-05-06 17:58                 ` Dave Korn
@ 2011-05-07  2:53                   ` Alan Modra
  0 siblings, 0 replies; 12+ messages in thread
From: Alan Modra @ 2011-05-07  2:53 UTC (permalink / raw)
  To: Dave Korn; +Cc: Binutils

On Fri, May 06, 2011 at 06:57:27PM +0100, Dave Korn wrote:
>   Hmm, still getting this:
> 
> > /n/10/davek/binutils/src.clean/gas/dw2gencfi.c: In function 'cfi_finish':
> > /n/10/davek/binutils/src.clean/gas/dw2gencfi.c:1903:17: error: variable 'ccseg' set but not used [-Werror=unused-but-set-variable]
> > cc1: all warnings being treated as errors

Caught out by my habit of compiling with -fno-inline.  These warnings
are a bit of a pain when you want to reduce struct size as I did with
#if SUPPORT_FRAME_LINKONCE.

Let's clean up some of the conditional compilation.  Shame on me for
not doing this properly in the first place.  SET_CUR_SEG in the
!SUPPORT_FRAME_LINKONCE case is a little tricky since you need to
reference the rhs to ensure no warnings about is_now_linkonce_segment
being unused, but don't want gcc to actually call (or emit) the
function.

	* dw2gencfi.c (CUR_SEG, SET_CUR_SEG, HANDLED, SET_HANDLED): Define.
	Use throughout in place of #if SUPPORT_FRAME_LINKONCE.
	(struct fde_entry): Rename cseg to cur_seg.
	(cfi_change_reg_numbers): Remove ATTRIBUTE_UNUSED.
	(get_cfi_seg): Likewise.  Use if (SUPPORT_FRAME_LINKONCE) rather
	that #if SUPPORT_FRAME_LINKONCE.
	(cfi_finish): Likewise.

Index: gas/dw2gencfi.c
===================================================================
RCS file: /cvs/src/src/gas/dw2gencfi.c,v
retrieving revision 1.53
diff -u -p -r1.53 dw2gencfi.c
--- gas/dw2gencfi.c	5 May 2011 13:11:36 -0000	1.53
+++ gas/dw2gencfi.c	7 May 2011 02:30:31 -0000
@@ -83,6 +83,17 @@
 #endif
 
 #if SUPPORT_FRAME_LINKONCE
+#define CUR_SEG(structp) structp->cur_seg
+#define SET_CUR_SEG(structp, seg) structp->cur_seg = seg 
+#define HANDLED(structp) structp->handled
+#define SET_HANDLED(structp, val) structp->handled = val
+#else
+#define CUR_SEG(structp) NULL
+#define SET_CUR_SEG(structp, seg) (void) (0 && seg)
+#define HANDLED(structp) 0
+#define SET_HANDLED(structp, val) (void) (0 && val)
+#endif
+
 /* Private segment collection list.  */
 struct dwcfi_seg_list
 {
@@ -232,7 +243,6 @@ dwcfi_hash_find_or_make (segT cseg, cons
 
   return item;
 }
-#endif
 
 /* ??? Share this with dwarf2cfg.c.  */
 #ifndef TC_DWARF2_EMIT_OFFSET
@@ -302,7 +312,7 @@ struct fde_entry
 {
   struct fde_entry *next;
 #if SUPPORT_FRAME_LINKONCE
-  segT cseg;
+  segT cur_seg;
 #endif
   symbolS *start_address;
   symbolS *end_address;
@@ -371,10 +381,8 @@ alloc_fde_entry (void)
   frchain_now->frch_cfi_data->cur_fde_data = fde;
   *last_fde_data = fde;
   last_fde_data = &fde->next;
-#if SUPPORT_FRAME_LINKONCE
-  fde->cseg = is_now_linkonce_segment ();
-  fde->handled = 0;
-#endif
+  SET_CUR_SEG (fde, is_now_linkonce_segment ());
+  SET_HANDLED (fde, 0);
   fde->last = &fde->data;
   fde->return_column = DWARF2_DEFAULT_RETURN_COLUMN;
   fde->per_encoding = DW_EH_PE_omit;
@@ -398,9 +406,7 @@ alloc_cfi_insn_data (void)
 
   *cur_fde_data->last = insn;
   cur_fde_data->last = &insn->next;
-#if SUPPORT_FRAME_LINKONCE
-  insn->cur_seg = is_now_linkonce_segment ();
-#endif
+  SET_CUR_SEG (insn, is_now_linkonce_segment ());
   return insn;
 }
 
@@ -1569,10 +1575,8 @@ output_cie (struct cie_entry *cie, bfd_b
     {
       for (i = cie->first; i != cie->last; i = i->next)
         {
-#if SUPPORT_FRAME_LINKONCE
-	  if (i->cur_seg != cie->cur_seg)
+	  if (CUR_SEG (i) != CUR_SEG (cie))
 	    continue;
-#endif
 	  output_cfi_insn (i);
 	}
     }
@@ -1682,9 +1686,7 @@ output_fde (struct fde_entry *fde, struc
     }
 
   for (; first; first = first->next)
-#if SUPPORT_FRAME_LINKONCE
-    if (first->cur_seg == fde->cseg)
-#endif
+    if (CUR_SEG (first) == CUR_SEG (fde))
       output_cfi_insn (first);
 
   frag_align (align, DW_CFA_nop, 0);
@@ -1700,10 +1702,8 @@ select_cie_for_fde (struct fde_entry *fd
 
   for (cie = cie_root; cie; cie = cie->next)
     {
-#if SUPPORT_FRAME_LINKONCE
-      if (cie->cur_seg != fde->cseg)
+      if (CUR_SEG (cie) != CUR_SEG (fde))
 	continue;
-#endif
       if (cie->return_column != fde->return_column
 	  || cie->signal_frame != fde->signal_frame
 	  || cie->per_encoding != fde->per_encoding
@@ -1802,9 +1802,7 @@ select_cie_for_fde (struct fde_entry *fd
   cie = (struct cie_entry *) xmalloc (sizeof (struct cie_entry));
   cie->next = cie_root;
   cie_root = cie;
-#if SUPPORT_FRAME_LINKONCE
-  cie->cur_seg = fde->cseg;
-#endif
+  SET_CUR_SEG (cie, CUR_SEG (fde));
   cie->return_column = fde->return_column;
   cie->signal_frame = fde->signal_frame;
   cie->per_encoding = fde->per_encoding;
@@ -1829,14 +1827,12 @@ select_cie_for_fde (struct fde_entry *fd
 
 #ifdef md_reg_eh_frame_to_debug_frame
 static void
-cfi_change_reg_numbers (struct cfi_insn_data *insn, segT ccseg ATTRIBUTE_UNUSED)
+cfi_change_reg_numbers (struct cfi_insn_data *insn, segT ccseg)
 {
   for (; insn; insn = insn->next)
     {
-#if SUPPORT_FRAME_LINKONCE
-      if (insn->cur_seg != ccseg)
+      if (CUR_SEG (insn) != ccseg)
         continue;
-#endif
       switch (insn->insn)
 	{
 	case DW_CFA_advance_loc:
@@ -1878,20 +1874,22 @@ cfi_change_reg_numbers (struct cfi_insn_
 #endif
 
 static segT
-get_cfi_seg (segT cseg ATTRIBUTE_UNUSED,
-	     const char *base, flagword flags, int align)
+get_cfi_seg (segT cseg, const char *base, flagword flags, int align)
 {
-#if SUPPORT_FRAME_LINKONCE
-  struct dwcfi_seg_list *l;
+  if (SUPPORT_FRAME_LINKONCE)
+    {
+      struct dwcfi_seg_list *l;
 
-  l = dwcfi_hash_find_or_make (cseg, base, flags);
+      l = dwcfi_hash_find_or_make (cseg, base, flags);
 
-  cseg = l->seg;
-  subseg_set (cseg, l->subseg);
-#else
-  cseg = subseg_new (base, 0);
-  bfd_set_section_flags (stdoutput, cseg, flags);
-#endif
+      cseg = l->seg;
+      subseg_set (cseg, l->subseg);
+    }
+  else
+    {
+      cseg = subseg_new (base, 0);
+      bfd_set_section_flags (stdoutput, cseg, flags);
+    }
   record_alignment (cseg, align);
   return cseg;
 }
@@ -1914,18 +1912,19 @@ cfi_finish (void)
       save_flag_traditional_format = flag_traditional_format;
       flag_traditional_format = 1;
 
-#if !SUPPORT_FRAME_LINKONCE
-      /* Open .eh_frame section.  */
-      cfi_seg = get_cfi_seg (NULL, ".eh_frame",
-			     SEC_ALLOC | SEC_LOAD | SEC_DATA
-			     | DWARF2_EH_FRAME_READ_ONLY,
-			     EH_FRAME_ALIGNMENT);
+      if (!SUPPORT_FRAME_LINKONCE)
+	{
+	  /* Open .eh_frame section.  */
+	  cfi_seg = get_cfi_seg (NULL, ".eh_frame",
+				 (SEC_ALLOC | SEC_LOAD | SEC_DATA
+				  | DWARF2_EH_FRAME_READ_ONLY),
+				 EH_FRAME_ALIGNMENT);
 #ifdef md_fix_up_eh_frame
-      md_fix_up_eh_frame (cfi_seg);
+	  md_fix_up_eh_frame (cfi_seg);
 #else
-      (void) cfi_seg;
-#endif
+	  (void) cfi_seg;
 #endif
+	}
 
       do
         {
@@ -1941,31 +1940,32 @@ cfi_finish (void)
 
 	  for (fde = all_fde_data; fde ; fde = fde->next)
 	    {
-#if SUPPORT_FRAME_LINKONCE
-	      if (fde->handled != 0)
-	        continue;
-	      if (seek_next_seg && fde->cseg != ccseg)
-	        {
-		  seek_next_seg = 2;
-		  continue;
-		}
-	      if (!seek_next_seg)
-	        {
-		  ccseg = fde->cseg;
-		  /* Open .eh_frame section.  */
-		  cfi_seg = get_cfi_seg (ccseg, ".eh_frame",
-					 SEC_ALLOC | SEC_LOAD | SEC_DATA
-					 | DWARF2_EH_FRAME_READ_ONLY,
-					 EH_FRAME_ALIGNMENT);
+	      if (SUPPORT_FRAME_LINKONCE)
+		{
+		  if (HANDLED (fde))
+		    continue;
+		  if (seek_next_seg && CUR_SEG (fde) != ccseg)
+		    {
+		      seek_next_seg = 2;
+		      continue;
+		    }
+		  if (!seek_next_seg)
+		    {
+		      ccseg = CUR_SEG (fde);
+		      /* Open .eh_frame section.  */
+		      cfi_seg = get_cfi_seg (ccseg, ".eh_frame",
+					     (SEC_ALLOC | SEC_LOAD | SEC_DATA
+					      | DWARF2_EH_FRAME_READ_ONLY),
+					     EH_FRAME_ALIGNMENT);
 #ifdef md_fix_up_eh_frame
-		  md_fix_up_eh_frame (cfi_seg);
+		      md_fix_up_eh_frame (cfi_seg);
 #else
-		  (void) cfi_seg;
+		      (void) cfi_seg;
 #endif
-		  seek_next_seg = 1;
+		      seek_next_seg = 1;
+		    }
+		  SET_HANDLED (fde, 1);
 		}
-	      fde->handled = 1;
-#endif
 
 	      if (fde->end_address == NULL)
 		{
@@ -1980,10 +1980,9 @@ cfi_finish (void)
 	}
       while (SUPPORT_FRAME_LINKONCE && seek_next_seg == 2);
 
-#if SUPPORT_FRAME_LINKONCE
-      for (fde = all_fde_data; fde ; fde = fde->next)
-        fde->handled = 0;
-#endif
+      if (SUPPORT_FRAME_LINKONCE)
+	for (fde = all_fde_data; fde ; fde = fde->next)
+	  SET_HANDLED (fde, 0);
 
       flag_traditional_format = save_flag_traditional_format;
     }
@@ -1992,11 +1991,11 @@ cfi_finish (void)
     {
       int alignment = ffs (DWARF2_ADDR_SIZE (stdoutput)) - 1;
 
-#if !SUPPORT_FRAME_LINKONCE
-      get_cfi_seg (NULL, ".debug_frame",
-		   SEC_READONLY | SEC_DEBUGGING,
-		   alignment);
-#endif
+      if (!SUPPORT_FRAME_LINKONCE)
+	get_cfi_seg (NULL, ".debug_frame",
+		     SEC_READONLY | SEC_DEBUGGING,
+		     alignment);
+
       do
         {
 	  ccseg = NULL;
@@ -2011,25 +2010,26 @@ cfi_finish (void)
 
 	  for (fde = all_fde_data; fde ; fde = fde->next)
 	    {
-#if SUPPORT_FRAME_LINKONCE
-	      if (fde->handled != 0)
-	        continue;
-	      if (seek_next_seg && fde->cseg != ccseg)
-	        {
-		  seek_next_seg = 2;
-		  continue;
-		}
-	      if (!seek_next_seg)
-	        {
-		  ccseg = fde->cseg;
-		  /* Open .debug_frame section.  */
-		  get_cfi_seg (ccseg, ".debug_frame",
-			       SEC_READONLY | SEC_DEBUGGING,
-			       alignment);
-		  seek_next_seg = 1;
+	      if (SUPPORT_FRAME_LINKONCE)
+		{
+		  if (HANDLED (fde))
+		    continue;
+		  if (seek_next_seg && CUR_SEG (fde) != ccseg)
+		    {
+		      seek_next_seg = 2;
+		      continue;
+		    }
+		  if (!seek_next_seg)
+		    {
+		      ccseg = CUR_SEG (fde);
+		      /* Open .debug_frame section.  */
+		      get_cfi_seg (ccseg, ".debug_frame",
+				   SEC_READONLY | SEC_DEBUGGING,
+				   alignment);
+		      seek_next_seg = 1;
+		    }
+		  SET_HANDLED (fde, 1);
 		}
-	      fde->handled = 1;
-#endif
 	      if (fde->end_address == NULL)
 		{
 		  as_bad (_("open CFI at the end of file; missing .cfi_endproc directive"));
@@ -2045,10 +2045,9 @@ cfi_finish (void)
 	}
       while (SUPPORT_FRAME_LINKONCE && seek_next_seg == 2);
 
-#if SUPPORT_FRAME_LINKONCE
-      for (fde = all_fde_data; fde ; fde = fde->next)
-        fde->handled = 0;
-#endif
+      if (SUPPORT_FRAME_LINKONCE)
+	for (fde = all_fde_data; fde ; fde = fde->next)
+	  SET_HANDLED (fde, 0);
     }
 }
 
-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2011-05-07  2:53 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-18  9:34 [patch ld bfd gas]: Handle linkonce for cfi generated debug_frame and eh_frame data Kai Tietz
2011-04-18 12:43 ` H.J. Lu
2011-04-18 20:04   ` Kai Tietz
2011-04-24 10:20     ` Kai Tietz
2011-04-26 15:29       ` Nick Clifton
2011-04-27 20:35         ` gas -Werror compilation break [Re: [patch ld bfd gas]: Handle linkonce for cfi generated debug_frame and eh_frame data] Jan Kratochvil
2011-05-05  0:29           ` Dave Korn
2011-05-05  8:45             ` Alan Modra
2011-05-05 13:21               ` Alan Modra
2011-05-06 17:58                 ` Dave Korn
2011-05-07  2:53                   ` Alan Modra
2011-05-05  8:50             ` Kai Tietz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).