This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] don't include symbols from S_ATTR_NO_TOC sections in mach-o canonical symtab output
- From: Tristan Gingold <gingold at adacore dot com>
- To: Nathan Froyd <froydnj at mozilla dot com>
- Cc: binutils at sourceware dot org
- Date: Mon, 4 Nov 2013 10:18:00 +0100
- Subject: Re: [PATCH] don't include symbols from S_ATTR_NO_TOC sections in mach-o canonical symtab output
- Authentication-results: sourceware.org; auth=none
- References: <1383069256-19868-1-git-send-email-froydnj at mozilla dot com> <1383069256-19868-2-git-send-email-froydnj at mozilla dot com>
On Oct 29, 2013, at 6:54 PM, Nathan Froyd <froydnj@mozilla.com> wrote:
> Hi,
>
> Generating static library archives with binutils and comparing them with
> archives produced by Apple's tools reveals one significant difference:
> those produced by Apple's tools are significantly smaller. binutils
> includes many ${SYMBOL_NAME}.eh symbols in the archive table of contents,
> whereas Apple's tools do not.
>
> This difference is due to the .eh symbols living in the .eh_frame section,
> which is tagged with the Mach-O section flag S_ATTR_NO_TOC. This flag
> instructs the archiver to not include symbols from such a section in the
> table of contents for an archive.
>
> The patch below changes bfd_mach_o_canonicalize_symtab to respect this flag.
>
> Tested on x86_64-apple-darwin11, no regressions. OK to checkin?
Yes, this is OK.
(Interesting to know that GNU ar is used on Darwin :-)
Tristan.
>
> -Nathan
>
> * mach-o.c (bfd_mach_o_canonicalize_symtab): Respect the
> BFD_MACH_O_S_ATTR_NO_TOC flag on symbol sections.
> ---
> bfd/mach-o.c | 21 ++++++++++++++++-----
> 1 file changed, 16 insertions(+), 5 deletions(-)
>
> diff --git a/bfd/mach-o.c b/bfd/mach-o.c
> index 32e48ac..095afeb 100644
> --- a/bfd/mach-o.c
> +++ b/bfd/mach-o.c
> @@ -630,7 +630,7 @@ bfd_mach_o_canonicalize_symtab (bfd *abfd, asymbol **alocation)
> bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
> long nsyms = bfd_mach_o_count_symbols (abfd);
> bfd_mach_o_symtab_command *sym = mdata->symtab;
> - unsigned long j;
> + unsigned long i, j;
>
> if (nsyms < 0)
> return nsyms;
> @@ -651,12 +651,23 @@ bfd_mach_o_canonicalize_symtab (bfd *abfd, asymbol **alocation)
>
> BFD_ASSERT (sym->symbols != NULL);
>
> - for (j = 0; j < sym->nsyms; j++)
> - alocation[j] = &sym->symbols[j].symbol;
> + for (i = 0, j = 0; j < sym->nsyms; j++)
> + {
> + bfd_mach_o_asymbol *asym = &sym->symbols[j];
> + if (asym->n_sect != 0)
> + {
> + bfd_mach_o_section *sect = mdata->sections[asym->n_sect-1];
> + if (sect->flags & BFD_MACH_O_S_ATTR_NO_TOC)
> + continue;
> + }
>
> - alocation[j] = NULL;
> + alocation[i] = &asym->symbol;
> + i++;
> + }
> +
> + alocation[i] = NULL;
>
> - return nsyms;
> + return i;
> }
>
> /* Create synthetic symbols for indirect symbols. */
> --
> 1.7.9.5
>