[PATCH] elfcpp: Add Sym::Sym(unsigned char*) constructor
H.J. Lu
hjl.tools@gmail.com
Sat Dec 19 20:12:55 GMT 2020
On Sat, Dec 19, 2020 at 11:59 AM Cary Coutant <ccoutant@gmail.com> wrote:
>
> Does this patch fix the problem?
>
> --- a/gold/plugin.cc
> +++ b/gold/plugin.cc
> @@ -1397,8 +1397,8 @@ Sized_pluginobj<size,
> big_endian>::do_add_symbols(Symbol_table* symtab,
> {
> const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
> unsigned char symbuf[sym_size];
> - elfcpp::Sym<size, big_endian> sym(symbuf);
> elfcpp::Sym_write<size, big_endian> osym(symbuf);
> + elfcpp::Sym<size, big_endian> sym(symbuf);
>
> Plugin_recorder* recorder = parameters->options().plugins()->recorder();
> if (recorder != NULL)
>
> If not that, then how about this:
>
> --- a/gold/plugin.cc
> +++ b/gold/plugin.cc
> @@ -1397,7 +1397,6 @@ Sized_pluginobj<size,
> big_endian>::do_add_symbols(Symbol_table* symtab,
> {
> const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
> unsigned char symbuf[sym_size];
> - elfcpp::Sym<size, big_endian> sym(symbuf);
> elfcpp::Sym_write<size, big_endian> osym(symbuf);
>
> Plugin_recorder* recorder = parameters->options().plugins()->recorder();
> @@ -1480,6 +1479,7 @@ Sized_pluginobj<size,
> big_endian>::do_add_symbols(Symbol_table* symtab,
> osym.put_st_other(vis, 0);
> osym.put_st_shndx(shndx);
>
> + elfcpp::Sym<size, big_endian> sym(symbuf);
> this->symbols_[i] =
> symtab->add_from_pluginobj<size, big_endian>(this, name, ver, &sym);
> }
Both fixed the build. Here is the complete patch to fox GCC 11 build.
> (Sorry, I don't have GCC 11 available to test.)
>
> I don't think adding a new constructor is the right solution.
>
> -cary
>
> On Sat, Dec 19, 2020 at 6:57 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> >
> > GCC 11 failed to build gold at -O0 due to -Wmaybe-uninitialized change
> > in GCC 11:
> >
> > In addition, passing a pointer (or in C++, a reference) to an
> > uninitialized object to a const-qualified function argument is also
> > diagnosed by this warning. (-Wuninitialized is issued for built-in
> > functions known to read the object.) Annotating the function with
> > attribute access (none) indicates that the argument isn’t used to
> > access the object and avoids the warning (see Common Function Attributes).
> >
> > Add Sym::Sym(unsigned char*) constructor to support
> >
> > const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
> > unsigned char symbuf[sym_size];
> > elfcpp::Sym<size, big_endian> sym(symbuf);
> >
> > PR gold/27097
> > elfcpp.h (Sym::Sym(unsigned char*)): New.
> > ---
> > elfcpp/elfcpp.h | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> > diff --git a/elfcpp/elfcpp.h b/elfcpp/elfcpp.h
> > index 428ecb8935..5ed9711dfa 100644
> > --- a/elfcpp/elfcpp.h
> > +++ b/elfcpp/elfcpp.h
> > @@ -1533,6 +1533,10 @@ class Sym
> > : p_(reinterpret_cast<const internal::Sym_data<size>*>(p))
> > { }
> >
> > + Sym(unsigned char* p)
> > + : p_(reinterpret_cast<const internal::Sym_data<size>*>(p))
> > + { }
> > +
> > template<typename File>
> > Sym(File* file, typename File::Location loc)
> > : p_(reinterpret_cast<const internal::Sym_data<size>*>(
> > --
> > 2.29.2
> >
--
H.J.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr27097.patch
Type: text/x-patch
Size: 2310 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20201219/47cbbed0/attachment.bin>
More information about the Binutils
mailing list