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]

[PATCH][ARM] weak undef references with PLT in ARM mode


Hello,

Following a discussion on another topic, I have identified a bug when there is an undefweak reference from ARM code: it is turned into a jump to the next instruction, even when a PLT entry will be created (see http://sourceware.org/ml/binutils/2009-04/msg00073.html).

Here is a patch to fix this.

Christophe.
2009-04-03  Christophe Lyon  <christophe.lyon@st.com>

	bfd/
	* elf32-arm.c (elf32_arm_final_link_relocate): Don't convert ARM
	branch to an undef weak symbol into a jump to next instruction if
	a PLT entry will be created.

	testsuite/
	* ld-arm/arm-elf.exp: Add 1 more test to check undef weak
	reference with PLT in ARM mode.
	* ld-arm/thumb2-bl-undefweak1.d, ld-arm/thumb2-bl-undefweak1.s:
	New files.
Index: bfd/elf32-arm.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-arm.c,v
retrieving revision 1.185
diff -u -p -r1.185 elf32-arm.c
--- bfd/elf32-arm.c	2 Apr 2009 14:12:45 -0000	1.185
+++ bfd/elf32-arm.c	3 Apr 2009 12:30:43 -0000
@@ -6363,8 +6363,9 @@ elf32_arm_final_link_relocate (reloc_how
 	  signed_addend >>= howto->rightshift;
 
 	  /* A branch to an undefined weak symbol is turned into a jump to
-	     the next instruction.  */
-	  if (h && h->root.type == bfd_link_hash_undefweak)
+	     the next instruction unless a PLT entry will be created.  */
+	  if (h && h->root.type == bfd_link_hash_undefweak
+	      && !(splt != NULL && h->plt.offset != (bfd_vma) -1))
 	    {
 	      value = (bfd_get_32 (input_bfd, hit_data) & 0xf0000000)
 		      | 0x0affffff;
Index: ld/testsuite/ld-arm/arm-elf.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-arm/arm-elf.exp,v
retrieving revision 1.52
diff -u -p -r1.52 arm-elf.exp
--- ld/testsuite/ld-arm/arm-elf.exp	1 Apr 2009 15:45:13 -0000	1.52
+++ ld/testsuite/ld-arm/arm-elf.exp	3 Apr 2009 12:30:53 -0000
@@ -185,6 +185,7 @@ run_dump_test "group-relocs-ldr-bad"
 run_dump_test "group-relocs-ldrs-bad"
 run_dump_test "group-relocs-ldc-bad"
 run_dump_test "thumb2-bl-undefweak"
+run_dump_test "thumb2-bl-undefweak1"
 run_dump_test "emit-relocs1"
 
 # Exclude non-ARM-EABI targets.
Index: ld/testsuite/ld-arm/thumb2-bl-undefweak1.d
===================================================================
RCS file: ld/testsuite/ld-arm/thumb2-bl-undefweak1.d
diff -N ld/testsuite/ld-arm/thumb2-bl-undefweak1.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-arm/thumb2-bl-undefweak1.d	3 Apr 2009 12:30:53 -0000
@@ -0,0 +1,9 @@
+#source: thumb2-bl-undefweak1.s
+#as:
+#ld: -shared
+#objdump: -dr
+#...
+Disassembly of section .text:
+
+.* <foo>:
+ .*:	........ 	bl	... <foo-0x.*>
Index: ld/testsuite/ld-arm/thumb2-bl-undefweak1.s
===================================================================
RCS file: ld/testsuite/ld-arm/thumb2-bl-undefweak1.s
diff -N ld/testsuite/ld-arm/thumb2-bl-undefweak1.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-arm/thumb2-bl-undefweak1.s	3 Apr 2009 12:30:53 -0000
@@ -0,0 +1,9 @@
+@ Test that calls to undefined weak functions resolve to call through
+@ the PLT in shared libraries in ARM mode.
+
+	.arch armv6
+	.syntax unified
+	.text
+foo:
+	bl bar
+	.weak bar

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