[PATCH] Use GCC LTO wrapper to get real symbols from LTO IR objects
H.J. Lu
hjl.tools@gmail.com
Tue Feb 11 01:23:00 GMT 2020
On Mon, Feb 10, 2020 at 3:02 PM Alan Modra <amodra@gmail.com> wrote:
>
> Wow, that's a lot of work to get proper symbol type. What happens if
Very true. I couldn't come up with a better solution without changing plugin
API.
> you run nm on a system where gcc isn't installed? Or where the lto
> version doesn't match?
I assume standard GCC installation directory layout like
PREFIX/libexec/gcc/TARGET/VERSION/liblto_plugin.so
PREFIX/libexec/gcc/TARGET/VERSION/lto-wrapper
and
PREFIX/bin/TARGET-gcc
or
PREFIX/bin/gcc
If there is no gcc nor lto-wrapper at expected location, no real
symbols will be used. If LTO version doesn't match, it is a
GCC installation problem.
> On Mon, Feb 10, 2020 at 01:31:16PM -0800, H.J. Lu wrote:
> > + gcc_name = bfd_malloc (length + target_length + sizeof ("gcc"));
> > + memcpy (gcc_name, real_name, length);
>
> No check of bfd_malloc return value before use.
Fixed.
> > + wrapper_name = bfd_malloc (length + sizeof ("lto-wrapper"));
> > + memcpy (wrapper_name, real_name, length);
>
> Again.
Fixed.
> > + real_syms = (asymbol **) xmalloc (real_symsize);
>
> xmalloc shouldn't be used in libbfd.
Fixed.
> > struct plugin_data_struct *plugin_data =
> > bfd_alloc (abfd, sizeof (plugin_data_struct));
>
> This also doesn't check for NULL, preexisting bug.
Fixed.
> > + int i;
> > +
> > + /* NB: LTO symbols are owned by LTO plugin. Create a copy so that we
> > + can use it in bfd_plugin_canonicalize_symtab. */
> > + copy_of_syms = bfd_alloc (abfd, nsyms * sizeof (*syms));
> > + memcpy (copy_of_syms, syms, nsyms * sizeof (*syms));
> > + for (i = 0; i < nsyms; i++)
> > + copy_of_syms[i].name = xstrdup (syms[i].name);
>
> xstrdup shouldn't be used in libbfd.
Fixed.
Here is the updated patch.
--
H.J.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Use-GCC-LTO-wrapper-to-get-real-symbols-from-LTO-IR-.patch
Type: text/x-patch
Size: 22184 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20200211/79d9c9cc/attachment.bin>
More information about the Binutils
mailing list