fix Dwarf2 build with certain gcc versions

Message ID c7522d4e-75c5-ab4f-a687-30b7f470f98b@suse.com
State New
Headers show
Series
  • fix Dwarf2 build with certain gcc versions
Related show

Commit Message

Alan Modra via Binutils June 4, 2021, 7:52 a.m.
Older gcc reports:

.../bfd/dwarf2.c: In function ‘read_ranges’:
.../bfd/dwarf2.c:3107: error: comparison between signed and unsigned
.../bfd/dwarf2.c: In function ‘read_rnglists’:
.../bfd/dwarf2.c:3189: error: comparison between signed and unsigned

Similarly for binutils/dwarf.c. Arrange for the left sides of the > to
also be unsigned quantities.

bfd/
2021-06-XX  Jan Beulich  <jbeulich@suse.com>

	* dwarf2.c (read_ranges, read_rnglists): Add u suffix to constant.

binutils/
2021-06-XX  Jan Beulich  <jbeulich@suse.com>

	* dwarf.c (display_debug_aranges): Add u suffix to constant.

Comments

Alan Modra via Binutils June 4, 2021, 9:11 a.m. | #1
Hi Jan,

> bfd/

> 2021-06-XX  Jan Beulich  <jbeulich@suse.com>

> 

> 	* dwarf2.c (read_ranges, read_rnglists): Add u suffix to constant.

> 

> binutils/

> 2021-06-XX  Jan Beulich  <jbeulich@suse.com>

> 

> 	* dwarf.c (display_debug_aranges): Add u suffix to constant.


Approved - please apply.

Cheers
   Nick
Alan Modra via Binutils June 7, 2021, 6:25 a.m. | #2
On Fri, Jun 04, 2021 at 09:52:39AM +0200, Jan Beulich via Binutils wrote:
> Older gcc reports:

> 

> .../bfd/dwarf2.c: In function ‘read_ranges’:

> .../bfd/dwarf2.c:3107: error: comparison between signed and unsigned

> .../bfd/dwarf2.c: In function ‘read_rnglists’:

> .../bfd/dwarf2.c:3189: error: comparison between signed and unsigned

> 

> Similarly for binutils/dwarf.c. Arrange for the left sides of the > to

> also be unsigned quantities.


Yeah, unsigned char promotes to int.  Thanks for fixing this.  How old
a version of gcc?  I didn't notice anything with gcc-4.9, which is the
oldest I regularly test.

-- 
Alan Modra
Australia Development Lab, IBM
Alan Modra via Binutils June 7, 2021, 6:31 a.m. | #3
On 07.06.2021 08:25, Alan Modra wrote:
> On Fri, Jun 04, 2021 at 09:52:39AM +0200, Jan Beulich via Binutils wrote:

>> Older gcc reports:

>>

>> .../bfd/dwarf2.c: In function ‘read_ranges’:

>> .../bfd/dwarf2.c:3107: error: comparison between signed and unsigned

>> .../bfd/dwarf2.c: In function ‘read_rnglists’:

>> .../bfd/dwarf2.c:3189: error: comparison between signed and unsigned

>>

>> Similarly for binutils/dwarf.c. Arrange for the left sides of the > to

>> also be unsigned quantities.

> 

> Yeah, unsigned char promotes to int.  Thanks for fixing this.  How old

> a version of gcc?  I didn't notice anything with gcc-4.9, which is the

> oldest I regularly test.


4.3-ish (with a number of backports).

Jan

Patch

--- a/bfd/dwarf2.c
+++ b/bfd/dwarf2.c
@@ -3104,7 +3104,7 @@  read_ranges (struct comp_unit *unit, str
       bfd_vma high_pc;
 
       /* PR 17512: file: 62cada7d.  */
-      if (2 * unit->addr_size > (size_t) (ranges_end - ranges_ptr))
+      if (2u * unit->addr_size > (size_t) (ranges_end - ranges_ptr))
 	return false;
 
       low_pc = read_address (unit, &ranges_ptr, ranges_end);
@@ -3186,7 +3186,7 @@  read_rnglists (struct comp_unit *unit, s
 	  break;
 
 	case DW_RLE_start_end:
-	  if (2 * unit->addr_size > (size_t) (rngs_end - rngs_ptr))
+	  if (2u * unit->addr_size > (size_t) (rngs_end - rngs_ptr))
 	    return false;
 	  low_pc = read_address (unit, &rngs_ptr, rngs_end);
 	  high_pc = read_address (unit, &rngs_ptr, rngs_end);
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -7284,7 +7284,7 @@  display_debug_aranges (struct dwarf_sect
 
       start = end_ranges;
 
-      while (2 * address_size <= (size_t) (start - addr_ranges))
+      while (2u * address_size <= (size_t) (start - addr_ranges))
 	{
 	  SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, start);
 	  SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, start);