From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8742 invoked by alias); 19 Nov 2004 15:49:07 -0000 Mailing-List: contact binutils-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sources.redhat.com Received: (qmail 8652 invoked from network); 19 Nov 2004 15:48:55 -0000 Received: from unknown (HELO mail.codesourcery.com) (65.74.133.9) by sourceware.org with SMTP; 19 Nov 2004 15:48:55 -0000 Received: (qmail 16271 invoked from network); 19 Nov 2004 15:48:54 -0000 Received: from localhost (HELO wren.home) (paul@127.0.0.1) by mail.codesourcery.com with SMTP; 19 Nov 2004 15:48:54 -0000 From: Paul Brook Organization: CodeSourcery To: binutils@sources.redhat.com Subject: Re: Don't use STT_ARM_TFUNC for final links Date: Fri, 19 Nov 2004 15:49:00 -0000 User-Agent: KMail/1.7.1 Cc: "Richard Earnshaw" , "Daniel Jacobowitz" References: <89A528FE6DB0FA44877BB2F05B8467180160F910@ZIPPY.Emea.Arm.com> In-Reply-To: <89A528FE6DB0FA44877BB2F05B8467180160F910@ZIPPY.Emea.Arm.com> MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_kXhnBiLCbOk/Qzk" Message-Id: <200411191548.52631.paul@codesourcery.com> X-SW-Source: 2004-11/txt/msg00290.txt.bz2 --Boundary-00=_kXhnBiLCbOk/Qzk Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Content-length: 1957 On Thursday 18 November 2004 20:03, Richard Earnshaw wrote: > > 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. > > It needs to be done for objects too. Without it, other toolchains can't > consume GAS assembled objects that claim to conform to the EABI. > > There's no reason why the tricks shouldn't work on objects, so I think > it should be done there too. > > As to the issue of backward compatibility, there shouldn't be a problem > in binutils, they will just do the appropriate transformation when > reading in object files. As for other tools, then I think they are just > going to have to get used to the new form. It is better that functions > really are tagged with STT_FUNC rather than a machine-dependent value, > and Thumb-ness really isn't that special. The attached patch does this. I pushed the transformation down into bfd_swap_symbol_{in,out} so that objcopy works. I had to make this change unconditionally because objcopy does not set the EABI version in e_flags until after the symbol table has been written out. This means and ABI change for thumb objects. New binutils/BFD will transparently handle both new and old format symbol tables. Tested with cross to arm-none-eabi, and light testing on arm-linux. Ok? Paul 2004-11-19 Paul Brook bfd/ * elf32-arm.c (elf32_arm_swap_symbol_in): New function. (elf32_arm_swap_symbol_out): New function. (elf32_arm_size_info): Add. (elf_backend_size_info): Define. ld/ * testsuite/ld-arm/mixed-lib.sym: Update for THUMB_FUNC change. --Boundary-00=_kXhnBiLCbOk/Qzk Content-Type: text/x-diff; charset="iso-8859-1"; name="patch.thumb_eabi" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="patch.thumb_eabi" Content-length: 3994 Index: bfd/elf32-arm.c =================================================================== RCS file: /cvs/src/src/bfd/elf32-arm.c,v retrieving revision 1.10 diff -u -p -r1.10 elf32-arm.c --- bfd/elf32-arm.c 19 Nov 2004 11:58:02 -0000 1.10 +++ bfd/elf32-arm.c 19 Nov 2004 14:34:15 -0000 @@ -5662,6 +5662,82 @@ elf32_arm_symbol_processing (bfd *abfd A elfsym->symbol.flags |= BSF_FUNCTION; } + +/* Mangle thumb function symbols as we read them in. */ + +static void +elf32_arm_swap_symbol_in (bfd * abfd, + const void *psrc, + const void *pshn, + Elf_Internal_Sym *dst) +{ + bfd_elf32_swap_symbol_in (abfd, psrc, pshn, dst); + + /* New EABI objects mark thumb function symbols by setting the low bit of + the address. Turn these into STT_ARM_TFUNC. */ + if (ELF_ST_TYPE (dst->st_info) == STT_FUNC + && (dst->st_value & 1)) + { + dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_ARM_TFUNC); + dst->st_value &= ~(bfd_vma) 1; + } +} + + +/* Mangle thumb function symbols as we write them out. */ + +static void +elf32_arm_swap_symbol_out (bfd *abfd, + const Elf_Internal_Sym *src, + void *cdst, + void *shndx) +{ + Elf_Internal_Sym newsym; + + /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit + of the address set, as per the new EABI. We do this unconditionally + because objcopy does not set the elf header flags until after + it writes out the symbol table. */ + if (ELF_ST_TYPE (src->st_info) == STT_ARM_TFUNC) + { + newsym = *src; + newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC); + newsym.st_value |= 1; + + src = &newsym; + } + bfd_elf32_swap_symbol_out (abfd, src, cdst, shndx); +} + +/* We use this to override swap_symbol_in and swap_symbol_out. */ +const struct elf_size_info elf32_arm_size_info = { + sizeof (Elf32_External_Ehdr), + sizeof (Elf32_External_Phdr), + sizeof (Elf32_External_Shdr), + sizeof (Elf32_External_Rel), + sizeof (Elf32_External_Rela), + sizeof (Elf32_External_Sym), + sizeof (Elf32_External_Dyn), + sizeof (Elf_External_Note), + 4, + 1, + 32, 2, + ELFCLASS32, EV_CURRENT, + bfd_elf32_write_out_phdrs, + bfd_elf32_write_shdrs_and_ehdr, + bfd_elf32_write_relocs, + elf32_arm_swap_symbol_in, + elf32_arm_swap_symbol_out, + bfd_elf32_slurp_reloc_table, + bfd_elf32_slurp_symbol_table, + bfd_elf32_swap_dyn_in, + bfd_elf32_swap_dyn_out, + bfd_elf32_swap_reloc_in, + bfd_elf32_swap_reloc_out, + bfd_elf32_swap_reloca_in, + bfd_elf32_swap_reloca_out +}; + #define ELF_ARCH bfd_arch_arm #define ELF_MACHINE_CODE EM_ARM #ifdef __QNXTARGET__ @@ -5701,6 +5777,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_size_info elf32_arm_size_info #define elf_backend_can_refcount 1 #define elf_backend_can_gc_sections 1 Index: ld/testsuite/ld-arm/mixed-lib.sym =================================================================== RCS file: /cvs/src/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 19 Nov 2004 14:34:16 -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__ --Boundary-00=_kXhnBiLCbOk/Qzk--