Fix gdb build on 32-bit hosts w/ --enable-64-bit-bfd

Message ID 20181204181650.18188-1-palves@redhat.com
State New
Headers show
Series
  • Fix gdb build on 32-bit hosts w/ --enable-64-bit-bfd
Related show

Commit Message

Pedro Alves Dec. 4, 2018, 6:16 p.m.
Building for x86_64/-m32 with --enable-64-bit-bfd, compilation fails
with:

 src/gdb/dwarf2read.c: In instantiation of ‘gdb::array_view<const unsigned char> get_gdb_index_contents_from_section(objfile*, T*) [with T = dwarf2_per_objfile]’:
 src/gdb/dwarf2read.c:6266:54:   required from here
 src/gdb/dwarf2read.c:6192:37: error: narrowing conversion of ‘section->dwarf2_section_info::size’ from ‘bfd_size_type {aka long long unsigned int}’ to ‘size_t {aka unsigned int}’ inside { } [-Werror=narrowing]
    return {section->buffer, section->size};
			     ~~~~~~~~~^~~~

This fixes it.

gdb/ChangeLog:
2018-12-04  Pedro Alves  <palves@redhat.com>

	* dwarf2read.c (get_gdb_index_contents_from_section): Use
	gdb::make_array_view.
---
 gdb/dwarf2read.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

-- 
2.14.4

Comments

Simon Marchi Dec. 4, 2018, 6:59 p.m. | #1
On 2018-12-04 1:16 p.m., Pedro Alves wrote:
> Building for x86_64/-m32 with --enable-64-bit-bfd, compilation fails

> with:

> 

>  src/gdb/dwarf2read.c: In instantiation of ‘gdb::array_view<const unsigned char> get_gdb_index_contents_from_section(objfile*, T*) [with T = dwarf2_per_objfile]’:

>  src/gdb/dwarf2read.c:6266:54:   required from here

>  src/gdb/dwarf2read.c:6192:37: error: narrowing conversion of ‘section->dwarf2_section_info::size’ from ‘bfd_size_type {aka long long unsigned int}’ to ‘size_t {aka unsigned int}’ inside { } [-Werror=narrowing]

>     return {section->buffer, section->size};

> 			     ~~~~~~~~~^~~~

> 

> This fixes it.


Woops, thanks, LGTM.

Simon
Pedro Alves Dec. 7, 2018, 7:59 p.m. | #2
On 12/04/2018 06:59 PM, Simon Marchi wrote:
> On 2018-12-04 1:16 p.m., Pedro Alves wrote:

>> Building for x86_64/-m32 with --enable-64-bit-bfd, compilation fails

>> with:

>>

>>  src/gdb/dwarf2read.c: In instantiation of ‘gdb::array_view<const unsigned char> get_gdb_index_contents_from_section(objfile*, T*) [with T = dwarf2_per_objfile]’:

>>  src/gdb/dwarf2read.c:6266:54:   required from here

>>  src/gdb/dwarf2read.c:6192:37: error: narrowing conversion of ‘section->dwarf2_section_info::size’ from ‘bfd_size_type {aka long long unsigned int}’ to ‘size_t {aka unsigned int}’ inside { } [-Werror=narrowing]

>>     return {section->buffer, section->size};

>> 			     ~~~~~~~~~^~~~

>>

>> This fixes it.

> 

> Woops, thanks, LGTM.

Pushed, thanks.

Thanks,
Pedro Alves

Patch

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 8bfbd693940..30bc101f11c 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -6189,7 +6189,13 @@  get_gdb_index_contents_from_section (objfile *obj, T *section_owner)
 
   dwarf2_read_section (obj, section);
 
-  return {section->buffer, section->size};
+  /* dwarf2_section_info::size is a bfd_size_type, while
+     gdb::array_view works with size_t.  On 32-bit hosts, with
+     --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
+     is 32-bit.  So we need an explicit narrowing conversion here.
+     This is fine, because it's impossible to allocate or mmap an
+     array/buffer larger than what size_t can represent.  */
+  return gdb::make_array_view (section->buffer, section->size);
 }
 
 /* Lookup the index cache for the contents of the index associated to