]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - bfd/elflink.c
aarch64: fix incorrect encoding for system register pmsdsfr_el1
[thirdparty/binutils-gdb.git] / bfd / elflink.c
index 321e3d5e2ff614daeb20ff41b340b3a93aa0b789..6db6a9c0b4702c66d73edba87294e2a59ffafcf5 100644 (file)
@@ -2942,8 +2942,7 @@ _bfd_elf_link_output_relocs (bfd *output_bfd,
                             asection *input_section,
                             Elf_Internal_Shdr *input_rel_hdr,
                             Elf_Internal_Rela *internal_relocs,
-                            struct elf_link_hash_entry **rel_hash
-                              ATTRIBUTE_UNUSED)
+                            struct elf_link_hash_entry **rel_hash)
 {
   Elf_Internal_Rela *irela;
   Elf_Internal_Rela *irelaend;
@@ -2986,9 +2985,13 @@ _bfd_elf_link_output_relocs (bfd *output_bfd,
                      * bed->s->int_rels_per_ext_rel);
   while (irela < irelaend)
     {
+      if (rel_hash && *rel_hash)
+       (*rel_hash)->has_reloc = 1;
       (*swap_out) (output_bfd, irela, erel);
       irela += bed->s->int_rels_per_ext_rel;
       erel += input_rel_hdr->sh_entsize;
+      if (rel_hash)
+       rel_hash++;
     }
 
   /* Bump the counter, so that we know where to add the next set of
@@ -6261,9 +6264,11 @@ elf_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info)
 
              if (!is_elf_hash_table (info->hash))
                continue;
-             /* Ignore the archive if the symbol isn't defined in a
-                shared object.  */
-             if (!((struct elf_link_hash_entry *) h)->def_dynamic)
+             struct elf_link_hash_entry *eh
+               = (struct elf_link_hash_entry *) h;
+             /* Ignore the archive if the symbol isn't referenced by a
+                regular object or isn't defined in a shared object.  */
+             if (!eh->ref_regular || !eh->def_dynamic)
                continue;
              /* Ignore the dynamic definition if symbol is first
                 defined in this archive.  */
@@ -10767,6 +10772,13 @@ elf_link_output_extsym (struct bfd_hash_entry *bh, void *data)
           && (h->root.u.undef.abfd->flags & BFD_PLUGIN) != 0)
     strip = true;
 
+  /* Remember if this symbol should be stripped.  */
+  bool should_strip = strip;
+
+  /* Strip undefined weak symbols link if they don't have relocation.  */
+  if (!strip)
+    strip = !h->has_reloc && h->root.type == bfd_link_hash_undefweak;
+
   type = h->type;
 
   /* If we're stripping it, and it's not a dynamic symbol, there's
@@ -10915,6 +10927,10 @@ elf_link_output_extsym (struct bfd_hash_entry *bh, void *data)
          eoinfo->failed = true;
          return false;
        }
+      /* If a symbol is in the dynamic symbol table and isn't a
+        should-strip symbol, also keep it in the symbol table.  */
+      if (!should_strip)
+       strip = false;
     }
 
   /* If we are marking the symbol as undefined, and there are no