PowerPC gold, fix 32-bit branch address arithmetic
authorAlan Modra <amodra@gmail.com>
Thu, 4 Dec 2014 11:15:05 +0000 (21:45 +1030)
committerAlan Modra <amodra@gmail.com>
Thu, 4 Dec 2014 11:16:49 +0000 (21:46 +1030)
Mixing 64-bit and 32-bit types led to the wrong promotions.  Keep
calculation in same type.  Also fix a case where PLTREL24 reloc addend
should be ignored.

* Powerpc.cc (Target_powerpc::Branch_info::make_stub): Ignore
addend of PLTREL24 reloc when not generating a plt stub.  Make
max_branch_offset an "Address".
(Target_powerpc::Relocate::relocate): Make max_branch_offset
an "Address".

gold/ChangeLog
gold/powerpc.cc

index d5413f6..2220da2 100644 (file)
@@ -1,5 +1,13 @@
 2014-12-04  Alan Modra  <amodra@gmail.com>
 
+       * Powerpc.cc (Target_powerpc::Branch_info::make_stub): Ignore
+       addend of PLTREL24 reloc when not generating a plt stub.  Make
+       max_branch_offset an "Address".
+       (Target_powerpc::Relocate::relocate): Make max_branch_offset
+       an "Address".
+
+2014-12-04  Alan Modra  <amodra@gmail.com>
+
        PR 17670
        * symtab.cc (Symbol::set_undefined): Remove assertion.
        * powerpc.cc (Target_powerpc::symval_for_branch): Don't assert
index 1ee9c77..0450937 100644 (file)
@@ -2600,7 +2600,7 @@ Target_powerpc<size, big_endian>::Branch_info::make_stub(
     }
   else
     {
-      unsigned long max_branch_offset;
+      Address max_branch_offset;
       if (this->r_type_ == elfcpp::R_POWERPC_REL14
          || this->r_type_ == elfcpp::R_POWERPC_REL14_BRTAKEN
          || this->r_type_ == elfcpp::R_POWERPC_REL14_BRNTAKEN)
@@ -2662,7 +2662,8 @@ Target_powerpc<size, big_endian>::Branch_info::make_stub(
          if (size == 64)
            to += this->object_->ppc64_local_entry_offset(this->r_sym_);
        }
-      to += this->addend_;
+      if (!(size == 32 && this->r_type_ == elfcpp::R_PPC_PLTREL24))
+       to += this->addend_;
       if (stub_table == NULL)
        stub_table = this->object_->stub_table(this->shndx_);
       if (size == 64 && target->abiversion() < 2)
@@ -7110,7 +7111,7 @@ Target_powerpc<size, big_endian>::Relocate::relocate(
   else if (!has_stub_value)
     {
       Address addend = 0;
-      if (r_type != elfcpp::R_PPC_PLTREL24)
+      if (!(size == 32 && r_type == elfcpp::R_PPC_PLTREL24))
        addend = rela.get_r_addend();
       value = psymval->value(object, addend);
       if (size == 64 && is_branch_reloc(r_type))
@@ -7129,7 +7130,7 @@ Target_powerpc<size, big_endian>::Relocate::relocate(
                                        &value, &dest_shndx);
            }
        }
-      unsigned int max_branch_offset = 0;
+      Address max_branch_offset = 0;
       if (r_type == elfcpp::R_POWERPC_REL24
          || r_type == elfcpp::R_PPC_PLTREL24
          || r_type == elfcpp::R_PPC_LOCAL24PC)