summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiong Wang <jiong.wang@arm.com>2016-05-03 11:59:37 +0100
committerJiong Wang <jiong.wang@arm.com>2016-05-03 11:59:37 +0100
commit1f56df9d0d5ad89806c24e71f296576d82344613 (patch)
tree5119f229d105a5dbb5a18c77cef5407d318a7fde
parent20f55f3866ab70778d08fec2c09626cff9ed781d (diff)
downloadbinutils-gdb-1f56df9d0d5ad89806c24e71f296576d82344613.tar.gz
[AArch64] Also puts value in place for R_AARCH64_RELATIVE
When handling absolute relocations for global symbols bind within the shared object, AArch64 will generate one dynamic RELATIVE relocation, but won't apply the value for this absolution relocations at static linking stage. This is different from AArch64 gold linker and x86-64. This is not a bug as AArch64 is RELA, there is only guarantee that relocation addend is placed in the relocation entry. But some system softwares originally writen for x86-64 might assume AArch64 bfd linker gets the same behavior as x86-64, then they could take advantage of this buy skipping those RELATIVE dynamic relocations if the load address is the same as the static linking address. This patch makes AArch64 BFD linker applies absolution relocations at static linking stage for scenario described above. Meanwhile old AArch64 android loader has a bug (PR19163) which relies on current linker behavior as a workaround, so the same option --no-apply-dynamic-relocs added.
-rw-r--r--bfd/ChangeLog9
-rw-r--r--bfd/bfd-in.h4
-rw-r--r--bfd/bfd-in2.h4
-rw-r--r--bfd/elfnn-aarch64.c8
-rw-r--r--ld/ChangeLog12
-rw-r--r--ld/NEWS3
-rw-r--r--ld/emultempl/aarch64elf.em11
-rw-r--r--ld/ld.texinfo5
-rw-r--r--ld/testsuite/ld-aarch64/aarch64-elf.exp4
-rw-r--r--ld/testsuite/ld-aarch64/rela-abs-relative-be.d13
-rw-r--r--ld/testsuite/ld-aarch64/rela-abs-relative-opt.d13
-rw-r--r--ld/testsuite/ld-aarch64/rela-abs-relative.d13
-rw-r--r--ld/testsuite/ld-aarch64/rela-abs-relative.s16
13 files changed, 109 insertions, 6 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 394e83c9617..432ec915023 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,12 @@
+2016-05-03 Jiong Wang <jiong.wang@arm.com>
+
+ * bfd-in.h (bfd_elf64_aarch64_set_options): Update prototype.
+ * bfd-in2.h (bfd_elf64_aarch64_set_options): Likewise.
+ * elfnn-aarch64.c (bfd_elfNN_aarch64_set_options): Initialize
+ no_apply_dynamic_relocs.
+ (elfNN_aarch64_final_link_relocate): Apply absolute relocations even though
+ dynamic relocations generated.
+
2016-04-29 H.J. Lu <hongjiu.lu@intel.com>
* elf32-i386.c (elf_i386_size_dynamic_sections): Move interp
diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h
index 5df2babf88b..46414056d60 100644
--- a/bfd/bfd-in.h
+++ b/bfd/bfd-in.h
@@ -961,10 +961,10 @@ extern void bfd_elf32_aarch64_init_maps
(bfd *);
extern void bfd_elf64_aarch64_set_options
- (bfd *, struct bfd_link_info *, int, int, int, int, int);
+ (bfd *, struct bfd_link_info *, int, int, int, int, int, int);
extern void bfd_elf32_aarch64_set_options
- (bfd *, struct bfd_link_info *, int, int, int, int, int);
+ (bfd *, struct bfd_link_info *, int, int, int, int, int, int);
/* ELF AArch64 mapping symbol support. */
#define BFD_AARCH64_SPECIAL_SYM_TYPE_MAP (1 << 0)
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index a19a6513992..f68c10766ae 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -968,10 +968,10 @@ extern void bfd_elf32_aarch64_init_maps
(bfd *);
extern void bfd_elf64_aarch64_set_options
- (bfd *, struct bfd_link_info *, int, int, int, int, int);
+ (bfd *, struct bfd_link_info *, int, int, int, int, int, int);
extern void bfd_elf32_aarch64_set_options
- (bfd *, struct bfd_link_info *, int, int, int, int, int);
+ (bfd *, struct bfd_link_info *, int, int, int, int, int, int);
/* ELF AArch64 mapping symbol support. */
#define BFD_AARCH64_SPECIAL_SYM_TYPE_MAP (1 << 0)
diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
index 5b9878e8f31..eecbf87dc26 100644
--- a/bfd/elfnn-aarch64.c
+++ b/bfd/elfnn-aarch64.c
@@ -2289,6 +2289,9 @@ struct elf_aarch64_link_hash_table
/* Enable ADRP->ADR rewrite for erratum 843419 workaround. */
int fix_erratum_843419_adr;
+ /* Don't apply link-time values for dynamic relocations. */
+ int no_apply_dynamic_relocs;
+
/* The number of bytes in the initial entry in the PLT. */
bfd_size_type plt_header_size;
@@ -4334,7 +4337,8 @@ bfd_elfNN_aarch64_set_options (struct bfd *output_bfd,
int no_enum_warn,
int no_wchar_warn, int pic_veneer,
int fix_erratum_835769,
- int fix_erratum_843419)
+ int fix_erratum_843419,
+ int no_apply_dynamic_relocs)
{
struct elf_aarch64_link_hash_table *globals;
@@ -4343,6 +4347,7 @@ bfd_elfNN_aarch64_set_options (struct bfd *output_bfd,
globals->fix_erratum_835769 = fix_erratum_835769;
globals->fix_erratum_843419 = fix_erratum_843419;
globals->fix_erratum_843419_adr = TRUE;
+ globals->no_apply_dynamic_relocs = no_apply_dynamic_relocs;
BFD_ASSERT (is_aarch64_elf (output_bfd));
elf_aarch64_tdata (output_bfd)->no_enum_size_warning = no_enum_warn;
@@ -5208,6 +5213,7 @@ elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
relocate the text and data segments independently,
so the symbol does not matter. */
symbol = 0;
+ relocate = globals->no_apply_dynamic_relocs ? FALSE : TRUE;
outrel.r_info = ELFNN_R_INFO (symbol, AARCH64_R (RELATIVE));
outrel.r_addend += value;
}
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 92596b7fe61..7d8d8ee995d 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,15 @@
+2016-05-03 Jiong Wang <jiong.wang@arm.com>
+
+ * emultempl/aarch64elf.em (--no-apply-dynamic-relocs): New option.
+ * NEWS: Mention --no-apply-dynamic-relocs.
+ * ld.texinfo (ld and the ARM family): Document
+ --no-apply-dynamic-relocs.
+ * testsuite/ld-aarch64/rela-abs-relative.s: New test source.
+ * testsuite/ld-aarch64/rela-abs-relative.d: New expected result.
+ * testsuite/ld-aarch64/rela-abs-relative-be.d: Likewise for big-endian.
+ * estsuite/ld-aarch64/rela-abs-relative-opt.d: Likewise, but enable new
+ option.
+
2016-05-03 Senthil Kumar Selvaraj <senthil_kumar.selvaraj@atmel.com>
* testsuite/ld-elfcomm/elfcomm.exp: Check for shared lib support
diff --git a/ld/NEWS b/ld/NEWS
index b4abd0b5b8d..228fddf7103 100644
--- a/ld/NEWS
+++ b/ld/NEWS
@@ -11,6 +11,9 @@
* The NOCROSSREFSTO command was added to the linker script language.
+* Add --no-apply-dynamic-relocs to the AArch64 linker to do not apply link-time
+ values for dynamic relocations.
+
Changes in 2.26:
* Add --fix-stm32l4xx-629360 to the ARM linker to enable a link-time
diff --git a/ld/emultempl/aarch64elf.em b/ld/emultempl/aarch64elf.em
index 9923be3a6b6..a17553a6a59 100644
--- a/ld/emultempl/aarch64elf.em
+++ b/ld/emultempl/aarch64elf.em
@@ -32,6 +32,7 @@ static int no_wchar_size_warning = 0;
static int pic_veneer = 0;
static int fix_erratum_835769 = 0;
static int fix_erratum_843419 = 0;
+static int no_apply_dynamic_relocs = 0;
static void
gld${EMULATION_NAME}_before_parse (void)
@@ -305,7 +306,8 @@ aarch64_elf_create_output_section_statements (void)
no_enum_size_warning,
no_wchar_size_warning,
pic_veneer,
- fix_erratum_835769, fix_erratum_843419);
+ fix_erratum_835769, fix_erratum_843419,
+ no_apply_dynamic_relocs);
stub_file = lang_add_input_file ("linker stubs",
lang_input_file_is_fake_enum,
@@ -356,6 +358,7 @@ PARSE_AND_LIST_PROLOGUE='
#define OPTION_NO_WCHAR_SIZE_WARNING 312
#define OPTION_FIX_ERRATUM_835769 313
#define OPTION_FIX_ERRATUM_843419 314
+#define OPTION_NO_APPLY_DYNAMIC_RELOCS 315
'
PARSE_AND_LIST_SHORTOPTS=p
@@ -368,6 +371,7 @@ PARSE_AND_LIST_LONGOPTS='
{ "no-wchar-size-warning", no_argument, NULL, OPTION_NO_WCHAR_SIZE_WARNING},
{ "fix-cortex-a53-835769", no_argument, NULL, OPTION_FIX_ERRATUM_835769},
{ "fix-cortex-a53-843419", no_argument, NULL, OPTION_FIX_ERRATUM_843419},
+ { "no-apply-dynamic-relocs", no_argument, NULL, OPTION_NO_APPLY_DYNAMIC_RELOCS},
'
PARSE_AND_LIST_OPTIONS='
@@ -387,6 +391,7 @@ PARSE_AND_LIST_OPTIONS='
));
fprintf (file, _(" --fix-cortex-a53-835769 Fix erratum 835769\n"));
fprintf (file, _(" --fix-cortex-a53-843419 Fix erratum 843419\n"));
+ fprintf (file, _(" --no-apply-dynamic-relocs Do not apply link-time values for dynamic relocations\n"));
'
PARSE_AND_LIST_ARGS_CASES='
@@ -414,6 +419,10 @@ PARSE_AND_LIST_ARGS_CASES='
fix_erratum_843419 = 1;
break;
+ case OPTION_NO_APPLY_DYNAMIC_RELOCS:
+ no_apply_dynamic_relocs = 1;
+ break;
+
case OPTION_STUBGROUP_SIZE:
{
const char *end;
diff --git a/ld/ld.texinfo b/ld/ld.texinfo
index 7a2ed3abed3..bc16764b055 100644
--- a/ld/ld.texinfo
+++ b/ld/ld.texinfo
@@ -6848,6 +6848,11 @@ The @samp{--long-plt} option enables the use of 16 byte PLT entries
which support up to 4Gb of code. The default is to use 12 byte PLT
entries which only support 512Mb of code.
+@kindex --no-apply-dynamic-relocs
+@cindex AArch64 rela addend
+The @samp{--no-apply-dynamic-relocs} option makes AArch64 linker do not apply
+link-time values for dynamic relocations.
+
@ifclear GENERIC
@lowersections
@end ifclear
diff --git a/ld/testsuite/ld-aarch64/aarch64-elf.exp b/ld/testsuite/ld-aarch64/aarch64-elf.exp
index b9c41330758..b27da52acd8 100644
--- a/ld/testsuite/ld-aarch64/aarch64-elf.exp
+++ b/ld/testsuite/ld-aarch64/aarch64-elf.exp
@@ -285,6 +285,10 @@ run_dump_test "dt_textrel"
run_dump_test "plt_mapping_symbol"
+run_dump_test "rela-abs-relative"
+run_dump_test "rela-abs-relative-be"
+run_dump_test "rela-abs-relative-opt"
+
set aarch64elflinktests {
{"ld-aarch64/so with global symbol" "-shared" "" "" {copy-reloc-so.s}
{} "copy-reloc-so.so"}
diff --git a/ld/testsuite/ld-aarch64/rela-abs-relative-be.d b/ld/testsuite/ld-aarch64/rela-abs-relative-be.d
new file mode 100644
index 00000000000..88ba58df171
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/rela-abs-relative-be.d
@@ -0,0 +1,13 @@
+#name: rela-abs-relative (big endian)
+#source: rela-abs-relative.s
+#ld: -shared -Ttext-segment=0x100000 -Tdata=0x200000 -Trelocs.ld
+#target: aarch64_be-*-*
+#objdump: -dR -j .data
+#...
+
+Disassembly of section .data:
+
+.* <a>:
+ 200000: 00 00 00 00 ca fe ca fe 00 00 00 00 00 01 00 ca.*
+ 200008: R_AARCH64_RELATIVE \*ABS\*\+0x100ca
+ 200010: 00 00 00 00 de ad de ad.*
diff --git a/ld/testsuite/ld-aarch64/rela-abs-relative-opt.d b/ld/testsuite/ld-aarch64/rela-abs-relative-opt.d
new file mode 100644
index 00000000000..a1e5ca0fc18
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/rela-abs-relative-opt.d
@@ -0,0 +1,13 @@
+#name: rela-abs-relative --no-apply-dynamic-relocs
+#source: rela-abs-relative.s
+#ld: -shared -Ttext-segment=0x100000 -Tdata=0x200000 -Trelocs.ld --no-apply-dynamic-relocs
+#notarget: aarch64_be-*-*
+#objdump: -dR -j .data
+#...
+
+Disassembly of section .data:
+
+.* <a>:
+ 200000: fe ca fe ca 00 00 00 00 00 00 00 00 00 00 00 00.*
+ 200008: R_AARCH64_RELATIVE \*ABS\*\+0x100ca
+ 200010: ad de ad de 00 00 00 00.*
diff --git a/ld/testsuite/ld-aarch64/rela-abs-relative.d b/ld/testsuite/ld-aarch64/rela-abs-relative.d
new file mode 100644
index 00000000000..aba876b7b49
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/rela-abs-relative.d
@@ -0,0 +1,13 @@
+#name: rela-abs-relative
+#source: rela-abs-relative.s
+#ld: -shared -Ttext-segment=0x100000 -Tdata=0x200000 -Trelocs.ld
+#notarget: aarch64_be-*-*
+#objdump: -dR -j .data
+#...
+
+Disassembly of section .data:
+
+.* <a>:
+ 200000: fe ca fe ca 00 00 00 00 ca 00 01 00 00 00 00 00.*
+ 200008: R_AARCH64_RELATIVE \*ABS\*\+0x100ca
+ 200010: ad de ad de 00 00 00 00.*
diff --git a/ld/testsuite/ld-aarch64/rela-abs-relative.s b/ld/testsuite/ld-aarch64/rela-abs-relative.s
new file mode 100644
index 00000000000..d4c466352ff
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/rela-abs-relative.s
@@ -0,0 +1,16 @@
+ .section .rodata
+ .align 3
+ .type string1, %object
+ .size string1, 8
+local_foo:
+ .string "local_foo"
+
+ .section .data,"aw",%progbits
+ .align 3
+ .global a
+ .type a, %object
+ .size a, 24
+a:
+ .xword 0xcafecafe
+ .xword local_foo + 0xca
+ .xword 0xdeaddead