This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[committed] fix DF_TEXTREL addition on mips


For mips after my cfi changes we were occasionally emitting DF_TEXTREL
when, in fact, we weren't generating the relocation at all. This was
giving glibc all sorts of headaches according to the comments from
Daniel :)

The best bet is to delay determining whether or not to set DF_TEXTREL
until we've actually emitted the relocation into the object file.

I've committed this to mainline now and will commit to the 2.16 branch
in a couple of days if I haven't broken anything else by accident.

Tested on mips-elf mips-linux-gnu mips-sgi-irix without regressions.
Tested with gcc for mips-elf and mips64-elf without regressions (though
those aren't a good test).

As a note this code should probably be cleaned up.

-eric

bfd/ChangeLog:

2005-03-23  Eric Christopher  <echristo@redhat.com>

	* elfxx-mips.c (MIPS_ELF_READONLY_SECTION): New.
	(mips_elf_calculate_relocation): Use. Define DF_TEXTREL
	after emitting relocation.
	(_bfd_mips_elf_adjust_dynamic_symbol): Ditto.
	(_bfd_mips_elf_check_relocs): Remove code to set DF_TEXTREL
	and readonly_reloc.

ld/testsuite/ChangeLog:

2005-03-23  Eric Christopher  <echristo@redhat.com>

	* ld-mips-elf/textrel-1.s, ld-mips-elf/textrel-1.d: New
	test.
	* ld-mips-elf/mips-elf.exp: Call it.
	* ld-mips-elf/rel32-n32.d: Update for DF_TEXTREL removal.
	* ld-mips-elf/rel32-o32.d: Ditto.
	* ld-mips-elf/rel64.d: Ditto.


Index: bfd/elfxx-mips.c
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-mips.c,v
retrieving revision 1.127
diff -u -p -w -r1.127 elfxx-mips.c
--- bfd/elfxx-mips.c	20 Mar 2005 23:36:19 -0000	1.127
+++ bfd/elfxx-mips.c	23 Mar 2005 03:10:19 -0000
@@ -478,6 +478,11 @@ static bfd *reldyn_sorting_bfd;
 #define MIPS_ELF_OPTIONS_SECTION_NAME(abfd) \
   (NEWABI_P (abfd) ? ".MIPS.options" : ".options")
 
+/* Whether the section is readonly.  */
+#define MIPS_ELF_READONLY_SECTION(sec)			\
+  ((sec->flags & (SEC_ALLOC | SEC_LOAD | SEC_READONLY))	\
+   == (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
+
 /* The name of the stub section.  */
 #define MIPS_ELF_STUB_SECTION_NAME(abfd) ".MIPS.stubs"
 
@@ -4005,6 +4010,10 @@ mips_elf_calculate_relocation (bfd *abfd
 						   &value,
 						   input_section))
 	    return bfd_reloc_undefined;
+
+	  /* If we've written this we need to set DF_TEXTREL here.  */
+	  if (MIPS_ELF_READONLY_SECTION (input_section))
+	    info->flags |= DF_TEXTREL;
 	}
       else
 	{
@@ -6101,20 +6110,13 @@ _bfd_mips_elf_check_relocs (bfd *abfd, s
 		  if (sreloc == NULL)
 		    return FALSE;
 		}
-#define MIPS_READONLY_SECTION (SEC_ALLOC | SEC_LOAD | SEC_READONLY)
+
 	      if (info->shared)
-		{
 		  /* When creating a shared object, we must copy these
 		     reloc types into the output file as R_MIPS_REL32
 		     relocs.  We make room for this reloc in the
 		     .rel.dyn reloc section.  */
 		  mips_elf_allocate_dynamic_relocations (dynobj, 1);
-		  if ((sec->flags & MIPS_READONLY_SECTION)
-		      == MIPS_READONLY_SECTION)
-		    /* We tell the dynamic linker that there are
-		       relocations against the text segment.  */
-		    info->flags |= DF_TEXTREL;
-		}
 	      else
 		{
 		  struct mips_elf_link_hash_entry *hmips;
@@ -6123,11 +6125,6 @@ _bfd_mips_elf_check_relocs (bfd *abfd, s
                      defined in a dynamic object.  */
 		  hmips = (struct mips_elf_link_hash_entry *) h;
 		  ++hmips->possibly_dynamic_relocs;
-		  if ((sec->flags & MIPS_READONLY_SECTION)
-		      == MIPS_READONLY_SECTION)
-		    /* We need it to tell the dynamic linker if there
-		       are relocations against the text segment.  */
-		    hmips->readonly_reloc = TRUE;
 		}
 
 	      /* Even though we don't directly need a GOT entry for
@@ -6423,9 +6420,12 @@ _bfd_mips_elf_adjust_dynamic_symbol (str
       && (h->root.type == bfd_link_hash_defweak
 	  || !h->def_regular))
     {
+      asection *sec;
+      sec = mips_elf_rel_dyn_section (dynobj, FALSE);
       mips_elf_allocate_dynamic_relocations (dynobj,
 					     hmips->possibly_dynamic_relocs);
-      if (hmips->readonly_reloc)
+
+      if (MIPS_ELF_READONLY_SECTION (sec))
 	/* We tell the dynamic linker that there are relocations
 	   against the text segment.  */
 	info->flags |= DF_TEXTREL;
Index: ld/testsuite/ld-mips-elf/mips-elf.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-mips-elf/mips-elf.exp,v
retrieving revision 1.29
diff -u -p -w -r1.29 mips-elf.exp
--- ld/testsuite/ld-mips-elf/mips-elf.exp	5 Mar 2005 00:01:44 -0000	1.29
+++ ld/testsuite/ld-mips-elf/mips-elf.exp	23 Mar 2005 03:10:20 -0000
@@ -101,6 +101,10 @@ if {$has_newabi} {
     run_dump_test "mips16-hilo-n32"
 }
 
+if { $linux_gnu } {
+    run_dump_test "textrel-1"
+}
+
 # For tests which may involve multiple files, use run_ld_link_tests.
 
 # List contains test-items with 3 items followed by 2 lists:
Index: ld/testsuite/ld-mips-elf/rel32-n32.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-mips-elf/rel32-n32.d,v
retrieving revision 1.4
diff -u -p -w -r1.4 rel32-n32.d
--- ld/testsuite/ld-mips-elf/rel32-n32.d	31 Jan 2005 22:01:02 -0000	1.4
+++ ld/testsuite/ld-mips-elf/rel32-n32.d	23 Mar 2005 03:10:20 -0000
@@ -4,12 +4,12 @@
 #readelf: -x 5 -r
 #ld: -shared -melf32btsmipn32
 
-Relocation section '.rel.dyn' at offset 0x304 contains 2 entries:
+Relocation section '.rel.dyn' at offset 0x2fc contains 2 entries:
  Offset     Info    Type            Sym.Value  Sym. Name
 00000000  00000000 R_MIPS_NONE      
-00000330  00000003 R_MIPS_REL32     
+00000320  00000003 R_MIPS_REL32     
 
 Hex dump of section '.text':
-  0x00000320 00000000 00000000 00000000 00000000 ................
-  0x00000330 00000330 00000000 00000000 00000000 ................
-  0x00000340 00000000 00000000 00000000 00000000 ................
+  0x00000310 00000000 00000000 00000000 00000000 ................
+  0x00000320 00000320 00000000 00000000 00000000 ................
+  0x00000330 00000000 00000000 00000000 00000000 ................
Index: ld/testsuite/ld-mips-elf/rel32-o32.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-mips-elf/rel32-o32.d,v
retrieving revision 1.3
diff -u -p -w -r1.3 rel32-o32.d
--- ld/testsuite/ld-mips-elf/rel32-o32.d	31 Jan 2005 22:01:02 -0000	1.3
+++ ld/testsuite/ld-mips-elf/rel32-o32.d	23 Mar 2005 03:10:20 -0000
@@ -4,7 +4,7 @@
 #readelf: -x 6 -r
 #ld: -shared -melf32btsmip
 
-Relocation section '.rel.dyn' at offset 0x31c contains 2 entries:
+Relocation section '.rel.dyn' at offset 0x314 contains 2 entries:
  Offset     Info    Type            Sym.Value  Sym. Name
 00000000  00000000 R_MIPS_NONE      
 00000340  00000003 R_MIPS_REL32     
Index: ld/testsuite/ld-mips-elf/rel64.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-mips-elf/rel64.d,v
retrieving revision 1.3
diff -u -p -w -r1.3 rel64.d
--- ld/testsuite/ld-mips-elf/rel64.d	31 Jan 2005 22:01:02 -0000	1.3
+++ ld/testsuite/ld-mips-elf/rel64.d	23 Mar 2005 03:10:20 -0000
@@ -4,16 +4,16 @@
 #readelf: -x 6 -r
 #ld: -shared -melf64btsmip
 
-Relocation section '.rel.dyn' at offset 0x498 contains 2 entries:
+Relocation section '.rel.dyn' at offset 0x488 contains 2 entries:
   Offset          Info           Type           Sym. Value    Sym. Name
 000000000000  000000000000 R_MIPS_NONE      
                     Type2: R_MIPS_NONE      
                     Type3: R_MIPS_NONE      
-0000000004d0  000000001203 R_MIPS_REL32     
+0000000004c0  000000001203 R_MIPS_REL32     
                     Type2: R_MIPS_64        
                     Type3: R_MIPS_NONE      
 
 Hex dump of section '.text':
-  0x000004c0 00000000 00000000 00000000 00000000 ................
-  0x000004d0 00000000 000004d0 00000000 00000000 ................
-  0x000004e0 00000000 00000000 00000000 00000000 ................
+  0x000004b0 00000000 00000000 00000000 00000000 ................
+  0x000004c0 00000000 000004c0 00000000 00000000 ................
+  0x000004d0 00000000 00000000 00000000 00000000 ................
Index: ld/testsuite/ld-mips-elf/textrel-1.d
===================================================================
RCS file: ld/testsuite/ld-mips-elf/textrel-1.d
diff -N ld/testsuite/ld-mips-elf/textrel-1.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-mips-elf/textrel-1.d	23 Mar 2005 03:10:20 -0000
@@ -0,0 +1,26 @@
+#name: MIPS textrel-1
+#source: textrel-1.s
+#as: -EB -n32
+#ld: -shared -melf32btsmipn32
+#readelf: -d
+
+Dynamic section at offset 0xb4 contains 18 entries:
+  Tag        Type                         Name/Value
+ 0x00000004 \(HASH\)                       0x16c
+ 0x00000005 \(STRTAB\)                     0x30c
+ 0x00000006 \(SYMTAB\)                     0x1fc
+ 0x0000000a \(STRSZ\)                      84 \(bytes\)
+ 0x0000000b \(SYMENT\)                     16 \(bytes\)
+ 0x00000015 \(DEBUG\)                      0x0
+ 0x00000003 \(PLTGOT\)                     0x1003e0
+ 0x00000011 \(REL\)                        0x360
+ 0x00000012 \(RELSZ\)                      8 \(bytes\)
+ 0x00000013 \(RELENT\)                     8 \(bytes\)
+ 0x70000001 \(MIPS_RLD_VERSION\)           1
+ 0x70000005 \(MIPS_FLAGS\)                 NOTPOT
+ 0x70000006 \(MIPS_BASE_ADDRESS\)          0
+ 0x7000000a \(MIPS_LOCAL_GOTNO\)           7
+ 0x70000011 \(MIPS_SYMTABNO\)              17
+ 0x70000012 \(MIPS_UNREFEXTNO\)            12
+ 0x70000013 \(MIPS_GOTSYM\)                0x11
+ 0x00000000 \(NULL\)                       0x0
Index: ld/testsuite/ld-mips-elf/textrel-1.s
===================================================================
RCS file: ld/testsuite/ld-mips-elf/textrel-1.s
diff -N ld/testsuite/ld-mips-elf/textrel-1.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-mips-elf/textrel-1.s	23 Mar 2005 03:10:20 -0000
@@ -0,0 +1,9 @@
+        .globl foo
+foo:
+        .cfi_startproc
+        nop
+        .cfi_def_cfa_offset 4
+        nop
+        .cfi_register $29, $0
+        nop
+        .cfi_endproc

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]