Fix build breaker with gcc 4.8

Message ID 20190619110410.GA14131@delia
State New, archived
Headers

Commit Message

Tom de Vries June 19, 2019, 11:04 a.m. UTC
  Hi,

When compiling with gcc 4.8, we run into:
...
/usr/include/c++/4.8/bits/unordered_map.h:100:18: required from \
  ‘class std::unordered_map<sect_offset, std::vector<sect_offset> >’
src/gdb/dwarf2read.h:260:5:   required from here
/usr/include/c++/4.8/bits/hashtable_policy.h:1070:12: error: invalid use of \
  incomplete type ‘struct std::hash<sect_offset>’
...

Fix this by adding std::hash<sect_offset>.

Build and reg-tested on x86_64-linux with gcc 4.8.

OK for trunk?

Thanks,
- Tom

[gdb] Fix build breaker with gcc 4.8

gdb/ChangeLog:

2019-06-19  Tom de Vries  <tdevries@suse.de>

	* dwarf2read.h (std::hash<sect_offset>): New specialization.

---
 gdb/dwarf2read.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
  

Comments

Pedro Alves June 19, 2019, 12:43 p.m. UTC | #1
On 6/19/19 12:04 PM, Tom de Vries wrote:
> Hi,
> 
> When compiling with gcc 4.8, we run into:
> ...
> /usr/include/c++/4.8/bits/unordered_map.h:100:18: required from \
>   ‘class std::unordered_map<sect_offset, std::vector<sect_offset> >’
> src/gdb/dwarf2read.h:260:5:   required from here
> /usr/include/c++/4.8/bits/hashtable_policy.h:1070:12: error: invalid use of \
>   incomplete type ‘struct std::hash<sect_offset>’
> ...
> 
> Fix this by adding std::hash<sect_offset>.
> 
> Build and reg-tested on x86_64-linux with gcc 4.8.
> 
> OK for trunk?
> 

hash_enum was added for this:

 https://sourceware.org/ml/gdb-patches/2017-12/msg00210.html

Can you use it here?

It's currently used in dwarf2read.c, here:

  std::unordered_map<sect_offset,
		     dwarf2_per_cu_data *,
		     gdb::hash_enum<sect_offset>>

Thanks,
Pedro Alves

> Thanks,
> - Tom
> 
> [gdb] Fix build breaker with gcc 4.8
> 
> gdb/ChangeLog:
> 
> 2019-06-19  Tom de Vries  <tdevries@suse.de>
> 
> 	* dwarf2read.h (std::hash<sect_offset>): New specialization.
> 
> ---
>  gdb/dwarf2read.h | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/gdb/dwarf2read.h b/gdb/dwarf2read.h
> index 776860e454..494dcb32c1 100644
> --- a/gdb/dwarf2read.h
> +++ b/gdb/dwarf2read.h
> @@ -99,6 +99,26 @@ struct signatured_type;
>  struct die_info;
>  typedef struct die_info *die_info_ptr;
>  
> +/* An std::hash specialization, required for use of sect_offset in
> +   std::unordered_map with gcc 4.8.  */
> +
> +namespace std
> +{
> +  template<> struct hash<sect_offset>
> +  {
> +    typedef sect_offset argument_type;
> +    typedef std::size_t result_type;
> +    using underlying_type
> +    = typename std::underlying_type<argument_type>::type;
> +
> +    result_type operator() (const argument_type &o) const noexcept
> +    {
> +      underlying_type u = static_cast<underlying_type> (o);
> +      return std::hash<underlying_type> {} (u);
> +    }
> +  };
> +};
> +
>  /* Collection of data recorded per objfile.
>     This hangs off of dwarf2_objfile_data_key.  */
>  
>
  
Steve Ellcey June 19, 2019, 2:56 p.m. UTC | #2
On Wed, 2019-06-19 at 13:04 +0200, Tom de Vries wrote:
> 

> [gdb] Fix build breaker with gcc 4.8

> 

> gdb/ChangeLog:

> 

> 2019-06-19  Tom de Vries  <tdevries@suse.de>

> 

> 	* dwarf2read.h (std::hash<sect_offset>): New specialization.


I think this might have broken the GDB build with GCC 5.4.  My
gdb/binutils build using the latest sources is dying with the
following message.  I am building on Ubuntu 18.04 and the installed GCC
5.4 compiler.  I haven't seen any errors from the buildbot, maybe that
is using GCC 4.8?

Error:


In file included from /usr/include/c++/5/bits/hashtable.h:35:0,
                 from /usr/include/c++/5/unordered_map:47,
                 from /home/sellcey/tot/src/binutils-
gdb/gdb/dwarf2read.h:23,
                 from /home/sellcey/tot/src/binutils-gdb/gdb/dwarf-
index-write.h:24,
                 from /home/sellcey/tot/src/binutils-gdb/gdb/dwarf-
index-cache.c:28:
/usr/include/c++/5/bits/hashtable_policy.h: In instantiation of ‘struct
std::__detail::__is_noexcept_hash<sect_offset, std::hash<sect_offset>
>’:

/usr/include/c++/5/type_traits:137:12:   required from ‘struct
std::__and_<std::__is_fast_hash<std::hash<sect_offset> >,
std::__detail::__is_noexcept_hash<sect_offset, std::hash<sect_offset> >
>’

/usr/include/c++/5/type_traits:148:38:   required from ‘struct
std::__not_<std::__and_<std::__is_fast_hash<std::hash<sect_offset> >,
std::__detail::__is_noexcept_hash<sect_offset, std::hash<sect_offset> >
> >’


(etc, etc, etc)
  
Tom de Vries June 19, 2019, 3 p.m. UTC | #3
On 19-06-19 16:56, Steve Ellcey wrote:
> On Wed, 2019-06-19 at 13:04 +0200, Tom de Vries wrote:
>>
>> [gdb] Fix build breaker with gcc 4.8
>>
>> gdb/ChangeLog:
>>
>> 2019-06-19  Tom de Vries  <tdevries@suse.de>
>>
>> 	* dwarf2read.h (std::hash<sect_offset>): New specialization.
> 
> I think this might have broken the GDB build with GCC 5.4.

I think you're running into the same build breaker as me, for which I
just pushed a fix (and not this one).

Thanks,
- Tom

> My
> gdb/binutils build using the latest sources is dying with the
> following message.  I am building on Ubuntu 18.04 and the installed GCC
> 5.4 compiler.  I haven't seen any errors from the buildbot, maybe that
> is using GCC 4.8?
>
  
Steve Ellcey June 19, 2019, 3:14 p.m. UTC | #4
On Wed, 2019-06-19 at 17:00 +0200, Tom de Vries wrote:
> 

> 

> I think you're running into the same build breaker as me, for which I

> just pushed a fix (and not this one).

> 

> Thanks,

> - Tom


Yes, that patch fixes my build. Thanks.

Steve Ellcey
sellcey@marvell.com
  

Patch

diff --git a/gdb/dwarf2read.h b/gdb/dwarf2read.h
index 776860e454..494dcb32c1 100644
--- a/gdb/dwarf2read.h
+++ b/gdb/dwarf2read.h
@@ -99,6 +99,26 @@  struct signatured_type;
 struct die_info;
 typedef struct die_info *die_info_ptr;
 
+/* An std::hash specialization, required for use of sect_offset in
+   std::unordered_map with gcc 4.8.  */
+
+namespace std
+{
+  template<> struct hash<sect_offset>
+  {
+    typedef sect_offset argument_type;
+    typedef std::size_t result_type;
+    using underlying_type
+    = typename std::underlying_type<argument_type>::type;
+
+    result_type operator() (const argument_type &o) const noexcept
+    {
+      underlying_type u = static_cast<underlying_type> (o);
+      return std::hash<underlying_type> {} (u);
+    }
+  };
+};
+
 /* Collection of data recorded per objfile.
    This hangs off of dwarf2_objfile_data_key.  */