Warn relocation in readonly section in a shared object.
authorH.J. Lu <hjl.tools@gmail.com>
Sat, 23 Apr 2011 01:16:31 +0000 (01:16 +0000)
committerH.J. Lu <hjl.tools@gmail.com>
Sat, 23 Apr 2011 01:16:31 +0000 (01:16 +0000)
2011-04-22  H.J. Lu  <hongjiu.lu@intel.com>

* elf32-i386.c (elf_i386_readonly_dynrelocs): Warn relocation
in readonly section in a shared object.
(elf_i386_size_dynamic_sections): Likewise.
* elf64-x86-64.c (elf_x86_64_readonly_dynrelocs): Likewise.
(elf_x86_64_size_dynamic_sections): Likewise.

bfd/ChangeLog
bfd/elf32-i386.c
bfd/elf64-x86-64.c

index 4d98456808827d80e561a9be179f593692b1ace2..cc10c522ff4370d3823953d8d529a6dc9b7e00b4 100644 (file)
@@ -1,3 +1,11 @@
+2011-04-22  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * elf32-i386.c (elf_i386_readonly_dynrelocs): Warn relocation
+       in readonly section in a shared object.
+       (elf_i386_size_dynamic_sections): Likewise.
+       * elf64-x86-64.c (elf_x86_64_readonly_dynrelocs): Likewise.
+       (elf_x86_64_size_dynamic_sections): Likewise.
+
 2011-04-21  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/12694
index bb79f897d79f56836f5c78d7c2375798f5660c8f..e32ec831c72b03bb5ca4221f282e155e823de244 100644 (file)
@@ -2399,6 +2399,11 @@ elf_i386_readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf)
 
          info->flags |= DF_TEXTREL;
 
+         if (info->warn_shared_textrel && info->shared)
+           info->callbacks->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'.\n"),
+                                   p->sec->owner, h->root.root.string,
+                                   p->sec);
+
          /* Not an error, just cut short the traversal.  */
          return FALSE;
        }
@@ -2482,7 +2487,13 @@ elf_i386_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
                  srel = elf_section_data (p->sec)->sreloc;
                  srel->size += p->count * sizeof (Elf32_External_Rel);
                  if ((p->sec->output_section->flags & SEC_READONLY) != 0)
-                   info->flags |= DF_TEXTREL;
+                   {
+                     info->flags |= DF_TEXTREL;
+                     if (info->warn_shared_textrel && info->shared)
+                       info->callbacks->einfo (_("%P: %B: warning: relocation in readonly section `%A'.\n"),
+                                               p->sec->owner, p->sec);
+                     break;
+                   }
                }
            }
        }
index 8d00eddb3da5699e8a6c2ef1409608594ea69260..a02b3e8c547f8bc9a7135d0306c5e969b7f96013 100644 (file)
@@ -2314,6 +2314,11 @@ elf_x86_64_readonly_dynrelocs (struct elf_link_hash_entry *h,
 
          info->flags |= DF_TEXTREL;
 
+         if (info->warn_shared_textrel && info->shared)
+           info->callbacks->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'.\n"),
+                                   p->sec->owner, h->root.root.string,
+                                   p->sec);
+
          /* Not an error, just cut short the traversal.  */
          return FALSE;
        }
@@ -2393,7 +2398,13 @@ elf_x86_64_size_dynamic_sections (bfd *output_bfd,
                  srel = elf_section_data (p->sec)->sreloc;
                  srel->size += p->count * bed->s->sizeof_rela;
                  if ((p->sec->output_section->flags & SEC_READONLY) != 0)
-                   info->flags |= DF_TEXTREL;
+                   {
+                     info->flags |= DF_TEXTREL;
+                     if (info->warn_shared_textrel && info->shared)
+                       info->callbacks->einfo (_("%P: %B: warning: relocation in readonly section `%A'.\n"),
+                                               p->sec->owner, p->sec);
+                     break;
+                   }
                }
            }
        }