This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: ARM mapping symbols and --strip-unneeded
- From: "Richard Earnshaw (lists)" <Richard dot Earnshaw at arm dot com>
- To: Nick Clifton <nickc at redhat dot com>, Michael Weiser <michael at weiser dot dinsnail dot net>
- Cc: binutils at sourceware dot org
- Date: Tue, 28 Jun 2016 17:40:50 +0100
- Subject: Re: ARM mapping symbols and --strip-unneeded
- Authentication-results: sourceware.org; auth=none
- References: <20160626221336 dot GB1916 at weiser dot dinsnail dot net> <e7fff803-6244-4782-2768-6b301387aed8 at redhat dot com> <577132D2 dot 9090903 at arm dot com> <1aa007dc-68eb-2d6f-d731-561564a1e3da at redhat dot com>
On 28/06/16 13:22, Nick Clifton wrote:
> Hi Guys,
>
> On 27/06/16 15:06, Richard Earnshaw (lists) wrote:
>> And potentially for little-endian binaries as well. For example, they
>> might sometimes be needed to insert correct interworking veneers.
>
> Agreed - so this is what I have checked in. It makes sure that "strip
> --strip-unneeded" will not remove mapping symbols from any ARM object
> file (little endian or big endian), whilst still allowing them to be
> removed from executables and shared libraries.
>
> Cheers
> Nick
>
> bfd/ChangeLog
> 2016-06-28 Nick Clifton <nickc@redhat.com>
>
> * elf32-arm.c (elf32_arm_backend_symbol_processing): New
> function. Marks mapping symbols in object files as precious, so
> that strip will not remove them.
> (elf_backend_symbol_processing): Define.
>
>
> elf32-arm.c.patch
>
>
> diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
> index a7964c1..04e776c 100644
> --- a/bfd/elf32-arm.c
> +++ b/bfd/elf32-arm.c
> @@ -18266,6 +18266,24 @@ elf32_arm_copy_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUSED,
> return FALSE;
> }
>
> +/* Make sure that mapping symbols in object files are not removed via the
> + "strip --strip-unneeded" tool. These symbols are needed in order to
> + correctly generate interworking veneers, and for byte swapping code
> + regions. Once an object file has been linked, it is safe to remove the
> + symbols as they will no longer be needed. */
> +
> +static void
> +elf32_arm_backend_symbol_processing (bfd *abfd, asymbol *sym)
> +{
> + if (((abfd->flags & (EXEC_P | DYNAMIC)) == 0)
> + && sym->name != NULL
> + && sym->section != bfd_abs_section_ptr
> + && (strcmp (sym->name, "$a") == 0
> + || strcmp (sym->name, "$t") == 0
> + || strcmp (sym->name, "$d") == 0))
Might be safer to use strncmp (sym, type, 2) since 'extended' mapping
symbols can be produced by some tools.
Otherwise, it looks sensible to me.
> + sym->flags |= BSF_KEEP;
> +}
> +
> #undef elf_backend_copy_special_section_fields
> #define elf_backend_copy_special_section_fields elf32_arm_copy_special_section_fields
>
> @@ -18324,6 +18342,7 @@ elf32_arm_copy_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUSED,
> #define elf_backend_begin_write_processing elf32_arm_begin_write_processing
> #define elf_backend_add_symbol_hook elf32_arm_add_symbol_hook
> #define elf_backend_count_additional_relocs elf32_arm_count_additional_relocs
> +#define elf_backend_symbol_processing elf32_arm_backend_symbol_processing
>
> #define elf_backend_can_refcount 1
> #define elf_backend_can_gc_sections 1
>