s390: Check UNDEFWEAK_NO_DYNAMIC_RELOC
authorH.J. Lu <hjl.tools@gmail.com>
Sat, 14 Oct 2017 18:06:00 +0000 (11:06 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Sat, 14 Oct 2017 18:06:20 +0000 (11:06 -0700)
Don't generate dynamic relocation against weak undefined symbol if it
is resolved to zero.  FIXME: UNDEFWEAK_NO_DYNAMIC_RELOC may need to be
checked in more places.

PR ld/22269
* elf32-s390.c (allocate_dynrelocs): Discard dynamic
relocations if UNDEFWEAK_NO_DYNAMIC_RELOC is true.
(elf_s390_relocate_section): Don't generate dynamic relocation
if UNDEFWEAK_NO_DYNAMIC_RELOC is true.
* elf64-s390.c (allocate_dynrelocs): Discard dynamic
relocations if UNDEFWEAK_NO_DYNAMIC_RELOC is true.
(elf_s390_relocate_section): Don't generate dynamic relocation
if UNDEFWEAK_NO_DYNAMIC_RELOC is true.

bfd/ChangeLog
bfd/elf32-s390.c
bfd/elf64-s390.c

index 21a01a1f109b3010cef2961160a148388feb0f51..096e5600851bdb9db04c2066260f07970b66c85a 100644 (file)
@@ -1,3 +1,15 @@
+2017-10-14  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/22269
+       * elf32-s390.c (allocate_dynrelocs): Discard dynamic
+       relocations if UNDEFWEAK_NO_DYNAMIC_RELOC is true.
+       (elf_s390_relocate_section): Don't generate dynamic relocation
+       if UNDEFWEAK_NO_DYNAMIC_RELOC is true.
+       * elf64-s390.c (allocate_dynrelocs): Discard dynamic
+       relocations if UNDEFWEAK_NO_DYNAMIC_RELOC is true.
+       (elf_s390_relocate_section): Don't generate dynamic relocation
+       if UNDEFWEAK_NO_DYNAMIC_RELOC is true.
+
 2017-10-14  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/22269
index 81e1a9df1302d533fd6b7f5b4b9d63124b2c8b09..eaf2bf14c01408913d909308838caa266e780f54 100644 (file)
@@ -1947,7 +1947,8 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
       if (eh->dyn_relocs != NULL
          && h->root.type == bfd_link_hash_undefweak)
        {
-         if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
+         if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
+             || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
            eh->dyn_relocs = NULL;
 
          /* Make sure undefined weak symbols are output as a dynamic
@@ -2357,6 +2358,7 @@ elf_s390_relocate_section (bfd *output_bfd,
       bfd_reloc_status_type r;
       int tls_type;
       asection *base_got = htab->elf.sgot;
+      bfd_boolean resolved_to_zero;
 
       r_type = ELF32_R_TYPE (rel->r_info);
       if (r_type == (int) R_390_GNU_VTINHERIT
@@ -2448,6 +2450,9 @@ elf_s390_relocate_section (bfd *output_bfd,
       if (bfd_link_relocatable (info))
        continue;
 
+      resolved_to_zero = (h != NULL
+                         && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h));
+
       switch (r_type)
        {
        case R_390_GOTPLT12:
@@ -2836,7 +2841,8 @@ elf_s390_relocate_section (bfd *output_bfd,
 
          if ((bfd_link_pic (info)
               && (h == NULL
-                  || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+                  || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+                      && !resolved_to_zero)
                   || h->root.type != bfd_link_hash_undefweak)
               && ((r_type != R_390_PC16
                    && r_type != R_390_PC12DBL
index 73d0331f8e41a725959465756ef0d08b3f6d1dfc..c12688027bfb938a914c0ef72a1056d91940e74f 100644 (file)
@@ -1890,7 +1890,8 @@ allocate_dynrelocs (struct elf_link_hash_entry *h,
       if (eh->dyn_relocs != NULL
          && h->root.type == bfd_link_hash_undefweak)
        {
-         if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
+         if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
+             || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
            eh->dyn_relocs = NULL;
 
          /* Make sure undefined weak symbols are output as a dynamic
@@ -2307,6 +2308,7 @@ elf_s390_relocate_section (bfd *output_bfd,
       bfd_reloc_status_type r;
       int tls_type;
       asection *base_got = htab->elf.sgot;
+      bfd_boolean resolved_to_zero;
 
       r_type = ELF64_R_TYPE (rel->r_info);
       if (r_type == (int) R_390_GNU_VTINHERIT
@@ -2402,6 +2404,9 @@ elf_s390_relocate_section (bfd *output_bfd,
       if (bfd_link_relocatable (info))
        continue;
 
+      resolved_to_zero = (h != NULL
+                         && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h));
+
       switch (r_type)
        {
        case R_390_GOTPLT12:
@@ -2804,7 +2809,8 @@ elf_s390_relocate_section (bfd *output_bfd,
 
          if ((bfd_link_pic (info)
               && (h == NULL
-                  || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+                  || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+                      && !resolved_to_zero)
                   || h->root.type != bfd_link_hash_undefweak)
               && ((r_type != R_390_PC16
                    && r_type != R_390_PC12DBL
This page took 0.034359 seconds and 4 git commands to generate.