[ARC] ARC_PC32 dynamic reloc incorrectly generated.
[deliverable/binutils-gdb.git] / bfd / elf32-arc.c
index 3e99cab7361d5f0afcea9413204126533c86fa46..b1a1697f4c19359a249f5d88dbb99a7650fe42ab 100644 (file)
@@ -55,17 +55,20 @@ name_for_global_symbol (struct elf_link_hash_entry *h)
     Elf_Internal_Rela _rel;                                            \
     bfd_byte * _loc;                                                   \
                                                                        \
-    BFD_ASSERT (_htab->srel##SECTION &&_htab->srel##SECTION->contents); \
-    _loc = _htab->srel##SECTION->contents                              \
-      + ((_htab->srel##SECTION->reloc_count)                           \
-        * sizeof (Elf32_External_Rela));                               \
-    _htab->srel##SECTION->reloc_count++;                               \
-    _rel.r_addend = ADDEND;                                            \
-    _rel.r_offset = (_htab->s##SECTION)->output_section->vma           \
-      + (_htab->s##SECTION)->output_offset + OFFSET;                   \
-    BFD_ASSERT ((long) SYM_IDX != -1);                                 \
-    _rel.r_info = ELF32_R_INFO (SYM_IDX, TYPE);                                \
-    bfd_elf32_swap_reloca_out (BFD, &_rel, _loc);                      \
+    if (_htab->dynamic_sections_created == TRUE)                               \
+      {                                                                        \
+       BFD_ASSERT (_htab->srel##SECTION &&_htab->srel##SECTION->contents); \
+       _loc = _htab->srel##SECTION->contents                           \
+         + ((_htab->srel##SECTION->reloc_count)                        \
+            * sizeof (Elf32_External_Rela));                           \
+       _htab->srel##SECTION->reloc_count++;                            \
+       _rel.r_addend = ADDEND;                                         \
+       _rel.r_offset = (_htab->s##SECTION)->output_section->vma        \
+         + (_htab->s##SECTION)->output_offset + OFFSET;                \
+       BFD_ASSERT ((long) SYM_IDX != -1);                              \
+       _rel.r_info = ELF32_R_INFO (SYM_IDX, TYPE);                     \
+       bfd_elf32_swap_reloca_out (BFD, &_rel, _loc);                   \
+      }                                                                        \
   }
 
 
@@ -728,9 +731,11 @@ arc_elf_merge_attributes (bfd *ibfd, struct bfd_link_info *info)
 
        case Tag_ARC_ABI_pic:
          tagname = "PIC";
+         /* fall through */
        case Tag_ARC_ABI_sda:
          if (!tagname)
            tagname = "SDA";
+         /* fall through */
        case Tag_ARC_ABI_tls:
          {
            const char *tagval[] = { "Absent", "MWDT", "GNU" };
@@ -756,9 +761,11 @@ arc_elf_merge_attributes (bfd *ibfd, struct bfd_link_info *info)
 
        case Tag_ARC_ABI_double_size:
          tagname = "Double size";
+         /* fall through */
        case Tag_ARC_ABI_enumsize:
          if (!tagname)
            tagname = "Enum size";
+         /* fall through */
        case Tag_ARC_ABI_exceptions:
          if (!tagname)
            tagname = "ABI exceptions";
@@ -1581,7 +1588,12 @@ elf_arc_relocate_section (bfd *                    output_bfd,
 
          while (h->root.type == bfd_link_hash_indirect
                 || h->root.type == bfd_link_hash_warning)
+         {
+           struct elf_link_hash_entry *h_old = h;
            h = (struct elf_link_hash_entry *) h->root.u.i.link;
+           if (h->got.glist == 0 && h_old->got.glist != h->got.glist)
+             h->got.glist = h_old->got.glist;
+         }
 
          /* TODO: Need to validate what was the intention.  */
          /* BFD_ASSERT ((h->dynindx == -1) || (h->forced_local != 0)); */
@@ -1701,16 +1713,22 @@ elf_arc_relocate_section (bfd *                   output_bfd,
            }
        }
 
+
+#define IS_ARC_PCREL_TYPE(TYPE) \
+  (   (TYPE == R_ARC_PC32)      \
+   || (TYPE == R_ARC_32_PCREL))
+
       switch (r_type)
        {
          case R_ARC_32:
          case R_ARC_32_ME:
          case R_ARC_PC32:
          case R_ARC_32_PCREL:
-           if ((bfd_link_pic (info))
-               && ((r_type != R_ARC_PC32 && r_type != R_ARC_32_PCREL)
+           if (bfd_link_pic (info)
+               && (!IS_ARC_PCREL_TYPE (r_type)
                    || (h != NULL
                        && h->dynindx != -1
+                       && !h->def_regular
                        && (!info->symbolic || !h->def_regular))))
              {
                Elf_Internal_Rela outrel;
@@ -1727,6 +1745,7 @@ elf_arc_relocate_section (bfd *                     output_bfd,
                                                           info,
                                                           input_section,
                                                           rel->r_offset);
+
                if (outrel.r_offset == (bfd_vma) -1)
                  skip = TRUE;
 
@@ -1734,10 +1753,6 @@ elf_arc_relocate_section (bfd *                    output_bfd,
                outrel.r_offset += (input_section->output_section->vma
                                    + input_section->output_offset);
 
-#define IS_ARC_PCREL_TYPE(TYPE) \
-  (   (TYPE == R_ARC_PC32)      \
-   || (TYPE == R_ARC_32_PCREL))
-
                if (skip)
                  {
                    memset (&outrel, 0, sizeof outrel);
@@ -1745,10 +1760,10 @@ elf_arc_relocate_section (bfd *                   output_bfd,
                  }
                else if (h != NULL
                         && h->dynindx != -1
-                        && ((IS_ARC_PCREL_TYPE (r_type))
-                        || !(bfd_link_executable (info)
-                             || SYMBOLIC_BIND (info, h))
-                        || ! h->def_regular))
+                        && (IS_ARC_PCREL_TYPE (r_type)
+                            || !(bfd_link_executable (info)
+                                 || SYMBOLIC_BIND (info, h))
+                            || ! h->def_regular))
                  {
                    BFD_ASSERT (h != NULL);
                    if ((input_section->flags & SEC_ALLOC) != 0)
@@ -1931,7 +1946,8 @@ elf_arc_check_relocs (bfd *                        abfd,
               and the dynamic linker can not resolve these.  However
               the error should not occur for e.g. debugging or
               non-readonly sections.  */
-           if ((bfd_link_dll (info) && !bfd_link_pie (info))
+           if (h != NULL
+               && (bfd_link_dll (info) && !bfd_link_pie (info))
                && (sec->flags & SEC_ALLOC) != 0
                && (sec->flags & SEC_READONLY) != 0
                && ((sec->flags & SEC_CODE) != 0
This page took 0.025216 seconds and 4 git commands to generate.