Never emit R_ARM_PC24 relocations when linking

Daniel Jacobowitz drow@mvista.com
Tue Jan 13 20:11:00 GMT 2004


On Tue, Jan 13, 2004 at 01:36:55PM -0500, Daniel Jacobowitz wrote:
> On Tue, Jan 13, 2004 at 06:12:31PM +0000, Richard Earnshaw wrote:
> > > > > 
> > > > > > Yes.  The only difference I see in their handling now is a case I
> > > > > > missed in relocate_section, and some PC24 code that doesn't handle
> > > > > > PLT32 for interworking.
> > > > > > 
> > > > > 
> > > > > Are you going to address those in another iteration of this patch, or as a 
> > > > > separate one?
> > > > 
> > > > Separate.
> > > 
> > > OK then.
> > > 
> > 
> > Argh!  Unfortunately this has completely broken testing for arm-elf.  Just 
> > try and run the gcc testsuite when using the new linker -- it keeps trying 
> > to make PLT entries in a non-shared library environment :-(
> 
> Hmm, I did run the testsuite for arm-elf.  There were no problems - I
> could create shared libraries just fine for the ld tests.
> 
> Wait, you're saying the _GCC_ testsuite.  So it's creating PLT entries
> even when not creating shared libraries.  Yuck!  I will look at the
> problem this afternoon.

That tipped me off to the problem.  I'm not set up for the simulator
tests at the moment - I'll fix that - but this patch fixes the problem
I found in some quick testing.  Could you test it?

As a free bonus, it comes with a basic "static linking works" testcase.
Another year of this and we might end up with a respectable testsuite!

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

2004-01-13  Daniel Jacobowitz  <drow@mvista.com>

	* elf32-arm.h (elf32_arm_final_link_relocate): Check that we created
	the .plt section.
	(elf32_arm_check_relocs): Don't increment the PLT refcount for
	relocs which would not use the PLT.

2004-01-13  Daniel Jacobowitz  <drow@mvista.com>

	* testsuite/ld-arm/arm-elf.exp: Add arm-static-app test.
	* testsuite/ld-arm/arm-static-app.s,
	testsuite/ld-arm/arm-static-app.d,
	testsuite/ld-arm/arm-static-app.r: New files.

Index: bfd/elf32-arm.h
===================================================================
RCS file: /big/fsf/rsync/src-cvs/src/bfd/elf32-arm.h,v
retrieving revision 1.118
diff -u -p -r1.118 elf32-arm.h
--- bfd/elf32-arm.h	9 Jan 2004 16:53:45 -0000	1.118
+++ bfd/elf32-arm.h	13 Jan 2004 20:06:21 -0000
@@ -1317,9 +1317,12 @@ elf32_arm_final_link_relocate (howto, in
 	 branches in this object should go to it.  */
       if ((r_type != R_ARM_ABS32 && r_type != R_ARM_REL32)
 	  && h != NULL
+	  && splt != NULL
 	  && h->plt.offset != (bfd_vma) -1)
 	{
-	  BFD_ASSERT (splt != NULL);
+	  /* If we've created a .plt section, and assigned a PLT entry to
+	     this function, it should not be known to bind locally.  If
+	     it were, we would have cleared the PLT entry.  */
 	  BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info, h));
 
 	  value = (splt->output_section->vma
@@ -2937,12 +2940,15 @@ elf32_arm_check_relocs (abfd, info, sec,
 		  h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
 
 		/* We may need a .plt entry if the function this reloc
-		   refers to is in a different object.  */
+		   refers to is in a different object.  We can't tell for
+		   sure yet, because something later might force the
+		   symbol local.  */
 		if (ELF32_R_TYPE (rel->r_info) == R_ARM_PC24
 		    || ELF32_R_TYPE (rel->r_info) == R_ARM_PLT32)
-		  h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
-
-		h->plt.refcount += 1;
+		  {
+		    h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
+		    h->plt.refcount += 1;
+		  }
 	      }
 
 	    /* If we are creating a shared library, and this is a reloc
Index: ld/testsuite/ld-arm/arm-elf.exp
===================================================================
RCS file: /big/fsf/rsync/src-cvs/src/ld/testsuite/ld-arm/arm-elf.exp,v
retrieving revision 1.1
diff -u -p -r1.1 arm-elf.exp
--- ld/testsuite/ld-arm/arm-elf.exp	6 Jan 2004 21:47:38 -0000	1.1
+++ ld/testsuite/ld-arm/arm-elf.exp	13 Jan 2004 19:55:45 -0000
@@ -41,6 +41,9 @@ set armelftests {
     {"Simple dynamic application" "tmpdir/arm-lib.so" "" {arm-app.s}
      {{objdump -fdw arm-app.d} {objdump -Rw arm-app.r}}
      "arm-app"}
+    {"Simple static application" "" "" {arm-static-app.s}
+     {{objdump -fdw arm-static-app.d} {objdump -rw arm-static-app.r}}
+     "arm-static-app"}
 }
 
 run_ld_link_tests $armelftests
Index: ld/testsuite/ld-arm/arm-static-app.d
===================================================================
RCS file: ld/testsuite/ld-arm/arm-static-app.d
diff -N ld/testsuite/ld-arm/arm-static-app.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-arm/arm-static-app.d	13 Jan 2004 19:58:23 -0000
@@ -0,0 +1,24 @@
+
+tmpdir/arm-static-app:     file format elf32-littlearm
+architecture: arm, flags 0x00000112:
+EXEC_P, HAS_SYMS, D_PAGED
+start address 0x.*
+
+Disassembly of section .text:
+
+.* <_start>:
+    .*:	e1a0c00d 	mov	ip, sp
+    .*:	e92dd800 	stmdb	sp!, {fp, ip, lr, pc}
+    .*:	eb000001 	bl	.* <app_func>
+    .*:	e89d6800 	ldmia	sp, {fp, sp, lr}
+    .*:	e12fff1e 	bx	lr
+
+.* <app_func>:
+    .*:	e1a0c00d 	mov	ip, sp
+    .*:	e92dd800 	stmdb	sp!, {fp, ip, lr, pc}
+    .*:	eb000001 	bl	.* <app_func2>
+    .*:	e89d6800 	ldmia	sp, {fp, sp, lr}
+    .*:	e12fff1e 	bx	lr
+
+.* <app_func2>:
+    .*:	e12fff1e 	bx	lr
Index: ld/testsuite/ld-arm/arm-static-app.r
===================================================================
RCS file: ld/testsuite/ld-arm/arm-static-app.r
diff -N ld/testsuite/ld-arm/arm-static-app.r
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-arm/arm-static-app.r	13 Jan 2004 19:58:22 -0000
@@ -0,0 +1,3 @@
+
+tmpdir/arm-static-app:     file format elf32-littlearm
+
Index: ld/testsuite/ld-arm/arm-static-app.s
===================================================================
RCS file: ld/testsuite/ld-arm/arm-static-app.s
diff -N ld/testsuite/ld-arm/arm-static-app.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-arm/arm-static-app.s	13 Jan 2004 19:56:47 -0000
@@ -0,0 +1,20 @@
+	.text
+	.globl _start
+_start:
+	mov	ip, sp
+	stmdb	sp!, {r11, ip, lr, pc}
+	bl	app_func
+	ldmia	sp, {r11, sp, lr}
+	bx lr
+
+	.globl app_func
+app_func:
+	mov	ip, sp
+	stmdb	sp!, {r11, ip, lr, pc}
+	bl	app_func2
+	ldmia	sp, {r11, sp, lr}
+	bx lr
+
+	.globl app_func2
+app_func2:
+	bx	lr



More information about the Binutils mailing list