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]

RFA: Don't use STT_ARM_TFUNC for final links


This patch makes BFD write out Thumb symbols as STT_FUNC with the low bit
set, rather than STT_ARM_TFUNC.  It also simulates STT_ARM_TFUNC when
reading in symbols - in two places, one for the linker and the other for the
BFD symbol table interface.

I made this change only for final links because it's less of a compatibility
issue than for relocatable output.  For EABI objects, presumably we should
do the same.  For non-EABI objects, I'm not sure if it should be changed or
left alone; I have no idea what other tools are affected.  However, since
dynamic objects containing Thumb symbols did not work properly before my
last change, I see no reason to conditionalize it.

No changes to GDB are necessary, but it has to be rebuilt with the new BFD.
An older version of GDB will clip the lower bit but not mark the symbol as
Thumb.  I verified that a rebuilt GDB works; and I'll be posting glibc
patches to go with this shortly.

Only one testsuite change is necessary - this is why I added readelf-based
tests with my last patch.  OK?

-- 
Daniel Jacobowitz

2004-11-18  Daniel Jacobowitz  <dan@codesourcery.com>

	* ld-arm/mixed-lib.sym: Update for THUMB_FUNC change.

2004-11-18  Daniel Jacobowitz  <dan@codesourcery.com>

	* elf32-arm.c (elf32_arm_finish_dynamic_symbol): Clear STT_ARM_TFUNC
	for output.
	(elf32_arm_output_symbol_hook): Likewise.
	(elf32_arm_symbol_processing): Simulate STT_ARM_TFUNC on input.
	(elf32_arm_add_symbol_hook): New function, likewise.
	(elf_backend_add_symbol_hook): Define.

Index: ld/testsuite/ld-arm/mixed-lib.sym
===================================================================
RCS file: /big/fsf/rsync/src-cvs/src/ld/testsuite/ld-arm/mixed-lib.sym,v
retrieving revision 1.1
diff -u -p -r1.1 mixed-lib.sym
--- ld/testsuite/ld-arm/mixed-lib.sym	17 Nov 2004 17:50:27 -0000	1.1
+++ ld/testsuite/ld-arm/mixed-lib.sym	17 Nov 2004 19:43:55 -0000
@@ -3,7 +3,7 @@ Symbol table for image:
   Num Buc:    Value  Size   Type   Bind Vis      Ndx Name
    ..  ..: ........     0  NOTYPE GLOBAL DEFAULT ABS _edata
    ..  ..: .......0    20    FUNC GLOBAL DEFAULT   6 lib_func1
-   ..  ..: .......0     2  THUMB_FUNC GLOBAL DEFAULT   6 lib_func2
+   ..  ..: .......1     2    FUNC GLOBAL DEFAULT   6 lib_func2
    ..  ..: ........     0  NOTYPE GLOBAL DEFAULT ABS _bss_end__
    ..  ..: ........     0  OBJECT GLOBAL DEFAULT ABS _DYNAMIC
    ..  ..: ........     0  NOTYPE GLOBAL DEFAULT ABS __bss_end__
Index: bfd/elf32-arm.c
===================================================================
RCS file: /big/fsf/rsync/src-cvs/src/bfd/elf32-arm.c,v
retrieving revision 1.9
diff -u -p -r1.9 elf32-arm.c
--- bfd/elf32-arm.c	17 Nov 2004 17:50:23 -0000	1.9
+++ bfd/elf32-arm.c	17 Nov 2004 19:39:43 -0000
@@ -4984,6 +4984,15 @@ elf32_arm_finish_dynamic_symbol (bfd * o
   htab = elf32_arm_hash_table (info);
   eh = (struct elf32_arm_link_hash_entry *) h;
 
+  /* Undo the internal STT_ARM_TFUNC representation when performing
+     a final link.  This will also be done in output_symbol_hook, but
+     that's too late to correct the entry in the dynamic symbol table.  */
+  if (!info->relocatable && ELF_ST_TYPE (sym->st_info) == STT_ARM_TFUNC)
+    {
+      sym->st_info = ELF_ST_INFO (ELF_ST_BIND (sym->st_info), STT_FUNC);
+      sym->st_value |= 1;
+    }
+
   if (h->plt.offset != (bfd_vma) -1)
     {
       asection * splt;
@@ -5514,7 +5523,8 @@ elf32_arm_section_from_shdr (bfd *abfd,
 }
 
 /* Called for each symbol.  Builds a section map based on mapping symbols.
-   Does not alter any of the symbols.  */
+   Also undoes the internal STT_ARM_TFUNC representation for non-relocatable
+   output.  */
 
 static bfd_boolean
 elf32_arm_output_symbol_hook (struct bfd_link_info *info,
@@ -5531,6 +5541,12 @@ elf32_arm_output_symbol_hook (struct bfd
   if (info->relocatable)
     return TRUE;
 
+  if (ELF_ST_TYPE (elfsym->st_info) == STT_ARM_TFUNC)
+    {
+      elfsym->st_info = ELF_ST_INFO (ELF_ST_BIND (elfsym->st_info), STT_FUNC);
+      elfsym->st_value |= 1;
+    }
+
   /* Only build a map if we need to byteswap code.  */
   globals = elf32_arm_hash_table (info);
   if (!globals->byteswap_code)
@@ -5658,8 +5674,46 @@ elf32_arm_symbol_processing (bfd *abfd A
 {
   elf_symbol_type *elfsym = (elf_symbol_type *) asym;
 
+  /* Mark STT_ARM_TFUNC input symbols as being functions, just
+     like STT_FUNC.  */
   if (ELF_ST_TYPE (elfsym->internal_elf_sym.st_info) == STT_ARM_TFUNC)
     elfsym->symbol.flags |= BSF_FUNCTION;
+
+  /* If the input symbol uses the modern EABI convention for marking
+     Thumb symbols, then pretend it used the GNU STT_ARM_TFUNC
+     convention.  */
+  if (ELF_ST_TYPE (elfsym->internal_elf_sym.st_info) == STT_FUNC
+      && (elfsym->internal_elf_sym.st_value & 1) != 0)
+    {
+      elfsym->internal_elf_sym.st_value &= ~ (bfd_vma) 1;
+      elfsym->symbol.value &= ~ (bfd_vma) 1;
+      elfsym->internal_elf_sym.st_info
+	= ELF_ST_INFO (ELF_ST_BIND (elfsym->internal_elf_sym.st_info),
+		       STT_ARM_TFUNC);
+    }
+}
+
+/* Hook called by the linker routine which adds symbols from an object
+   file.  We must simulate STT_ARM_TFUNC here.  */
+
+static bfd_boolean
+elf32_arm_add_symbol_hook (bfd *abfd ATTRIBUTE_UNUSED,
+			   struct bfd_link_info *info ATTRIBUTE_UNUSED,
+			   Elf_Internal_Sym *sym,
+			   const char **namep ATTRIBUTE_UNUSED,
+			   flagword *flagsp ATTRIBUTE_UNUSED,
+			   asection **secp ATTRIBUTE_UNUSED,
+			   bfd_vma *valp)
+{
+  if (ELF_ST_TYPE (sym->st_info) == STT_FUNC
+      && (sym->st_value & 1) != 0)
+    {
+      sym->st_value &= ~ (bfd_vma) 1;
+      *valp &= ~ (bfd_vma) 1;
+      sym->st_info = ELF_ST_INFO (ELF_ST_BIND (sym->st_info), STT_ARM_TFUNC);
+    }
+
+  return TRUE;
 }
 
 #define ELF_ARCH			bfd_arch_arm
@@ -5701,6 +5755,7 @@ elf32_arm_symbol_processing (bfd *abfd A
 #define elf_backend_final_write_processing      elf32_arm_final_write_processing
 #define elf_backend_copy_indirect_symbol        elf32_arm_copy_indirect_symbol
 #define elf_backend_symbol_processing		elf32_arm_symbol_processing
+#define elf_backend_add_symbol_hook		elf32_arm_add_symbol_hook
 
 #define elf_backend_can_refcount    1
 #define elf_backend_can_gc_sections 1


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