This is the mail archive of the binutils@sourceware.org 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]

[ARM] Relocation counting during gc sweep


This patch fixes a problem I saw while working on the STT_GNU_IFUNC support.
We can record dynamic relocs for quite a wide range of relocations:

	  case R_ARM_MOVW_ABS_NC:
	  case R_ARM_MOVT_ABS:
	  case R_ARM_THM_MOVW_ABS_NC:
	  case R_ARM_THM_MOVT_ABS:
	    [...]
	  case R_ARM_ABS32:
	  case R_ARM_ABS32_NOI:
	  case R_ARM_REL32:
	  case R_ARM_REL32_NOI:
	  case R_ARM_MOVW_PREL_NC:
	  case R_ARM_MOVT_PREL:
	  case R_ARM_THM_MOVW_PREL_NC:
	  case R_ARM_THM_MOVT_PREL:

(from elf32_arm_check_relocs) but we only sweep them for four:

	      if (r_type == R_ARM_ABS32
		  || r_type == R_ARM_REL32
                  || r_type == R_ARM_ABS32_NOI
                  || r_type == R_ARM_REL32_NOI)
		for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
		  if (p->sec == sec)
		    {
		      p->count -= 1;
		      if (ELF32_R_TYPE (rel->r_info) == R_ARM_REL32
			  || ELF32_R_TYPE (rel->r_info) == R_ARM_REL32_NOI)
			p->pc_count -= 1;
		      if (p->count == 0)
			*pp = p->next;
		      break;
		    }

This means that, for the attached testcase, we end up with two R_ARM_NONE
relocations for the discarded .text.foo.

Because we're discarding the whole section, it ought to be safe to remove
sec's entry unconditionally.  The patch does that by stealing from
elf32-ppc.c.

Tested on arm-linux-gnueabi and arm-eabi.  OK to install?

Richard


bfd/
	* elf32-arm.c (elf32_arm_gc_sweep_hook): Remove all registered
	dynamic relocs for the removed section.

ld/testsuite/
	* ld-arm/gc-thumb-lib.s, ld-arm/gc-thumb.s,
	ld-arm/gc-thumb.d: New test.
	* ld-arm/arm-elf.exp: Run it.

Index: bfd/elf32-arm.c
===================================================================
--- bfd/elf32-arm.c	2010-12-14 15:30:05.000000000 +0000
+++ bfd/elf32-arm.c	2010-12-14 15:34:35.000000000 +0000
@@ -10678,21 +10678,13 @@ elf32_arm_gc_sweep_hook (bfd *          
 		    eh->plt_thumb_refcount--;
 		}
 
-	      if (r_type == R_ARM_ABS32
-		  || r_type == R_ARM_REL32
-                  || r_type == R_ARM_ABS32_NOI
-                  || r_type == R_ARM_REL32_NOI)
-		for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
-		  if (p->sec == sec)
-		    {
-		      p->count -= 1;
-		      if (ELF32_R_TYPE (rel->r_info) == R_ARM_REL32
-			  || ELF32_R_TYPE (rel->r_info) == R_ARM_REL32_NOI)
-			p->pc_count -= 1;
-		      if (p->count == 0)
-			*pp = p->next;
-		      break;
-		    }
+	      for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
+		if (p->sec == sec)
+		  {
+		    /* Everything must go for SEC.  */
+		    *pp = p->next;
+		    break;
+		  }
 	    }
 	  break;
 
Index: ld/testsuite/ld-arm/gc-thumb-lib.s
===================================================================
--- /dev/null	2010-12-14 12:47:12.274544604 +0000
+++ ld/testsuite/ld-arm/gc-thumb-lib.s	2010-12-14 15:34:35.000000000 +0000
@@ -0,0 +1,6 @@
+	.data
+	.globl	foo
+	.type	foo,%object
+	.size	foo,4
+foo:
+	.word	0
Index: ld/testsuite/ld-arm/gc-thumb.s
===================================================================
--- /dev/null	2010-12-14 12:47:12.274544604 +0000
+++ ld/testsuite/ld-arm/gc-thumb.s	2010-12-14 15:41:29.000000000 +0000
@@ -0,0 +1,11 @@
+	.arch	armv7-a
+	.syntax	unified
+	.text
+	.globl	_start
+_start:
+	mov	pc,lr
+
+	.section .text.foo,"ax",%progbits
+	.thumb
+	movw	r0,#:lower16:foo-.
+	movt	r0,#:upper16:foo-.
Index: ld/testsuite/ld-arm/gc-thumb.d
===================================================================
--- /dev/null	2010-12-14 12:47:12.274544604 +0000
+++ ld/testsuite/ld-arm/gc-thumb.d	2010-12-14 15:34:35.000000000 +0000
@@ -0,0 +1,2 @@
+
+There are no relocations in this file\.
Index: ld/testsuite/ld-arm/arm-elf.exp
===================================================================
--- ld/testsuite/ld-arm/arm-elf.exp	2010-12-14 15:30:05.000000000 +0000
+++ ld/testsuite/ld-arm/arm-elf.exp	2010-12-14 15:34:35.000000000 +0000
@@ -228,6 +228,12 @@ set armelftests {
     {"Unwinding and -gc-sections" "-gc-sections" "" {gc-unwind.s}
      {{objdump -sj.data gc-unwind.d}}
      "gc-unwind"}
+    {"Thumb and -gc-sections" "-shared -T arm-dyn.ld" "" {gc-thumb-lib.s}
+     {}
+     "gc-thumb-lib.so"}
+    {"Thumb and -gc-sections" "-pie -T arm.ld -gc-sections tmpdir/gc-thumb-lib.so" "" {gc-thumb.s}
+     {{readelf --relocs gc-thumb.d}}
+     "gc-thumb"}
     {"arm-pic-veneer" "-static -T arm.ld --pic-veneer" "" {arm-pic-veneer.s}
      {{objdump -d arm-pic-veneer.d}}
      "arm-pic-veneer"}


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