powerpc gold, fix pr17566
authorAlan Modra <amodra@gmail.com>
Wed, 3 Dec 2014 11:26:19 +0000 (21:56 +1030)
committerAlan Modra <amodra@gmail.com>
Wed, 3 Dec 2014 14:39:55 +0000 (01:09 +1030)
Code stolen from arm.cc.

PR 17566
* powerpc.cc (Target_powerpc::Scan::local): Use add_local_section
when adding dynamic relocations against section symbols.

gold/ChangeLog
gold/powerpc.cc

index 8bd1afc8c44091743cca9d59251763bb3c9e3662..b75530f220593c2a50ca9e11f27260455c0783d8 100644 (file)
@@ -1,3 +1,9 @@
+2014-12-03  Alan Modra  <amodra@gmail.com>
+
+       PR 17566
+       * powerpc.cc (Target_powerpc::Scan::local): Use add_local_section
+       when adding dynamic relocations against section symbols.
+
 2014-12-01  Dimitry Ivanov <dimitry@google.com>
 
        * layout.cc (Layout::finish_dynamic_section): When '-z global'
index 554bf385ecaeeaeee7783eec5d61998186072866..5805c0bd769e1cb13c701bdd13422cb3d08c7e9f 100644 (file)
@@ -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;