[PATCH] gold: fix some signed-unsigned comparison warnings

Roland McGrath mcgrathr@google.com
Thu Nov 1 20:57:00 GMT 2012


On Thu, Nov 1, 2012 at 1:41 PM, Cary Coutant <ccoutant@google.com> wrote:
> Seems to me that offset_in_output_section is misdeclared here. As
> passed from relocate_relocs(), the actual parameter is declared as an
> Elf_Addr, which is unsigned. I think offset_in_output_section should
> be Arm_address here.

It seems to me the really proper type here is Elf_Off (albeit that is
actually identical to Elf_Addr), since what this refers to an offset in an
ELF file.  In fact, I think most of the uses of off_t throughout gold
really ought to be Elf_Off, but I'm not trying to clean everything up
right now.

> This is the right thing here, but it's preferable to use C++
> static_cast<off_t>(...).

Oh yeah, C++.


How's this version?


Thanks,
Roland


gold/
	* target.h (Sized_target::relocate_special_relocatable): Use Elf_Off
	for offset_in_output_section parameter.
	* arm.cc (Target_arm::relocate_special_relocatable): Likewise.

	* dwarf_reader.cc (Sized_elf_reloc_mapper::symbol_section): Cast
	SYMNDX to off_t before comparing it to this->data_size().
	* output.cc (Output_symtab_xindex::endian_do_write): Likewise.
	* incremental.cc (Output_section_incremental_inputs::do_write):
	Cast GLOBAL_SYM_COUNT to off_t before comparing it to SYMTAB_SIZE.


diff --git a/gold/arm.cc b/gold/arm.cc
index 5770c8a..d4efc80 100644
--- a/gold/arm.cc
+++ b/gold/arm.cc
@@ -2309,7 +2309,8 @@ class Target_arm : public Sized_target<32, big_endian>
 			       const unsigned char* preloc_in,
 			       size_t relnum,
 			       Output_section* output_section,
-			       off_t offset_in_output_section,
+			       typename elfcpp::Elf_types<32>::Elf_Off
+                                 offset_in_output_section,
 			       unsigned char* view,
 			       typename elfcpp::Elf_types<32>::Elf_Addr
 				 view_address,
@@ -9638,7 +9639,7 @@ Target_arm<big_endian>::relocate_special_relocatable(
     const unsigned char* preloc_in,
     size_t relnum,
     Output_section* output_section,
-    off_t offset_in_output_section,
+    typename elfcpp::Elf_types<32>::Elf_Off offset_in_output_section,
     unsigned char* view,
     elfcpp::Elf_types<32>::Elf_Addr view_address,
     section_size_type,
diff --git a/gold/dwarf_reader.cc b/gold/dwarf_reader.cc
index c80e8cb..ec0e845 100644
--- a/gold/dwarf_reader.cc
+++ b/gold/dwarf_reader.cc
@@ -57,7 +57,7 @@ Sized_elf_reloc_mapper<size, big_endian>::symbol_section(
     unsigned int symndx, Address* value, bool* is_ordinary)
 {
   const int symsize = elfcpp::Elf_sizes<size>::sym_size;
-  gold_assert((symndx + 1) * symsize <= this->symtab_size_);
+  gold_assert(static_cast<off_t>((symndx + 1) * symsize) <=
this->symtab_size_);
   elfcpp::Sym<size, big_endian> elfsym(this->symtab_ + symndx * symsize);
   *value = elfsym.get_st_value();
   return this->object_->adjust_sym_shndx(symndx, elfsym.get_st_shndx(),
diff --git a/gold/incremental.cc b/gold/incremental.cc
index acabaea..714b198 100644
--- a/gold/incremental.cc
+++ b/gold/incremental.cc
@@ -1432,7 +1432,7 @@ Output_section_incremental_inputs<size,
big_endian>::do_write(Output_file* of)
   gold_assert(pov - oview == oview_size);

   // Write the .gnu_incremental_symtab section.
-  gold_assert(global_sym_count * 4 == symtab_size);
+  gold_assert(static_cast<off_t>(global_sym_count) * 4 == symtab_size);
   this->write_symtab(symtab_view, global_syms, global_sym_count);

   delete[] global_syms;
diff --git a/gold/output.cc b/gold/output.cc
index 6e5cd25..b47ad4d 100644
--- a/gold/output.cc
+++ b/gold/output.cc
@@ -1935,7 +1935,7 @@ Output_symtab_xindex::endian_do_write(unsigned
char* const oview)
        ++p)
     {
       unsigned int symndx = p->first;
-      gold_assert(symndx * 4 < this->data_size());
+      gold_assert(static_cast<off_t>(symndx) * 4 < this->data_size());
       elfcpp::Swap<32, big_endian>::writeval(oview + symndx * 4, p->second);
     }
 }
diff --git a/gold/target.h b/gold/target.h
index 3464a2b..3914a0f 100644
--- a/gold/target.h
+++ b/gold/target.h
@@ -868,7 +868,8 @@ class Sized_target : public Target
 			       const unsigned char* /* preloc_in */,
 			       size_t /* relnum */,
 			       Output_section* /* output_section */,
-			       off_t /* offset_in_output_section */,
+			       typename elfcpp::Elf_types<size>::Elf_Off
+                                 /* offset_in_output_section */,
 			       unsigned char* /* view */,
 			       typename elfcpp::Elf_types<size>::Elf_Addr
 				 /* view_address */,



More information about the Binutils mailing list