public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Cary Coutant <ccoutant@gmail.com>
To: "H.J. Lu" <hjl.tools@gmail.com>
Cc: Binutils <binutils@sourceware.org>
Subject: Re: [PATCH] elfcpp: Add Sym::Sym(unsigned char*) constructor
Date: Sat, 19 Dec 2020 11:59:25 -0800	[thread overview]
Message-ID: <CAJimCsGYKZiyxHXMmoend0g3QgGDw=SoYchDAbJu77cAQxU55g@mail.gmail.com> (raw)
In-Reply-To: <20201219145718.171683-1-hjl.tools@gmail.com>

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);
     }

(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
>

  reply	other threads:[~2020-12-19 19:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-19 14:57 H.J. Lu
2020-12-19 19:59 ` Cary Coutant [this message]
2020-12-19 20:12   ` H.J. Lu
2020-12-19 21:02     ` Cary Coutant
2020-12-19 21:31       ` [PATCH] gold: Move sym declaration just before use H.J. Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAJimCsGYKZiyxHXMmoend0g3QgGDw=SoYchDAbJu77cAQxU55g@mail.gmail.com' \
    --to=ccoutant@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=hjl.tools@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).