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

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