This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[arm,patch] Add Unwind index table sections


The patch below adds binutils support for the SHT_ARM_EXIDX, as defined by
 the ARM EABI.

Tested with cross to arm-none-eabi and bulding --enable-targets=all.
Ok?

Paul

2004-09-18  Paul Brook  <paul@codesourcery.com>

bfd/
 * elf32-arm.h (elf32_arm_fake_sections): New function.
 (is_unwind_section_name, elf32_arm_section_from_shdr): New functions.
 (elf_backend_fake_sections, elf_backend_section_from_shdr): Define.
binutils/
 * readelf.c (get_arm_section_type_name): New function.
 (get_section_type_name): Use it.
gas/
 * config/tc-arm.c (arm_elf_section_type): New function.
 (arm_elf_change_section): Set section link for exidx sections.
 * config/tc-arm.h (arm_elf_section_type): Add prototype.
 (md_elf_section_type): Define.
include/
 * elf/arm.h (SHT_ARM_EXIDX): Define.
 (ELF_STRING_ARM_unwind, ELF_STRING_ARM_unwind,
 ELF_STRING_ARM_unwind_once, ELF_STRING_ARM_unwind_info_once): Define.
 * emulparams/armelf.sh: Add unwinding table sections.

Index: bfd/elf32-arm.h
===================================================================
RCS file: /cvs/src/src/bfd/elf32-arm.h,v
retrieving revision 1.144
diff -u -p -r1.144 elf32-arm.h
--- bfd/elf32-arm.h 17 Sep 2004 12:34:54 -0000 1.144
+++ bfd/elf32-arm.h 18 Sep 2004 16:15:29 -0000
@@ -4235,6 +4235,8 @@ elf32_arm_reloc_type_class (const Elf_In
 
 static bfd_boolean elf32_arm_section_flags           (flagword *, const Elf_Internal_Shdr *);
 static void        elf32_arm_final_write_processing  (bfd *, bfd_boolean);
+static bfd_boolean elf32_arm_fake_sections (bfd *, Elf_Internal_Shdr *,
+         asection *);
 
 /* Set the right machine number for an Arm ELF file.  */
 
@@ -4254,6 +4256,66 @@ elf32_arm_final_write_processing (bfd *a
 }
 
 
+/* Return TRUE if this is an unwinding table entry.  */
+
+static bfd_boolean
+is_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name)
+{
+  size_t len1, len2;
+
+  len1 = sizeof (ELF_STRING_ARM_unwind) - 1;
+  len2 = sizeof (ELF_STRING_ARM_unwind_once) - 1;
+  return (strncmp (name, ELF_STRING_ARM_unwind, len1) == 0
+   || strncmp (name, ELF_STRING_ARM_unwind_once, len2) == 0);
+}
+
+
+/* Set the type and flags for an ARM section.  We do this by the
+   section name, which is a hack, but ought to work.  */
+
+static bfd_boolean
+elf32_arm_fake_sections (bfd * abfd, Elf_Internal_Shdr * hdr, asection * sec)
+{
+  const char * name;
+
+  name = bfd_get_section_name (abfd, sec);
+
+  if (is_unwind_section_name (abfd, name))
+    {
+      hdr->sh_type = SHT_ARM_EXIDX;
+      hdr->sh_flags |= SHF_LINK_ORDER;
+    }
+  return TRUE;
+}
+
+
+/* Handle an ARM specific section when reading an object file.  This
+   is called when elf.c finds a section with an unknown type.  */
+
+static bfd_boolean
+elf32_arm_section_from_shdr (bfd *abfd, Elf_Internal_Shdr * hdr,
+        const char *name)
+{
+  /* There ought to be a place to keep ELF backend specific flags, but
+     at the moment there isn't one.  We just keep track of the
+     sections by their name, instead.  Fortunately, the ABI gives
+     names for all the ARM specific sections, so we will probably get
+     away with this.  */
+  switch (hdr->sh_type)
+    {
+    case SHT_ARM_EXIDX:
+      break;
+
+    default:
+      return FALSE;
+    }
+
+  if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
+    return FALSE;
+
+  return TRUE;
+}
+
 /* Called for each symbol.  Builds a section map based on mapping symbols.
    Does not alter any of the symbols.  */
 
@@ -4424,6 +4486,8 @@ elf32_arm_write_section (bfd *output_bfd
 #define elf_backend_reloc_type_class  elf32_arm_reloc_type_class
 #define elf_backend_object_p   elf32_arm_object_p
 #define elf_backend_section_flags  elf32_arm_section_flags
+#define elf_backend_fake_sections  elf32_arm_fake_sections
+#define elf_backend_section_from_shdr  elf32_arm_section_from_shdr
 #define elf_backend_final_write_processing      elf32_arm_final_write_processing
 #define elf_backend_copy_indirect_symbol        elf32_arm_copy_indirect_symbol
 
Index: binutils/readelf.c
===================================================================
RCS file: /cvs/src/src/binutils/readelf.c,v
retrieving revision 1.252
diff -u -p -r1.252 readelf.c
--- binutils/readelf.c 12 Sep 2004 05:52:44 -0000 1.252
+++ binutils/readelf.c 18 Sep 2004 16:15:31 -0000
@@ -2404,6 +2404,19 @@ get_ia64_section_type_name (unsigned int
 }
 
 static const char *
+get_arm_section_type_name (unsigned int sh_type)
+{
+  switch (sh_type)
+    {
+    case SHT_ARM_EXIDX:
+      return "ARM_EXIDX";
+    default:
+      break;
+    }
+  return NULL;
+}
+
+static const char *
 get_section_type_name (unsigned int sh_type)
 {
   static char buff[32];
@@ -2453,6 +2466,9 @@ get_section_type_name (unsigned int sh_t
      case EM_IA_64:
        result = get_ia64_section_type_name (sh_type);
        break;
+     case EM_ARM:
+       result = get_arm_section_type_name (sh_type);
+       break;
      default:
        result = NULL;
        break;
Index: gas/config/tc-arm.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-arm.c,v
retrieving revision 1.177
diff -u -p -r1.177 tc-arm.c
--- gas/config/tc-arm.c 17 Sep 2004 12:34:58 -0000 1.177
+++ gas/config/tc-arm.c 18 Sep 2004 16:15:33 -0000
@@ -2903,6 +2960,11 @@ arm_elf_change_section (void)
 {
   flagword flags;
 
+  /* Link unlinked unwind index table section to the .text section.  */
+  if (elf_section_type (now_seg) == SHT_ARM_EXIDX
+      && elf_linked_to_section (now_seg) == NULL)
+    elf_linked_to_section (now_seg) = text_section;
+
   if (!SEG_NORMAL (now_seg))
     return;
 
@@ -2914,6 +2976,15 @@ arm_elf_change_section (void)
 
   mapstate = seg_info (now_seg)->tc_segment_info_data;
 }
+
+int
+arm_elf_section_type (const char * str, size_t len)
+{
+  if (len == 5 && strncmp (str, "exidx", 5) == 0)
+    return SHT_ARM_EXIDX;
+
+  return -1;
+}
 #else
 #define mapping_state(a)
 #endif /* OBJ_ELF */
Index: gas/config/tc-arm.h
===================================================================
RCS file: /cvs/src/src/gas/config/tc-arm.h,v
retrieving revision 1.22
diff -u -p -r1.22 tc-arm.h
--- gas/config/tc-arm.h 22 Apr 2004 09:49:03 -0000 1.22
+++ gas/config/tc-arm.h 18 Sep 2004 16:15:33 -0000
@@ -164,9 +164,13 @@ struct fix;
     }
 
 #ifdef OBJ_ELF
+
+int arm_elf_section_type (const char *, size_t);
+
 # define DWARF2_LINE_MIN_INSN_LENGTH  2
 # define obj_frob_symbol(sym, punt) armelf_frob_symbol ((sym), & (punt))
 # define md_elf_section_change_hook() arm_elf_change_section ()
+# define md_elf_section_type(str, len) arm_elf_section_type (str, len)
 # define GLOBAL_OFFSET_TABLE_NAME "_GLOBAL_OFFSET_TABLE_"
 # define LOCAL_LABEL_PREFIX   '.'
 # define TC_SEGMENT_INFO_TYPE   enum mstate
Index: include/elf/arm.h
===================================================================
RCS file: /cvs/src/src/include/elf/arm.h,v
retrieving revision 1.16
diff -u -p -r1.16 arm.h
--- include/elf/arm.h 17 Sep 2004 12:35:00 -0000 1.16
+++ include/elf/arm.h 18 Sep 2004 16:15:34 -0000
@@ -64,6 +64,9 @@
 #define STT_ARM_TFUNC      STT_LOPROC   /* A Thumb function.  */
 #define STT_ARM_16BIT      STT_HIPROC   /* A Thumb label.  */
 
+/* Additional section types.  */
+#define SHT_ARM_EXIDX 0x70000001
+
 /* ARM-specific values for sh_flags.  */
 #define SHF_ENTRYSECT      0x10000000   /* Section contains an entry point.  */
 #define SHF_COMDEF         0x80000000   /* Section may be multiply defined in the input to a link step.  */
@@ -157,5 +160,11 @@ END_RELOC_NUMBERS (R_ARM_max)
 
 /* The name of the note section used to identify arm variants.  */
 #define ARM_NOTE_SECTION ".note.gnu.arm.ident"
-     
+
+/* Special section names.  */
+#define ELF_STRING_ARM_unwind  ".ARM.exidx"
+#define ELF_STRING_ARM_unwind_info ".ARM.extab"
+#define ELF_STRING_ARM_unwind_once ".gnu.linkonce.armexidx."
+#define ELF_STRING_ARM_unwind_info_once ".gnu.linkonce.armextab."
+
 #endif /* _ELF_ARM_H */
Index: ld/emulparams/armelf.sh
===================================================================
RCS file: /cvs/src/src/ld/emulparams/armelf.sh,v
retrieving revision 1.12
diff -u -p -r1.12 armelf.sh
--- ld/emulparams/armelf.sh 9 Feb 2004 18:06:20 -0000 1.12
+++ ld/emulparams/armelf.sh 18 Sep 2004 16:15:35 -0000
@@ -10,6 +10,11 @@ OTHER_TEXT_SECTIONS='*(.glue_7t) *(.glue
 OTHER_BSS_SYMBOLS='__bss_start__ = .;'
 OTHER_BSS_END_SYMBOLS='_bss_end__ = . ; __bss_end__ = . ; __end__ = . ;'
 OTHER_SECTIONS='.note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }'
+OTHER_READONLY_SECTIONS="
+  .ARM.extab ${RELOCATING-0} : { *(.ARM.extab${RELOCATING+* .gnu.linkonce.armextab.*}) }
+  __exidx_start = .;
+  .ARM.exidx ${RELOCATING-0} : { *(.ARM.exidx${RELOCATING+* .gnu.linkonce.armexidx.*}) }
+  __exidx_end = .;"
 
 DATA_START_SYMBOLS='__data_start = . ;';
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]