This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GOLD: RFA: Fixing a coverty error for aarch64.cc


On 01/24/2017 01:07 AM, Cary Coutant wrote:
>> I would suggest letting the compiler handle computing
>> array sizes.  Something like the below.  (Build tested
>> only, feel free to run with it).   If you restore the
>> pointer with something like:
>>
>>  +  const static Insntype* ST_E_835769_INSNS = ST_E_843419_INSNS;
>>  +
>>  [...]
>>  -  // ST_E_835769 has the same stub template as ST_E_843419.
>>  -  install_insn_template_insns(ST_E_835769, ST_E_843419);
>>  +  install_insn_template(ST_E_835769);
>>
>> Then the compiler catches the problem:
> 
> I like your suggestion, but I'm curious whether this depends on any
> more recent features of C++ or the compiler. Would this work, say,
> with GCC 4.2 (which is close to the oldest compiler we claim will work
> for building gold)? Would it work with 4.6?

Yes, this is plain old C++98.  I've tried it with GCC 4.1, and it works.
Given the template usage, and given C++98/C++03, a couple restrictions apply.
For example, we wouldn't be able to pass a stack/local array to the
constructor.  (Restriction lifted in C++11.)

For a while now I've been thinking of adding a C++11 version of libiberty's
ARRAY_SIZE using the same mechanism to gdb.  C++11 (which 
GDB requires) makes it trivial:

 template <class T, size_t N>
 constexpr size_t
 array_size (const T (&array)[N]) noexcept
 { return N; }

Actually, this is exactly what one of C++17's std::size
overloads looks like.

It's doable in C++03 too, with the restriction mentioned
above, using a (widely known and used) sizeof trick.  (See below.)

> 
> I'm not averse to moving the line forward a bit, but I don't think I'd
> want to move it too far forward in one jump, or for the sake of one
> minor patch. (For example, at some point, I'd like to start using auto
> types and range-based for loops, among other not-all-that-new-anymore
> features.)

FWIW, gdb master requires C++11 nowadays, with GCC 4.8 as baseline.  We found
that the latest stable versions of all the major distros have that or
newer gcc version either as system compiler, or available as
optional package, and decided to make the jump.  It's well worth it, IMO.

I'm replying to this email with a small series of 3 patches.  The first
two are the just the same patch split in two, in case you want to
take the new macro without the template stuff.  The last one adds
a C++03 array_size to gold and uses it throughout.  I checked that this
all builds with g++ 5.3 and g++ 4.1, but I haven't run regression
tests.

Thanks,
Pedro Alves


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]