From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18253 invoked by alias); 23 Apr 2011 01:17:37 -0000 Received: (qmail 18245 invoked by uid 22791); 23 Apr 2011 01:17:36 -0000 X-SWARE-Spam-Status: No, hits=-4.6 required=5.0 tests=AWL,BAYES_00,NO_DNS_FOR_FROM,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mga01.intel.com (HELO mga01.intel.com) (192.55.52.88) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 23 Apr 2011 01:17:21 +0000 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP; 22 Apr 2011 18:17:18 -0700 X-ExtLoop1: 1 Received: from gnu-6.sc.intel.com ([10.3.194.135]) by fmsmga001.fm.intel.com with ESMTP; 22 Apr 2011 18:17:18 -0700 Received: by gnu-6.sc.intel.com (Postfix, from userid 500) id 5A0EC180F1A; Fri, 22 Apr 2011 18:17:18 -0700 (PDT) Date: Sat, 23 Apr 2011 01:17:00 -0000 From: "H.J. Lu" To: binutils@sourceware.org Subject: PATCH: Warn relocation in readonly section in a shared object Message-ID: <20110423011718.GA2480@intel.com> Reply-To: "H.J. Lu" MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2011-04/txt/msg00330.txt.bz2 Hi, I checked in this patch to warn relocation in readonly section in a shared object. H.J. --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 4d98456..cc10c52 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,11 @@ +2011-04-22 H.J. Lu + + * 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 PR ld/12694 diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c index bb79f89..e32ec83 100644 --- a/bfd/elf32-i386.c +++ b/bfd/elf32-i386.c @@ -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; + } } } } diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index 8d00edd..a02b3e8 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -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; + } } } }