[PATCH] elfcpp: Add Sym::Sym(unsigned char*) constructor

H.J. Lu hjl.tools@gmail.com
Sat Dec 19 14:57:18 GMT 2020


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



More information about the Binutils mailing list