Bug 27815 - gold fails to build with latest GCC
Summary: gold fails to build with latest GCC
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: 2.37
: P2 normal
Target Milestone: ---
Assignee: Alan Modra
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-05-03 17:58 UTC by Matheus Castanho
Modified: 2021-08-19 06:14 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matheus Castanho 2021-05-03 17:58:22 UTC
Building gold with upstream GCC started to fail after GCC commit:

commit d96db15967e78d7cecea3b1cf3169ceb924678ac
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Apr 28 17:46:01 2021 +0100

    libstdc++: Deprecate non-standard std::pair constructors [PR 99957]

gold/gc.h is using one of the deprecated std::pair constructors to create an empty Section_id in some cases:

binutils/gold/gc.h:250:37: error: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second: [-Werror]
  250 |                 (*secvec).push_back(Section_id(NULL, 0));
      |                                     ^~~~~~~~~~~~~~~~~~~
Comment 1 Cary Coutant 2021-05-05 20:38:27 UTC
I haven't had the chance to build a new-enough GCC to test, but it looks like the proper fix is to use nullptr instead of NULL. Does that sound right? That would require that I raise the minimum version of GCC that can build gold from 4.1.3 to at least 4.6. I'm not sure if anyone needs to build with such an old version, but if so, maybe I could just use a static cast here.
Comment 2 Matheus Castanho 2021-05-06 12:12:23 UTC
Yes, that sounds right. I tested that and it's enough to get past the error with upstream GCC. I didn't have the chance to test with the oldest supported GCC though.
Comment 3 H.J. Lu 2021-05-06 13:59:22 UTC
(In reply to Cary Coutant from comment #1)
> I haven't had the chance to build a new-enough GCC to test, but it looks
> like the proper fix is to use nullptr instead of NULL. Does that sound
> right? That would require that I raise the minimum version of GCC that can
> build gold from 4.1.3 to at least 4.6. I'm not sure if anyone needs to build
> with such an old version, but if so, maybe I could just use a static cast
> here.

For GCC 12 or newer, use nullptr.  Otherwise, use NULL.
Comment 4 cvs-commit@gcc.gnu.org 2021-05-22 07:53:33 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1f1fb219fdc4f96fd967e6173e9090c4c4917e96

commit 1f1fb219fdc4f96fd967e6173e9090c4c4917e96
Author: Alan Modra <amodra@gmail.com>
Date:   Thu May 20 08:19:00 2021 +0930

    [GOLD] PR27815, gold fails to build with latest GCC
    
    ...gold/gc.h:250:37: error: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second: [-Werror]
      250 |                 (*secvec).push_back(Section_id(NULL, 0));
          |                                     ^~~~~~~~~~~~~~~~~~~
    
            PR gold/27815
            * gc.h (gc_process_relocs): Use nullptr in Section_id constructor.
Comment 5 Alan Modra 2021-05-22 10:28:23 UTC
Fixed
Comment 6 Alan Modra 2021-05-22 10:43:51 UTC
Oh oh, maybe I let myself be talked into the nullptr solution when I shouldn't have.  The original patch I posted using a cast works everywhere.  nullptr, although cleaner, requires c++11, doesn't it?  So all versions of gcc prior to 6.1 will need -std=c++11 to be passed to the compiler.
Comment 7 cvs-commit@gcc.gnu.org 2021-05-25 07:45:29 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=5d7f11f0e76ca290e3745c8836b92a5266cb84e2

commit 5d7f11f0e76ca290e3745c8836b92a5266cb84e2
Author: Alan Modra <amodra@gmail.com>
Date:   Tue May 25 15:06:49 2021 +0930

    [GOLD] PR27815, gold fails to build with latest GCC
    
    Don't use nullptr, it requires -std=c++11 on versions of gcc prior to
    6.1.  It would be possible to arrange to pass -std=c++11 automatically
    when required (top level configure does that for gcc builds) but that
    seems overkill and since we're not up-to-date on the top level config
    files would mean someone would need to sync those over.
    
            PR gold/27815
            * gc.h (gc_process_relocs): Use cast in Section_id constructor.
Comment 8 Alan Modra 2021-05-25 08:04:33 UTC
I've gone back to the original patch I posted.
Comment 9 cvs-commit@gcc.gnu.org 2021-07-20 12:02:50 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b97bd976233ee4d43c2fe18f6356e62779cbe82d

commit b97bd976233ee4d43c2fe18f6356e62779cbe82d
Author: Alan Modra <amodra@gmail.com>
Date:   Tue Jul 20 18:46:57 2021 +0930

    PR28106, build of 2.37 fails on FreeBSD and Clang
    
    https://en.cppreference.com/w/cpp/types/NULL says NULL might be
    defined as nullptr.
    https://en.cppreference.com/w/cpp/language/reinterpret_cast says
    reinterpret_cast can't be used on nullptr.
    
            PR gold/28106
            PR gold/27815
            * gc.h (gc_process_relocs): Use static_cast in Section_id constructor.
Comment 10 cvs-commit@gcc.gnu.org 2021-07-20 12:04:58 UTC
The binutils-2_37-branch branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=10b4dbbf281397e2827820c715c39559c7f7a29d

commit 10b4dbbf281397e2827820c715c39559c7f7a29d
Author: Alan Modra <amodra@gmail.com>
Date:   Tue Jul 20 18:46:57 2021 +0930

    PR28106, build of 2.37 fails on FreeBSD and Clang
    
    https://en.cppreference.com/w/cpp/types/NULL says NULL might be
    defined as nullptr.
    https://en.cppreference.com/w/cpp/language/reinterpret_cast says
    reinterpret_cast can't be used on nullptr.
    
            PR gold/28106
            PR gold/27815
            * gc.h (gc_process_relocs): Use static_cast in Section_id constructor.
    
    (cherry picked from commit b97bd976233ee4d43c2fe18f6356e62779cbe82d)
Comment 11 cvs-commit@gcc.gnu.org 2021-08-19 06:14:38 UTC
The binutils-2_36-branch branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ee51385839895013660b2fe5a86713e43f1627cf

commit ee51385839895013660b2fe5a86713e43f1627cf
Author: Alan Modra <amodra@gmail.com>
Date:   Thu May 20 08:19:00 2021 +0930

    [GOLD] PR27815, gold fails to build with latest GCC
    
    ...gold/gc.h:250:37: error: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second: [-Werror]
      250 |                 (*secvec).push_back(Section_id(NULL, 0));
          |                                     ^~~~~~~~~~~~~~~~~~~
    
            PR gold/27815
            * gc.h (gc_process_relocs): Use nullptr in Section_id constructor.
    
    Don't use nullptr, it requires -std=c++11 on versions of gcc prior to
    6.1.  It would be possible to arrange to pass -std=c++11 automatically
    when required (top level configure does that for gcc builds) but that
    seems overkill and since we're not up-to-date on the top level config
    files would mean someone would need to sync those over.
    
            PR gold/27815
            * gc.h (gc_process_relocs): Use cast in Section_id constructor.
    
    https://en.cppreference.com/w/cpp/types/NULL says NULL might be
    defined as nullptr.
    https://en.cppreference.com/w/cpp/language/reinterpret_cast says
    reinterpret_cast can't be used on nullptr.
    
            PR gold/28106
            PR gold/27815
            * gc.h (gc_process_relocs): Use static_cast in Section_id constructor.
    
    (cherry picked from commit 1f1fb219fdc4f96fd967e6173e9090c4c4917e96)
    (cherry picked from commit 5d7f11f0e76ca290e3745c8836b92a5266cb84e2)
    (cherry picked from commit b97bd976233ee4d43c2fe18f6356e62779cbe82d)