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

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


On Thu, Nov 1, 2012 at 3:09 PM, Ian Lance Taylor <iant@google.com> wrote:
> In gold, a file offset should normally be off_t.  It's true that it
> can be Elf_Off in templatized code, but there is a fair amount of
> non-templatized code in gold that deals with file offsets, and for
> those it should be off_t.

Still not sure why an unsigned type (GElf_Off or equivalent) wouldn't be
more appropriate for almost every case.  But whatever.

> However, when we have a view in a section, an offset into the section
> should be section_offset_type, not off_t.  I agree this is confusing,
> but it makes a significant performance difference when building on
> 32-bit systems to use section_offset_type rather than off_t when
> appropriate.

It's not particularly confusing to me.  But then I'm used to the 17 Elf*_*
names for the same type. ;-)

> I think it's pretty hard to justify changing the type of
> offset_in_output_section in Target::relocate_special_relocatable
> without also changing the type of offset_in_output_section in
> Target::relocate_relocs.  This is templatized code so we could make
> them both Elf_Off.  Or we could make them both section_offset_type.

My sort of pedanticism favors the most right-sized as well as the most
right-named types, so templatized Elf_Off is my preference.

How about this?


Thanks,
Roland


gold/
	* target.h (Sized_target::relocate_relocs): Use Elf_Off
	for offset_in_output_section parameter.
	(Sized_target::relocate_special_relocatable): Likewise.
	* arm.cc (Target_arm::relocate_relocs): Likewise.
	(Target_arm::relocate_special_relocatable): Likewise.
	* i386.cc (Target_i386::relocate_relocs): Likewise.
	* powerpc.cc (Target_powerpc::relocate_relocs): Likewise.
	* sparc.cc (Target_sparc::relocate_relocs): Likewise.
	* target-reloc.h (relocate_relocs): Likewise.
	* testsuite/testfile.cc (Target_test): Likewise.
	* tilegx.cc (Target_tilegx::relocate_relocs): Likewise.
	* x86_64.cc (Target_x86_64::relocate_relocs): Likewise.


diff --git a/gold/arm.cc b/gold/arm.cc
index 5770c8a..1994329 100644
--- a/gold/arm.cc
+++ b/gold/arm.cc
@@ -2293,7 +2293,8 @@ class Target_arm : public Sized_target<32, big_endian>
 		  const unsigned char* prelocs,
 		  size_t reloc_count,
 		  Output_section* output_section,
-		  off_t offset_in_output_section,
+		  typename elfcpp::Elf_types<32>::Elf_Off
+                    offset_in_output_section,
 		  const Relocatable_relocs*,
 		  unsigned char* view,
 		  Arm_address view_address,
@@ -2309,7 +2310,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,
@@ -9603,7 +9605,7 @@ Target_arm<big_endian>::relocate_relocs(
     const unsigned char* prelocs,
     size_t reloc_count,
     Output_section* output_section,
-    off_t offset_in_output_section,
+    typename elfcpp::Elf_types<32>::Elf_Off offset_in_output_section,
     const Relocatable_relocs* rr,
     unsigned char* view,
     Arm_address view_address,
@@ -9638,7 +9640,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/i386.cc b/gold/i386.cc
index 78f9770..fbf5670 100644
--- a/gold/i386.cc
+++ b/gold/i386.cc
@@ -414,7 +414,8 @@ class Target_i386 : public Sized_target<32, false>
 		  const unsigned char* prelocs,
 		  size_t reloc_count,
 		  Output_section* output_section,
-		  off_t offset_in_output_section,
+		  typename elfcpp::Elf_types<32>::Elf_Off
+                    offset_in_output_section,
 		  const Relocatable_relocs*,
 		  unsigned char* view,
 		  elfcpp::Elf_types<32>::Elf_Addr view_address,
@@ -3617,7 +3618,7 @@ Target_i386::relocate_relocs(
     const unsigned char* prelocs,
     size_t reloc_count,
     Output_section* output_section,
-    off_t offset_in_output_section,
+    typename elfcpp::Elf_types<32>::Elf_Off offset_in_output_section,
     const Relocatable_relocs* rr,
     unsigned char* view,
     elfcpp::Elf_types<32>::Elf_Addr view_address,
diff --git a/gold/powerpc.cc b/gold/powerpc.cc
index 5e4006c..3b36b41 100644
--- a/gold/powerpc.cc
+++ b/gold/powerpc.cc
@@ -393,7 +393,8 @@ class Target_powerpc : public Sized_target<size, big_endian>
 		  const unsigned char* prelocs,
 		  size_t reloc_count,
 		  Output_section* output_section,
-		  off_t offset_in_output_section,
+		  typename elfcpp::Elf_types<size>::Elf_Off
+                    offset_in_output_section,
 		  const Relocatable_relocs*,
 		  unsigned char*,
 		  Address view_address,
@@ -5177,7 +5178,7 @@ Target_powerpc<size, big_endian>::relocate_relocs(
     const unsigned char* prelocs,
     size_t reloc_count,
     Output_section* output_section,
-    off_t offset_in_output_section,
+    typename elfcpp::Elf_types<size>::Elf_Off offset_in_output_section,
     const Relocatable_relocs* rr,
     unsigned char*,
     Address view_address,
diff --git a/gold/sparc.cc b/gold/sparc.cc
index 456ee46..6db3b10 100644
--- a/gold/sparc.cc
+++ b/gold/sparc.cc
@@ -138,7 +138,8 @@ class Target_sparc : public Sized_target<size, big_endian>
 		  const unsigned char* prelocs,
 		  size_t reloc_count,
 		  Output_section* output_section,
-		  off_t offset_in_output_section,
+		  typename elfcpp::Elf_types<size>::Elf_Off
+                    offset_in_output_section,
 		  const Relocatable_relocs*,
 		  unsigned char* view,
 		  typename elfcpp::Elf_types<size>::Elf_Addr view_address,
@@ -4213,7 +4214,7 @@ Target_sparc<size, big_endian>::relocate_relocs(
     const unsigned char* prelocs,
     size_t reloc_count,
     Output_section* output_section,
-    off_t offset_in_output_section,
+    typename elfcpp::Elf_types<size>::Elf_Off offset_in_output_section,
     const Relocatable_relocs* rr,
     unsigned char* view,
     typename elfcpp::Elf_types<size>::Elf_Addr view_address,
diff --git a/gold/target-reloc.h b/gold/target-reloc.h
index 769a524..039621c 100644
--- a/gold/target-reloc.h
+++ b/gold/target-reloc.h
@@ -1,6 +1,7 @@
 // target-reloc.h -- target specific relocation support  -*- C++ -*-

-// Copyright 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012
+// Free Software Foundation, Inc.
 // Written by Ian Lance Taylor <iant@google.com>.

 // This file is part of gold.
@@ -606,7 +607,7 @@ relocate_relocs(
     const unsigned char* prelocs,
     size_t reloc_count,
     Output_section* output_section,
-    typename elfcpp::Elf_types<size>::Elf_Addr offset_in_output_section,
+    typename elfcpp::Elf_types<size>::Elf_Off offset_in_output_section,
     const Relocatable_relocs* rr,
     unsigned char* view,
     typename elfcpp::Elf_types<size>::Elf_Addr view_address,
diff --git a/gold/target.h b/gold/target.h
index 3464a2b..d4b9d0f 100644
--- a/gold/target.h
+++ b/gold/target.h
@@ -838,7 +838,8 @@ class Sized_target : public Target
 		  const unsigned char* prelocs,
 		  size_t reloc_count,
 		  Output_section* output_section,
-		  off_t offset_in_output_section,
+		  typename elfcpp::Elf_types<size>::Elf_Off
+                    offset_in_output_section,
 		  const Relocatable_relocs*,
 		  unsigned char* view,
 		  typename elfcpp::Elf_types<size>::Elf_Addr view_address,
@@ -868,7 +869,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 */,
diff --git a/gold/testsuite/testfile.cc b/gold/testsuite/testfile.cc
index 3ce0c97..da3dc61 100644
--- a/gold/testsuite/testfile.cc
+++ b/gold/testsuite/testfile.cc
@@ -74,8 +74,8 @@ class Target_test : public Sized_target<size, big_endian>
   void
   relocate_relocs(const Relocate_info<size, big_endian>*,
 		  unsigned int, const unsigned char*, size_t,
-		  Output_section*, off_t, const Relocatable_relocs*,
-		  unsigned char*,
+		  Output_section*, typename elfcpp::Elf_types<size>::Elf_Off,
+                  const Relocatable_relocs*, unsigned char*,
 		  typename elfcpp::Elf_types<size>::Elf_Addr,
 		  section_size_type, unsigned char*,
 		  section_size_type)
diff --git a/gold/tilegx.cc b/gold/tilegx.cc
index f03014f..7babf4e 100644
--- a/gold/tilegx.cc
+++ b/gold/tilegx.cc
@@ -316,7 +316,7 @@ class Target_tilegx : public Sized_target<size, big_endian>
       const unsigned char* prelocs,
       size_t reloc_count,
       Output_section* output_section,
-      off_t offset_in_output_section,
+      typename elfcpp::Elf_types<size>::Elf_Off offset_in_output_section,
       const Relocatable_relocs*,
       unsigned char* view,
       typename elfcpp::Elf_types<size>::Elf_Addr view_address,
@@ -4836,7 +4836,7 @@ Target_tilegx<size, big_endian>::relocate_relocs(
     const unsigned char* prelocs,
     size_t reloc_count,
     Output_section* output_section,
-    off_t offset_in_output_section,
+    typename elfcpp::Elf_types<size>::Elf_Off offset_in_output_section,
     const Relocatable_relocs* rr,
     unsigned char* view,
     typename elfcpp::Elf_types<size>::Elf_Addr view_address,
diff --git a/gold/x86_64.cc b/gold/x86_64.cc
index 6c379ba..6342196 100644
--- a/gold/x86_64.cc
+++ b/gold/x86_64.cc
@@ -477,7 +477,7 @@ class Target_x86_64 : public Sized_target<size, false>
       const unsigned char* prelocs,
       size_t reloc_count,
       Output_section* output_section,
-      off_t offset_in_output_section,
+      typename elfcpp::Elf_types<size>::Elf_Off offset_in_output_section,
       const Relocatable_relocs*,
       unsigned char* view,
       typename elfcpp::Elf_types<size>::Elf_Addr view_address,
@@ -4221,7 +4221,7 @@ Target_x86_64<size>::relocate_relocs(
     const unsigned char* prelocs,
     size_t reloc_count,
     Output_section* output_section,
-    off_t offset_in_output_section,
+    typename elfcpp::Elf_types<size>::Elf_Off offset_in_output_section,
     const Relocatable_relocs* rr,
     unsigned char* view,
     typename elfcpp::Elf_types<size>::Elf_Addr view_address,


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