Blame SOURCES/binutils-2.30-allow_R_AARCH64-symbols.patch

13ae24
From 279b2f94168ee91e02ccd070d27c983fc001fe12 Mon Sep 17 00:00:00 2001
13ae24
From: Renlin Li <renlin.li@arm.com>
13ae24
Date: Sat, 3 Feb 2018 13:18:17 +0000
13ae24
Subject: [PATCH] [PR22764][LD][AARCH64]Allow R_AARCH64_ABS16 and
13ae24
 R_AARCH64_ABS32 against absolution symbol or undefine symbol in shared
13ae24
 object.
13ae24
13ae24
The assumption that R_AARCH64_ABS16 and R_AARCH64_ABS32 relocation in LP64 abi
13ae24
will be used to generate an address does not hold for absolute symbol.
13ae24
In this case, it is a value fixed at static linking time.
13ae24
13ae24
The condition to check the relocations is relax to allow absolute symbol and
13ae24
undefined symbol case.
13ae24
13ae24
bfd/
13ae24
13ae24
2018-02-05  Renlin Li  <renlin.li@arm.com>
13ae24
13ae24
	PR ld/22764
13ae24
	* elfnn-aarch64.c (elfNN_aarch64_check_relocs): Relax the
13ae24
	R_AARCH64_ABS32 and R_AARCH64_ABS16 for absolute symbol. Apply the
13ae24
	check for writeable section as well.
13ae24
13ae24
ld/
13ae24
13ae24
2018-02-05  Renlin Li  <renlin.li@arm.com>
13ae24
13ae24
	PR ld/22764
13ae24
	* testsuite/ld-aarch64/emit-relocs-258.s: Define symbol as an address.
13ae24
	* testsuite/ld-aarch64/emit-relocs-259.s: Likewise.
13ae24
	* testsuite/ld-aarch64/aarch64-elf.exp: Run new test.
13ae24
	* testsuite/ld-aarch64/pr22764.s: New.
13ae24
	* testsuite/ld-aarch64/pr22764.d: New.
13ae24
---
13ae24
 bfd/ChangeLog                             |  7 +++++++
13ae24
 bfd/elfnn-aarch64.c                       | 15 ++++++++++++---
13ae24
 ld/ChangeLog                              |  8 ++++++++
13ae24
 ld/testsuite/ld-aarch64/aarch64-elf.exp   |  1 +
13ae24
 ld/testsuite/ld-aarch64/emit-relocs-258.s |  3 ++-
13ae24
 ld/testsuite/ld-aarch64/emit-relocs-259.s |  3 ++-
13ae24
 ld/testsuite/ld-aarch64/pr22764.d         | 18 ++++++++++++++++++
13ae24
 ld/testsuite/ld-aarch64/pr22764.s         |  6 ++++++
13ae24
 8 files changed, 56 insertions(+), 5 deletions(-)
13ae24
 create mode 100644 ld/testsuite/ld-aarch64/pr22764.d
13ae24
 create mode 100644 ld/testsuite/ld-aarch64/pr22764.s
13ae24
13ae24
diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
13ae24
index af448f9..2737773 100644
13ae24
--- a/bfd/elfnn-aarch64.c
13ae24
+++ b/bfd/elfnn-aarch64.c
13ae24
@@ -7189,10 +7189,19 @@ elfNN_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info,
13ae24
 #if ARCH_SIZE == 64
13ae24
 	case BFD_RELOC_AARCH64_32:
13ae24
 #endif
13ae24
-	  if (bfd_link_pic (info)
13ae24
-	      && (sec->flags & SEC_ALLOC) != 0
13ae24
-	      && (sec->flags & SEC_READONLY) != 0)
13ae24
+	  if (bfd_link_pic (info) && (sec->flags & SEC_ALLOC) != 0)
13ae24
 	    {
13ae24
+	      if (h != NULL
13ae24
+		  /* This is an absolute symbol.  It represents a value instead
13ae24
+		     of an address.  */
13ae24
+		  && ((h->root.type == bfd_link_hash_defined
13ae24
+		       && bfd_is_abs_section (h->root.u.def.section))
13ae24
+		      /* This is an undefined symbol.  */
13ae24
+		      || h->root.type == bfd_link_hash_undefined))
13ae24
+		break;
13ae24
+
13ae24
+	      /* For local symbols, defined global symbols in a non-ABS section,
13ae24
+		 it is assumed that the value is an address.  */
13ae24
 	      int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
13ae24
 	      _bfd_error_handler
13ae24
 		/* xgettext:c-format */
13ae24
diff --git a/ld/testsuite/ld-aarch64/aarch64-elf.exp b/ld/testsuite/ld-aarch64/aarch64-elf.exp
13ae24
index 2602a43..c67ffb1 100644
13ae24
--- a/ld/testsuite/ld-aarch64/aarch64-elf.exp
13ae24
+++ b/ld/testsuite/ld-aarch64/aarch64-elf.exp
13ae24
@@ -285,6 +285,7 @@ run_dump_test "pr17415"
13ae24
 run_dump_test_lp64 "tprel_g2_overflow"
13ae24
 run_dump_test "tprel_add_lo12_overflow"
13ae24
 run_dump_test "protected-data"
13ae24
+run_dump_test_lp64 "pr22764"
13ae24
 
13ae24
 # ifunc tests
13ae24
 run_dump_test "ifunc-1"
13ae24
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-258.s b/ld/testsuite/ld-aarch64/emit-relocs-258.s
13ae24
index f724776..87bb657 100644
13ae24
--- a/ld/testsuite/ld-aarch64/emit-relocs-258.s
13ae24
+++ b/ld/testsuite/ld-aarch64/emit-relocs-258.s
13ae24
@@ -1,5 +1,6 @@
13ae24
+.global dummy
13ae24
 .text
13ae24
-
13ae24
+dummy:
13ae24
   ldr x0, .L1
13ae24
 
13ae24
 .L1:
13ae24
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-259.s b/ld/testsuite/ld-aarch64/emit-relocs-259.s
13ae24
index 7e1ba3c..0977c9d 100644
13ae24
--- a/ld/testsuite/ld-aarch64/emit-relocs-259.s
13ae24
+++ b/ld/testsuite/ld-aarch64/emit-relocs-259.s
13ae24
@@ -1,5 +1,6 @@
13ae24
+.global dummy
13ae24
 .text
13ae24
-
13ae24
+dummy:
13ae24
   ldr x0, .L1
13ae24
 
13ae24
 .L1:
13ae24
diff --git a/ld/testsuite/ld-aarch64/pr22764.d b/ld/testsuite/ld-aarch64/pr22764.d
13ae24
new file mode 100644
13ae24
index 0000000..997519f
13ae24
--- /dev/null
13ae24
+++ b/ld/testsuite/ld-aarch64/pr22764.d
13ae24
@@ -0,0 +1,18 @@
13ae24
+#source: pr22764.s
13ae24
+#ld: -shared -T relocs.ld -defsym sym_abs1=0x1 -defsym sym_abs2=0x2 -defsym sym_abs3=0x3 -e0 --emit-relocs
13ae24
+#notarget: aarch64_be-*-*
13ae24
+#objdump: -dr
13ae24
+#...
13ae24
+
13ae24
+Disassembly of section \.text:
13ae24
+
13ae24
+0000000000010000 \<\.text\>:
13ae24
+   10000:	d503201f 	nop
13ae24
+	...
13ae24
+			10004: R_AARCH64_ABS64	sym_abs1
13ae24
+   1000c:	00000002 	\.word	0x00000002
13ae24
+			1000c: R_AARCH64_ABS32	sym_abs2
13ae24
+   10010:	0003      	\.short	0x0003
13ae24
+			10010: R_AARCH64_ABS16	sym_abs3
13ae24
+   10012:	0000      	\.short	0x0000
13ae24
+   10014:	d503201f 	nop
13ae24
diff --git a/ld/testsuite/ld-aarch64/pr22764.s b/ld/testsuite/ld-aarch64/pr22764.s
13ae24
new file mode 100644
13ae24
index 0000000..25e36b4
13ae24
--- /dev/null
13ae24
+++ b/ld/testsuite/ld-aarch64/pr22764.s
13ae24
@@ -0,0 +1,6 @@
13ae24
+  .text
13ae24
+  nop
13ae24
+  .xword sym_abs1
13ae24
+  .word sym_abs2
13ae24
+  .short sym_abs3
13ae24
+  nop
13ae24
-- 
13ae24
2.9.3