This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB 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]

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


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

commit 8bebfcda34f2ea883fa6b87e748ad8a5f72b352f
Author: Pedro Alves <palves@redhat.com>
Date:   Fri Dec 7 19:54:19 2018 +0000

    Fix gdb build on 32-bit hosts w/ --enable-64-bit-bfd
    
    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-07  Pedro Alves  <palves@redhat.com>
    
    	* dwarf2read.c (get_gdb_index_contents_from_section): Use
    	gdb::make_array_view.

Diff:
---
 gdb/ChangeLog    | 5 +++++
 gdb/dwarf2read.c | 8 +++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index eaea262..6812f96 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2018-12-07  Pedro Alves  <palves@redhat.com>
+
+	* dwarf2read.c (get_gdb_index_contents_from_section): Use
+	gdb::make_array_view.
+
 2018-12-05  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
 
 	* language.c (_initialize_language): Fix leak by assigning
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 8bfbd69..30bc101 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


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