2012-02-03 Doug Kwan <dougkwan@google.com>
authorDoug Kwan <dougkwan@google.com>
Fri, 3 Feb 2012 20:01:01 +0000 (20:01 +0000)
committerDoug Kwan <dougkwan@google.com>
Fri, 3 Feb 2012 20:01:01 +0000 (20:01 +0000)
* arm.cc (Arm_relocate_functions::abs8,
Arm_relocate_functions::abs16): Use
Bits::has_signed_unsigned_overflow32.
(Arm_relocate_functions::thm_abs8): Correct range of
overflow check.
* reloc.h (Bits class): Change minimum number of bits from 0 to 1
in assertions.

gold/ChangeLog
gold/arm.cc
gold/reloc.h

index 249346ec18e6773ac175c6e68a55e8a122e6f862..6c5078e737489e933a6330ab6d08bcb5a2073893 100644 (file)
@@ -1,3 +1,13 @@
+2012-02-03  Doug Kwan  <dougkwan@google.com>
+
+       * arm.cc (Arm_relocate_functions::abs8,
+       Arm_relocate_functions::abs16): Use
+       Bits::has_signed_unsigned_overflow32.
+       (Arm_relocate_functions::thm_abs8): Correct range of
+       overflow check.
+       * reloc.h (Bits class): Change minimum number of bits from 0 to 1
+       in assertions.
+
 2012-02-02  Doug Kwan  <dougkwan@google.com>
 
        * arm.cc (Reloc_stub::stub_type_for_reloc): Use PIC stubs in all
index ec80d674e5556f3f8407da40a916c23f6a1c744e..bc704ccbcb42a2c6564bc56bb179ad4df7c78083 100644 (file)
@@ -3183,8 +3183,7 @@ class Arm_relocate_functions : public Relocate_functions<32, big_endian>
     elfcpp::Swap<8, big_endian>::writeval(wv, val);
 
     // R_ARM_ABS8 permits signed or unsigned results.
-    int signed_x = static_cast<int32_t>(x);
-    return ((signed_x < -128 || signed_x > 255)
+    return (Bits<8>::has_signed_unsigned_overflow32(x)
            ? This::STATUS_OVERFLOW
            : This::STATUS_OKAY);
   }
@@ -3203,10 +3202,7 @@ class Arm_relocate_functions : public Relocate_functions<32, big_endian>
     Reltype x = psymval->value(object, addend);
     val = Bits<32>::bit_select32(val, x << 6, 0x7e0U);
     elfcpp::Swap<16, big_endian>::writeval(wv, val);
-
-    // R_ARM_ABS16 permits signed or unsigned results.
-    int signed_x = static_cast<int32_t>(x);
-    return ((signed_x < -32768 || signed_x > 65535)
+    return (Bits<5>::has_overflow32(x)
            ? This::STATUS_OVERFLOW
            : This::STATUS_OKAY);
   }
@@ -3245,8 +3241,7 @@ class Arm_relocate_functions : public Relocate_functions<32, big_endian>
     elfcpp::Swap_unaligned<16, big_endian>::writeval(view, val);
 
     // R_ARM_ABS16 permits signed or unsigned results.
-    int signed_x = static_cast<int32_t>(x);
-    return ((signed_x < -32768 || signed_x > 65536)
+    return (Bits<16>::has_signed_unsigned_overflow32(x)
            ? This::STATUS_OVERFLOW
            : This::STATUS_OKAY);
   }
index 973adb07a129b9bba32595b325467fd10b3c6d36..ec448acc152be041622e1db688f3eccfdb2e0fa1 100644 (file)
@@ -724,11 +724,11 @@ class Bits
 {
  public:
   // Sign extend an n-bit unsigned integer stored in a uint32_t into
-  // an int32_t.  BITS must be between 0 and 32.
+  // an int32_t.  BITS must be between 1 and 32.
   static inline int32_t
   sign_extend32(uint32_t val)
   {
-    gold_assert(bits >= 0 && bits <= 32);
+    gold_assert(bits > 0 && bits <= 32);
     if (bits == 32)
       return static_cast<int32_t>(val);
     uint32_t mask = (~static_cast<uint32_t>(0)) >> (32 - bits);
@@ -745,7 +745,7 @@ class Bits
   static inline bool
   has_overflow32(uint32_t val)
   {
-    gold_assert(bits >= 0 && bits <= 32);
+    gold_assert(bits > 0 && bits <= 32);
     if (bits == 32)
       return false;
     int32_t max = (1 << (bits - 1)) - 1;
@@ -761,7 +761,7 @@ class Bits
   static inline bool
   has_signed_unsigned_overflow32(uint32_t val)
   {
-    gold_assert(bits >= 0 && bits <= 32);
+    gold_assert(bits > 0 && bits <= 32);
     if (bits == 32)
       return false;
     int32_t max = static_cast<int32_t>((1U << bits) - 1);
@@ -778,11 +778,11 @@ class Bits
   { return (a & ~mask) | (b & mask); }
 
   // Sign extend an n-bit unsigned integer stored in a uint64_t into
-  // an int64_t.  BITS must be between 0 and 64.
+  // an int64_t.  BITS must be between 1 and 64.
   static inline int64_t
   sign_extend(uint64_t val)
   {
-    gold_assert(bits >= 0 && bits <= 64);
+    gold_assert(bits > 0 && bits <= 64);
     if (bits == 64)
       return static_cast<int64_t>(val);
     uint64_t mask = (~static_cast<uint64_t>(0)) >> (64 - bits);
@@ -799,7 +799,7 @@ class Bits
   static inline bool
   has_overflow(uint64_t val)
   {
-    gold_assert(bits >= 0 && bits <= 64);
+    gold_assert(bits > 0 && bits <= 64);
     if (bits == 64)
       return false;
     int64_t max = (static_cast<int64_t>(1) << (bits - 1)) - 1;
@@ -815,7 +815,7 @@ class Bits
   static inline bool
   has_signed_unsigned_overflow64(uint64_t val)
   {
-    gold_assert(bits >= 0 && bits <= 64);
+    gold_assert(bits > 0 && bits <= 64);
     if (bits == 64)
       return false;
     int64_t max = static_cast<int64_t>((static_cast<uint64_t>(1) << bits) - 1);
This page took 0.035609 seconds and 4 git commands to generate.