From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11700 invoked by alias); 1 Jun 2004 16:59:08 -0000 Mailing-List: contact binutils-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sources.redhat.com Received: (qmail 11683 invoked from network); 1 Jun 2004 16:59:07 -0000 Received: from unknown (HELO iguana.mbuf.com) (209.19.166.52) by sourceware.org with SMTP; 1 Jun 2004 16:59:07 -0000 Received: (qmail 12945 invoked from network); 1 Jun 2004 16:59:06 -0000 Received: from localhost (HELO ?127.0.0.1?) (127.0.0.1) by localhost with SMTP; 1 Jun 2004 16:59:06 -0000 Mime-Version: 1.0 (Apple Message framework v613) In-Reply-To: <20040529060633.GH3368@bubble.modra.org> References: <20040528145608.GA556@nevyn.them.org> <20040529060633.GH3368@bubble.modra.org> Content-Type: multipart/mixed; boundary=Apple-Mail-5-427765898 Message-Id: From: David Poole Subject: Re: DT_TEXTREL/.dynamic issue with the binutils 2.15 linker on ARM and Linux Date: Tue, 01 Jun 2004 16:59:00 -0000 To: binutils@sources.redhat.com X-SW-Source: 2004-06/txt/msg00010.txt.bz2 --Apple-Mail-5-427765898 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed Content-length: 441 On May 29, 2004, at 12:06 AM, Alan Modra wrote: > On Fri, May 28, 2004 at 10:56:09AM -0400, Daniel Jacobowitz wrote: >> I don't know why DT_TEXTREL isn't there for this case. It should be. > > Perhaps because elf32-arm.h doesn't have something like > readonly_dynrelocs as implemented in other backends. Looking at elf32-i386.c and elf32-s390.c, I copied the readonly_dynrelocs() and the call in elf_(i386|s390)_size_dynamic_sections. --Apple-Mail-5-427765898 Content-Transfer-Encoding: 7bit Content-Type: application/octet-stream; x-unix-mode=0644; name="binutils-2.15-elf32-arm-textrel.patch" Content-Disposition: attachment; filename=binutils-2.15-elf32-arm-textrel.patch Content-length: 2009 diff -uNr binutils-2.15.orig/ binutils-2.15 diff -uNr binutils-2.15.orig/bfd/elf32-arm.h binutils-2.15/bfd/elf32-arm.h --- binutils-2.15.orig/bfd/elf32-arm.h 2004-05-17 13:35:58.000000000 -0600 +++ binutils-2.15/bfd/elf32-arm.h 2004-06-01 10:44:52.000000000 -0600 @@ -87,6 +87,8 @@ #endif static bfd_boolean allocate_dynrelocs PARAMS ((struct elf_link_hash_entry *h, PTR inf)); +static bfd_boolean elf32_arm_readonly_dynrelocs + PARAMS ((struct elf_link_hash_entry *, PTR)); static bfd_boolean create_got_section PARAMS ((bfd * dynobj, struct bfd_link_info * info)); static bfd_boolean elf32_arm_create_dynamic_sections @@ -3457,6 +3459,37 @@ return TRUE; } +/* Find any dynamic relocs that apply to read-only sections. */ + +static bfd_boolean +elf32_arm_readonly_dynrelocs (h, inf) + struct elf_link_hash_entry *h; + PTR inf; +{ + struct elf32_arm_link_hash_entry *eh; + struct elf32_arm_relocs_copied *p; + + if (h->root.type == bfd_link_hash_warning) + h = (struct elf_link_hash_entry *) h->root.u.i.link; + + eh = (struct elf32_arm_link_hash_entry *) h; + for (p = eh->relocs_copied; p != NULL; p = p->next) + { + asection *s = p->section; + + if (s != NULL && (s->flags & SEC_READONLY) != 0) + { + struct bfd_link_info *info = (struct bfd_link_info *) inf; + + info->flags |= DF_TEXTREL; + + /* Not an error, just cut short the traversal. */ + return FALSE; + } + } + return TRUE; +} + /* Set the sizes of the dynamic sections. */ static bfd_boolean @@ -3666,6 +3699,12 @@ return FALSE; } + /* If any dynamic relocs apply to a read-only section, + then we need a DT_TEXTREL entry. */ + if ((info->flags & DF_TEXTREL) == 0) + elf_link_hash_traverse (&htab->root, elf32_arm_readonly_dynrelocs, + (PTR) info); + if ((info->flags & DF_TEXTREL) != 0) { if (!add_dynamic_entry (DT_TEXTREL, 0)) --Apple-Mail-5-427765898 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed Content-length: 1627 Solves my DT_TEXTREL problem but needs more testing. As a related question, in the original elf32-arm.h, the check for DF_TEXTREL was done outside the if(relocs): if (relocs) { if ( !add_dynamic_entry (DT_REL, 0) || !add_dynamic_entry (DT_RELSZ, 0) || !add_dynamic_entry (DT_RELENT, sizeof (Elf32_External_Rel))) return FALSE; } if ((info->flags & DF_TEXTREL) != 0) { if (!add_dynamic_entry (DT_TEXTREL, 0)) return FALSE; info->flags |= DF_TEXTREL; } but in elf32-i386.c and elf32-s390.c, the DF_TEXTREL handling is done inside the if(relocs): if (relocs) { if (!add_dynamic_entry (DT_REL, 0) || !add_dynamic_entry (DT_RELSZ, 0) || !add_dynamic_entry (DT_RELENT, sizeof (Elf32_External_Rel))) return FALSE; /* If any dynamic relocs apply to a read-only section, then we need a DT_TEXTREL entry. */ if ((info->flags & DF_TEXTREL) == 0) elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, (PTR) info); if ((info->flags & DF_TEXTREL) != 0) { if (!add_dynamic_entry (DT_TEXTREL, 0)) return FALSE; } } Is this an issue in elf32-arm.h or a simply small optimization that causes no trouble otherwise? -- David Poole Mobility Electronics, Idaho http://www.mobl.com 960 Broadway Avenue, Suite 300 Boise, ID 83706 --Apple-Mail-5-427765898--