[PATCH, ARM]: Fix SB group relocations

John Tytgat john@bass-software.com
Fri Aug 2 21:26:00 GMT 2013


In message <4617da7153.Jo@hobbes.bass-software.com>
          John Tytgat <john@bass-software.com> wrote:

> I recreated the patch and also corrected a problem which I found out in
> the meanwhile : when using an unresolved symbol for the SB group relocation
> there was an ICE as the section containing that symbol is NULL.  Hence
> the added test on sym_sec in elf32_arm_final_link_relocation.
> I also added a specific unresolved failure test for this.

In the meanwhile Nick already applied my first patch which was not taking
Richard's comments into account.  Basically this following up patch
addresses this by swapping the ld-arm/group-relocs-ldr(s)-bad(-2) tests
and also fixes the above mentioned problem with unresolved symbols
in a sb group relocation.

bfd

John Tytgat  <john@bass-software.com>

	* elf32-arm.c (elf32_arm_final_link_relocate): Handle
	unresolved symbol case for sb group relocations.

ld/testsuite

John Tytgat  <john@bass-software.com>

	* ld-arm/unresolved-2.d: New.
	* ld-arm/unresolved-2.s: New.
	* ld-arm/arm-elf.exp: Add the new test.
	* ld-arm/group-relocs-ldr-bad-2.d: Swap with...
	* ld-arm/group-relocs-ldr-bad.d: ...this.
	* ld-arm/group-relocs-ldr-bad-2.s: Swap with...
	* ld-arm/group-relocs-ldr-bad.s: ...this.
	* ld-arm/group-relocs-ldrs-bad-2.d: Swap with...
	* ld-arm/group-relocs-ldrs-bad.d: ...this.
	* ld-arm/group-relocs-ldrs-bad-2.s: Swap with...
	* ld-arm/group-relocs-ldrs-bad.s: ...this.

Thanks,
John.
-- 
John Tytgat                                                             BASS
John@bass-software.com
-------------- next part --------------
diff -r -u -N bfd/elf32-arm.c ../new/bfd/elf32-arm.c
--- bfd/elf32-arm.c	2013-07-31 18:26:02.000000000 +0200
+++ ../new/bfd/elf32-arm.c	2013-07-28 19:04:38.090458222 +0200
@@ -9853,7 +9851,7 @@
 	bfd_vma pc = input_section->output_section->vma
 		     + input_section->output_offset + rel->r_offset;
 	/* sb is the origin of the *segment* containing the symbol.  */
-	bfd_vma sb = sym_sec->output_section->vma;
+	bfd_vma sb = sym_sec ? sym_sec->output_section->vma : 0;
 	bfd_vma residual;
 	bfd_vma g_n;
 	bfd_signed_vma signed_value;
@@ -9987,7 +9985,7 @@
 	bfd_vma pc = input_section->output_section->vma
 		     + input_section->output_offset + rel->r_offset;
 	/* sb is the origin of the *segment* containing the symbol.  */
-	bfd_vma sb = sym_sec->output_section->vma;
+	bfd_vma sb = sym_sec ? sym_sec->output_section->vma : 0;
 	bfd_vma residual;
 	bfd_signed_vma signed_value;
 	int group = 0;
@@ -10071,7 +10069,7 @@
 	bfd_vma pc = input_section->output_section->vma
 		     + input_section->output_offset + rel->r_offset;
 	/* sb is the origin of the *segment* containing the symbol.  */
-	bfd_vma sb = sym_sec->output_section->vma;
+	bfd_vma sb = sym_sec ? sym_sec->output_section->vma : 0;
 	bfd_vma residual;
 	bfd_signed_vma signed_value;
 	int group = 0;
@@ -10155,7 +10153,7 @@
 	bfd_vma pc = input_section->output_section->vma
 		     + input_section->output_offset + rel->r_offset;
 	/* sb is the origin of the *segment* containing the symbol.  */
-	bfd_vma sb = sym_sec->output_section->vma;
+	bfd_vma sb = sym_sec ? sym_sec->output_section->vma : 0;
 	bfd_vma residual;
 	bfd_signed_vma signed_value;
 	int group = 0;
diff -r -u -N ld/testsuite/ld-arm/arm-elf.exp ../new/ld/testsuite/ld-arm/arm-elf.exp
--- ld/testsuite/ld-arm/arm-elf.exp	2013-07-31 18:26:02.000000000 +0200
+++ ../new/ld/testsuite/ld-arm/arm-elf.exp	2013-07-27 15:45:44.529471638 +0200
@@ -836,4 +836,5 @@
 if { ![istarget "arm*-*-nacl*"] } {
     run_dump_test "unresolved-1-dyn"
 }
+run_dump_test "unresolved-2"
 run_dump_test "gc-hidden-1"
diff -r -u -N ld/testsuite/ld-arm/unresolved-2.d ../new/ld/testsuite/ld-arm/unresolved-2.d
--- ld/testsuite/ld-arm/unresolved-2.d	1970-01-01 01:00:00.000000000 +0100
+++ ../new/ld/testsuite/ld-arm/unresolved-2.d	2013-07-27 16:00:37.202249222 +0200
@@ -0,0 +1,5 @@
+#name: SB relocations failure test
+#source: unresolved-2.s
+#ld: 
+#error: \(\.text\+0x0\): undefined reference to `foo'
+
diff -r -u -N ld/testsuite/ld-arm/unresolved-2.s ../new/ld/testsuite/ld-arm/unresolved-2.s
--- ld/testsuite/ld-arm/unresolved-2.s	1970-01-01 01:00:00.000000000 +0100
+++ ../new/ld/testsuite/ld-arm/unresolved-2.s	2013-07-27 15:51:39.893004114 +0200
@@ -0,0 +1,5 @@
+	.text
+	.globl	_start
+_start:
+	ldr	r1, [r0, #:sb_g0:(foo)]
+
diff -r -u -N ld/testsuite/ld-arm/group-relocs-ldr-bad-2.d ../new/ld/testsuite/ld-arm/group-relocs-ldr-bad-2.d
--- ld/testsuite/ld-arm/group-relocs-ldr-bad-2.d	2013-07-31 18:26:02.000000000 +0200
+++ ../new/ld/testsuite/ld-arm/group-relocs-ldr-bad-2.d	2013-07-27 15:02:12.054314899 +0200
@@ -1,4 +1,4 @@
 #name: LDR group relocations failure test
 #source: group-relocs-ldr-bad-2.s
 #ld: -Ttext 0x8000 --section-start foo=0x8001000
-#error: .*Overflow whilst splitting 0x123456 for group relocation.*
+#error: .*Overflow whilst splitting 0x7ff9000 for group relocation.*
diff -r -u -N ld/testsuite/ld-arm/group-relocs-ldr-bad.d ../new/ld/testsuite/ld-arm/group-relocs-ldr-bad.d
--- ld/testsuite/ld-arm/group-relocs-ldr-bad.d	2013-07-31 18:26:02.000000000 +0200
+++ ../new/ld/testsuite/ld-arm/group-relocs-ldr-bad.d	2013-07-27 15:01:55.554522329 +0200
@@ -1,4 +1,4 @@
 #name: LDR group relocations failure test
 #source: group-relocs-ldr-bad.s
 #ld: -Ttext 0x8000 --section-start foo=0x8001000
-#error: .*Overflow whilst splitting 0x7ff9000 for group relocation.*
+#error: .*Overflow whilst splitting 0x123456 for group relocation.*
diff -r -u -N ld/testsuite/ld-arm/group-relocs-ldr-bad-2.s ../new/ld/testsuite/ld-arm/group-relocs-ldr-bad-2.s
--- ld/testsuite/ld-arm/group-relocs-ldr-bad-2.s	2013-07-31 18:26:02.000000000 +0200
+++ ../new/ld/testsuite/ld-arm/group-relocs-ldr-bad-2.s	2013-07-25 00:34:17.063115657 +0200
@@ -6,12 +6,13 @@
 	.globl _start
 
 _start:
-	add	r0, r0, #:sb_g0_nc:(bar)
-	ldr	r1, [r0, #:sb_g1:(bar)]
+	add	r0, r0, #:pc_g0_nc:(bar)
+	ldr	r1, [r0, #:pc_g1:(bar + 4)]
 
-@ We will place the section foo at 0x8001000 but that should be irrelevant
-@ for sb_g* relocations.
+@ We will place the section foo at 0x8001000.
 
 	.section foo
-	.set bar,foo + 0x123456
+
+bar:
+	mov r0, #0
 
diff -r -u -N ld/testsuite/ld-arm/group-relocs-ldr-bad.s ../new/ld/testsuite/ld-arm/group-relocs-ldr-bad.s
--- ld/testsuite/ld-arm/group-relocs-ldr-bad.s	2013-07-31 18:26:02.000000000 +0200
+++ ../new/ld/testsuite/ld-arm/group-relocs-ldr-bad.s	2013-07-25 00:34:17.067115606 +0200
@@ -6,13 +6,12 @@
 	.globl _start
 
 _start:
-	add	r0, r0, #:pc_g0_nc:(bar)
-	ldr	r1, [r0, #:pc_g1:(bar + 4)]
+	add	r0, r0, #:sb_g0_nc:(bar)
+	ldr	r1, [r0, #:sb_g1:(bar)]
 
-@ We will place the section foo at 0x8001000.
+@ We will place the section foo at 0x8001000 but that should be irrelevant
+@ for sb_g* relocations.
 
 	.section foo
-
-bar:
-	mov r0, #0
+	.set bar,foo + 0x123456
 
diff -r -u -N ld/testsuite/ld-arm/group-relocs-ldrs-bad-2.d ../new/ld/testsuite/ld-arm/group-relocs-ldrs-bad-2.d
--- ld/testsuite/ld-arm/group-relocs-ldrs-bad-2.d	2013-07-31 18:26:02.000000000 +0200
+++ ../new/ld/testsuite/ld-arm/group-relocs-ldrs-bad-2.d	2013-07-27 15:02:17.946240827 +0200
@@ -1,4 +1,4 @@
 #name: LDRS group relocations failure test
 #source: group-relocs-ldrs-bad-2.s
 #ld: -Ttext 0x8000 --section-start foo=0x8000100
-#error: Overflow whilst splitting 0x123456 for group relocation
+#error: Overflow whilst splitting 0x7ff8100 for group relocation
diff -r -u -N ld/testsuite/ld-arm/group-relocs-ldrs-bad.d ../new/ld/testsuite/ld-arm/group-relocs-ldrs-bad.d
--- ld/testsuite/ld-arm/group-relocs-ldrs-bad.d	2013-07-31 18:26:02.000000000 +0200
+++ ../new/ld/testsuite/ld-arm/group-relocs-ldrs-bad.d	2013-07-27 15:02:01.938442072 +0200
@@ -1,4 +1,4 @@
 #name: LDRS group relocations failure test
 #source: group-relocs-ldrs-bad.s
 #ld: -Ttext 0x8000 --section-start foo=0x8000100
-#error: Overflow whilst splitting 0x7ff8100 for group relocation
+#error: Overflow whilst splitting 0x123456 for group relocation
diff -r -u -N ld/testsuite/ld-arm/group-relocs-ldrs-bad-2.s ../new/ld/testsuite/ld-arm/group-relocs-ldrs-bad-2.s
--- ld/testsuite/ld-arm/group-relocs-ldrs-bad-2.s	2013-07-31 18:26:02.000000000 +0200
+++ ../new/ld/testsuite/ld-arm/group-relocs-ldrs-bad-2.s	2013-07-25 00:34:17.063115657 +0200
@@ -6,12 +6,12 @@
 	.globl _start
 
 _start:
-	add	r0, r0, #:sb_g0_nc:(bar)
-	ldrd	r2, [r0, #:sb_g1:(bar)]
+	add	r0, r0, #:pc_g0_nc:(bar)
+	ldrd	r2, [r0, #:pc_g1:(bar + 4)]
 
-@ We will place the section foo at 0x8000100 but that should be irrelevant
-@ for sb_g* relocations.
+@ We will place the section foo at 0x8000100.
 
 	.section foo
-	.set bar,foo + 0x123456
 
+bar:
+	mov r0, #0
diff -r -u -N ld/testsuite/ld-arm/group-relocs-ldrs-bad.s ../new/ld/testsuite/ld-arm/group-relocs-ldrs-bad.s
--- ld/testsuite/ld-arm/group-relocs-ldrs-bad.s	2013-07-31 18:26:02.000000000 +0200
+++ ../new/ld/testsuite/ld-arm/group-relocs-ldrs-bad.s	2013-07-25 00:34:17.067115606 +0200
@@ -6,12 +6,12 @@
 	.globl _start
 
 _start:
-	add	r0, r0, #:pc_g0_nc:(bar)
-	ldrd	r2, [r0, #:pc_g1:(bar + 4)]
+	add	r0, r0, #:sb_g0_nc:(bar)
+	ldrd	r2, [r0, #:sb_g1:(bar)]
 
-@ We will place the section foo at 0x8000100.
+@ We will place the section foo at 0x8000100 but that should be irrelevant
+@ for sb_g* relocations.
 
 	.section foo
+	.set bar,foo + 0x123456
 
-bar:
-	mov r0, #0



More information about the Binutils mailing list