Support compressed debug sections in dynamic object files.
[deliverable/binutils-gdb.git] / gold / powerpc.cc
index 554bf385ecaeeaeee7783eec5d61998186072866..d9a61ad0af73a108901812940273545f18a5d00a 100644 (file)
@@ -1,6 +1,6 @@
 // powerpc.cc -- powerpc target support for gold.
 
-// Copyright (C) 2008-2014 Free Software Foundation, Inc.
+// Copyright (C) 2008-2015 Free Software Foundation, Inc.
 // Written by David S. Miller <davem@davemloft.net>
 //        and David Edelsohn <edelsohn@gnu.org>
 
@@ -1035,11 +1035,11 @@ class Target_powerpc : public Sized_target<size, big_endian>
     bool issued_non_pic_error_;
   };
 
-  Address
-  symval_for_branch(const Symbol_table* symtab, Address value,
+  bool
+  symval_for_branch(const Symbol_table* symtab,
                    const Sized_symbol<size>* gsym,
                    Powerpc_relobj<size, big_endian>* object,
-                   unsigned int *dest_shndx);
+                   Address *value, unsigned int *dest_shndx);
 
   // The class which implements relocation.
   class Relocate : protected Track_tls
@@ -1650,7 +1650,7 @@ public:
   addr16_ds(unsigned char* view, Address value, Overflow_check overflow)
   {
     Status stat = This::template rela<16,16>(view, 0, 0xfffc, value, overflow);
-    if (overflow != CHECK_NONE && (value & 3) != 0)
+    if ((value & 3) != 0)
       stat = STATUS_OVERFLOW;
     return stat;
   }
@@ -2657,7 +2657,7 @@ Target_powerpc<size, big_endian>::Branch_info::make_stub(
     }
   else
     {
-      unsigned long max_branch_offset = max_branch_delta(this->r_type_);
+      Address max_branch_offset = max_branch_delta(this->r_type_);
       if (max_branch_offset == 0)
        return true;
       Address from = this->object_->get_output_section_offset(this->shndx_);
@@ -2711,14 +2711,16 @@ 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)
        {
          unsigned int dest_shndx;
-         to = target->symval_for_branch(symtab, to, gsym,
-                                        this->object_, &dest_shndx);
+         if (!target->symval_for_branch(symtab, gsym, this->object_,
+                                        &to, &dest_shndx))
+           return true;
        }
       Address delta = to - from;
       if (delta + max_branch_offset >= 2 * max_branch_offset)
@@ -3176,8 +3178,6 @@ static const uint32_t addi_11_11  = 0x396b0000;
 static const uint32_t addi_12_12       = 0x398c0000;
 static const uint32_t addis_0_2                = 0x3c020000;
 static const uint32_t addis_0_13       = 0x3c0d0000;
-static const uint32_t addis_3_2                = 0x3c620000;
-static const uint32_t addis_3_13       = 0x3c6d0000;
 static const uint32_t addis_11_2       = 0x3d620000;
 static const uint32_t addis_11_11      = 0x3d6b0000;
 static const uint32_t addis_11_30      = 0x3d7e0000;
@@ -3626,7 +3626,7 @@ class Stub_table : public Output_relaxed_input_section
   bool
   can_reach_stub(Address from, unsigned int off, unsigned int r_type)
   {
-    unsigned long max_branch_offset = max_branch_delta(r_type);
+    Address max_branch_offset = max_branch_delta(r_type);
     if (max_branch_offset == 0)
       return true;
     gold_assert(from != invalid_address);
@@ -5566,10 +5566,10 @@ Target_powerpc<size, big_endian>::Scan::local(
        {
          Reloc_section* rela_dyn = target->rela_dyn_section(symtab, layout,
                                                             is_ifunc);
+         unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
          if ((size == 32 && r_type == elfcpp::R_POWERPC_ADDR32)
              || (size == 64 && r_type == elfcpp::R_PPC64_ADDR64))
            {
-             unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
              unsigned int dynrel = (is_ifunc ? elfcpp::R_POWERPC_IRELATIVE
                                     : elfcpp::R_POWERPC_RELATIVE);
              rela_dyn->add_local_relative(object, r_sym, dynrel,
@@ -5577,14 +5577,28 @@ Target_powerpc<size, big_endian>::Scan::local(
                                           reloc.get_r_offset(),
                                           reloc.get_r_addend(), false);
            }
-         else
+         else if (lsym.get_st_type() != elfcpp::STT_SECTION)
            {
              check_non_pic(object, r_type);
-             unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
              rela_dyn->add_local(object, r_sym, r_type, output_section,
                                  data_shndx, reloc.get_r_offset(),
                                  reloc.get_r_addend());
            }
+         else
+           {
+             gold_assert(lsym.get_st_value() == 0);
+             unsigned int shndx = lsym.get_st_shndx();
+             bool is_ordinary;
+             shndx = object->adjust_sym_shndx(r_sym, shndx,
+                                              &is_ordinary);
+             if (!is_ordinary)
+               object->error(_("section symbol %u has bad shndx %u"),
+                             r_sym, shndx);
+             else
+               rela_dyn->add_local_section(object, shndx, r_type,
+                                           output_section, data_shndx,
+                                           reloc.get_r_offset());
+           }
        }
       break;
 
@@ -5655,8 +5669,8 @@ Target_powerpc<size, big_endian>::Scan::local(
 
        if (!parameters->options().output_is_position_independent())
          {
-           if ((size == 32 && is_ifunc)
-               || (size == 64 && target->abiversion() >= 2))
+           if (is_ifunc
+               && (size == 32 || target->abiversion() >= 2))
              got->add_local_plt(object, r_sym, GOT_TYPE_STANDARD);
            else
              got->add_local(object, r_sym, GOT_TYPE_STANDARD);
@@ -6103,8 +6117,8 @@ Target_powerpc<size, big_endian>::Scan::global(
        got = target->got_section(symtab, layout);
        if (gsym->final_value_is_known())
          {
-           if ((size == 32 && is_ifunc)
-               || (size == 64 && target->abiversion() >= 2))
+           if (is_ifunc
+               && (size == 32 || target->abiversion() >= 2))
              got->add_global_plt(gsym, GOT_TYPE_STANDARD);
            else
              got->add_global(gsym, GOT_TYPE_STANDARD);
@@ -6535,7 +6549,12 @@ class Global_symbol_visitor_opd
     unsigned int shndx = sym->shndx(&is_ordinary);
     if (shndx == symobj->opd_shndx()
        && symobj->get_opd_discard(sym->value()))
-      sym->set_symtab_index(-1U);
+      {
+       sym->set_undefined();
+       sym->set_visibility(elfcpp::STV_DEFAULT);
+       sym->set_is_defined_in_discarded_section();
+       sym->set_symtab_index(-1U);
+      }
   }
 };
 
@@ -6713,12 +6732,12 @@ ok_lo_toc_insn(uint32_t insn)
 // Return the value to use for a branch relocation.
 
 template<int size, bool big_endian>
-typename Target_powerpc<size, big_endian>::Address
+bool
 Target_powerpc<size, big_endian>::symval_for_branch(
     const Symbol_table* symtab,
-    Address value,
     const Sized_symbol<size>* gsym,
     Powerpc_relobj<size, big_endian>* object,
+    Address *value,
     unsigned int *dest_shndx)
 {
   if (size == 32 || this->abiversion() >= 2)
@@ -6730,20 +6749,20 @@ Target_powerpc<size, big_endian>::symval_for_branch(
   Powerpc_relobj<size, big_endian>* symobj = object;
   if (gsym != NULL
       && gsym->source() != Symbol::FROM_OBJECT)
-    return value;
+    return true;
   if (gsym != NULL)
     symobj = static_cast<Powerpc_relobj<size, big_endian>*>(gsym->object());
   unsigned int shndx = symobj->opd_shndx();
   if (shndx == 0)
-    return value;
+    return true;
   Address opd_addr = symobj->get_output_section_offset(shndx);
   if (opd_addr == invalid_address)
-    return value;
+    return true;
   opd_addr += symobj->output_section_address(shndx);
-  if (value >= opd_addr && value < opd_addr + symobj->section_size(shndx))
+  if (*value >= opd_addr && *value < opd_addr + symobj->section_size(shndx))
     {
       Address sec_off;
-      *dest_shndx = symobj->get_opd_ent(value - opd_addr, &sec_off);
+      *dest_shndx = symobj->get_opd_ent(*value - opd_addr, &sec_off);
       if (symtab->is_section_folded(symobj, *dest_shndx))
        {
          Section_id folded
@@ -6752,11 +6771,13 @@ Target_powerpc<size, big_endian>::symval_for_branch(
          *dest_shndx = folded.second;
        }
       Address sec_addr = symobj->get_output_section_offset(*dest_shndx);
-      gold_assert(sec_addr != invalid_address);
+      if (sec_addr == invalid_address)
+       return false;
+
       sec_addr += symobj->output_section(*dest_shndx)->address();
-      value = sec_addr + sec_off;
+      *value = sec_addr + sec_off;
     }
-  return value;
+  return true;
 }
 
 // Perform a relocation.
@@ -6916,10 +6937,9 @@ Target_powerpc<size, big_endian>::Relocate::relocate(
                  if (target->abiversion() < 2)
                    {
                      Address addend = rela.get_r_addend();
-                     Address opdent = psymval->value(object, addend);
-                     code = target->symval_for_branch(relinfo->symtab,
-                                                      opdent, gsym, object,
-                                                      &dest_shndx);
+                     code = psymval->value(object, addend);
+                     target->symval_for_branch(relinfo->symtab, gsym, object,
+                                               &code, &dest_shndx);
                    }
                  bool is_ordinary;
                  if (dest_shndx == 0)
@@ -6987,9 +7007,12 @@ Target_powerpc<size, big_endian>::Relocate::relocate(
              || r_type == elfcpp::R_POWERPC_GOT_TLSGD16_LO)
            {
              Insn* iview = reinterpret_cast<Insn*>(view - 2 * big_endian);
-             Insn insn = addis_3_13;
+             Insn insn = elfcpp::Swap<32, big_endian>::readval(iview);
+             insn &= (1 << 26) - (1 << 21); // extract rt
              if (size == 32)
-               insn = addis_3_2;
+               insn |= addis_0_2;
+             else
+               insn |= addis_0_13;
              elfcpp::Swap<32, big_endian>::writeval(iview, insn);
              r_type = elfcpp::R_POWERPC_TPREL16_HA;
              value = psymval->value(object, rela.get_r_addend());
@@ -7022,9 +7045,12 @@ Target_powerpc<size, big_endian>::Relocate::relocate(
              || r_type == elfcpp::R_POWERPC_GOT_TLSLD16_LO)
            {
              Insn* iview = reinterpret_cast<Insn*>(view - 2 * big_endian);
-             Insn insn = addis_3_13;
+             Insn insn = elfcpp::Swap<32, big_endian>::readval(iview);
+             insn &= (1 << 26) - (1 << 21); // extract rt
              if (size == 32)
-               insn = addis_3_2;
+               insn |= addis_0_2;
+             else
+               insn |= addis_0_13;
              elfcpp::Swap<32, big_endian>::writeval(iview, insn);
              r_type = elfcpp::R_POWERPC_TPREL16_HA;
              value = dtp_offset;
@@ -7177,8 +7203,7 @@ Target_powerpc<size, big_endian>::Relocate::relocate(
   else if (!has_stub_value)
     {
       Address addend = 0;
-      unsigned int dest_shndx;
-      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))
@@ -7191,10 +7216,13 @@ Target_powerpc<size, big_endian>::Relocate::relocate(
                value += object->ppc64_local_entry_offset(r_sym);
            }
          else
-           value = target->symval_for_branch(relinfo->symtab, value,
-                                             gsym, object, &dest_shndx);
+           {
+             unsigned int dest_shndx;
+             target->symval_for_branch(relinfo->symtab, gsym, object,
+                                       &value, &dest_shndx);
+           }
        }
-      unsigned long max_branch_offset = max_branch_delta(r_type);
+      Address max_branch_offset = max_branch_delta(r_type);
       if (max_branch_offset != 0
          && value - address + max_branch_offset >= 2 * max_branch_offset)
        {
@@ -7508,7 +7536,6 @@ Target_powerpc<size, big_endian>::Relocate::relocate(
       Insn* iview = reinterpret_cast<Insn*>(view - 2 * big_endian);
       Insn insn = elfcpp::Swap<32, big_endian>::readval(iview);
 
-      overflow = Reloc::CHECK_SIGNED;
       if ((insn & (0x3f << 26)) == 10u << 26 /* cmpli */)
        overflow = Reloc::CHECK_BITFIELD;
       else if (overflow == Reloc::CHECK_LOW_INSN
@@ -7519,6 +7546,8 @@ Target_powerpc<size, big_endian>::Relocate::relocate(
                  || (insn & (0x3f << 26)) == 25u << 26 /* oris */
                  || (insn & (0x3f << 26)) == 27u << 26 /* xoris */))
        overflow = Reloc::CHECK_UNSIGNED;
+      else
+       overflow = Reloc::CHECK_SIGNED;
     }
 
   typename Powerpc_relocate_functions<size, big_endian>::Status status
@@ -7568,8 +7597,11 @@ Target_powerpc<size, big_endian>::Relocate::relocate(
 
     case elfcpp::R_POWERPC_GOT_DTPREL16:
     case elfcpp::R_POWERPC_GOT_DTPREL16_LO:
+    case elfcpp::R_POWERPC_GOT_TPREL16:
+    case elfcpp::R_POWERPC_GOT_TPREL16_LO:
       if (size == 64)
        {
+         // On ppc64 these are all ds form
          status = Reloc::addr16_ds(view, value, overflow);
          break;
        }
@@ -7582,7 +7614,6 @@ Target_powerpc<size, big_endian>::Relocate::relocate(
     case elfcpp::R_POWERPC_DTPREL16:
     case elfcpp::R_POWERPC_GOT_TLSGD16:
     case elfcpp::R_POWERPC_GOT_TLSLD16:
-    case elfcpp::R_POWERPC_GOT_TPREL16:
     case elfcpp::R_POWERPC_ADDR16_LO:
     case elfcpp::R_POWERPC_REL16_LO:
     case elfcpp::R_PPC64_TOC16_LO:
@@ -7592,7 +7623,6 @@ Target_powerpc<size, big_endian>::Relocate::relocate(
     case elfcpp::R_POWERPC_DTPREL16_LO:
     case elfcpp::R_POWERPC_GOT_TLSGD16_LO:
     case elfcpp::R_POWERPC_GOT_TLSLD16_LO:
-    case elfcpp::R_POWERPC_GOT_TPREL16_LO:
       status = Reloc::addr16(view, value, overflow);
       break;
 
This page took 0.031619 seconds and 4 git commands to generate.