From 2e0488d33f8abbbc5bec214e1723d07048d7afcc Mon Sep 17 00:00:00 2001 From: Jiong Wang Date: Tue, 8 Jul 2014 09:29:06 +0100 Subject: Enable elf_backend_rela_normal for AArch64 If we are generating non-relocatable object and --emit-relocs specified, aarch64 ld is actually generating wrong addend for rela entry when relocate against local symbol. for example, for simple testcase foo.c === const char * const a = "foo"; const char * foo () { return a; } bar.c === const char * const b = "bar"; const char * bar () { return b; } aarch64-none-linux-gnu-ld --emit-relocs -o x.o foo.o bar.o aarch64-none-linux-gnu-readelf -r x.o ... R_AARCH64_ADR_PRE 0000000000400018 .rodata + 0 ... R_AARCH64_ADD_ABS 0000000000400018 .rodata + 0 ... R_AARCH64_ADR_PRE 0000000000400018 .rodata + 0 ... R_AARCH64_ADD_ABS 0000000000400018 .rodata + 0 while it should be: ... R_AARCH64_ADR_PRE 0000000000400018 .rodata + 0 ... R_AARCH64_ADD_ABS 0000000000400018 .rodata + 0 ... R_AARCH64_ADR_PRE 0000000000400018 .rodata + 10 ... R_AARCH64_ADD_ABS 0000000000400018 .rodata + 10 bfd generic code could actually handle this properly, but only when elf_backend_rela_normal set to '1'. this patch enable this and remove those target specific hack. bfd/ * elfnn-aarch64.c (elf_backend_rela_normal): Set to 1. (elfNN_aarch64_relocate_section): Remove duplicated addend adjustment when info->relocatable be true. ld/testsuite/ * ld-aarch64/emit-relocs-local-addend-bar.s: * New source file. * ld-aarch64/emit-relocs-local-addend-foo.s: * Likewise. * ld-aarch64/emit-relocs-local-addend.d: * New testcase. * ld-aarch64/local-addend-r.d: Likewise. --- bfd/ChangeLog | 6 ++++++ bfd/elfnn-aarch64.c | 11 ++--------- 2 files changed, 8 insertions(+), 9 deletions(-) (limited to 'bfd') diff --git a/bfd/ChangeLog b/bfd/ChangeLog index f6bc88b..deed8ce 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2014-07-08 Jiong Wang + + * elfnn-aarch64.c (elf_backend_rela_normal): Set to 1. + (elfNN_aarch64_relocate_section): Remove duplicated addend adjustment + when info->relocatable be true. + 2014-07-07 Barney Stratford * elf32-avr.c: Handle R_AVR_PORT5 and R_AVR_PORT6. diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c index a8578da..4dfb604 100644 --- a/bfd/elfnn-aarch64.c +++ b/bfd/elfnn-aarch64.c @@ -4158,15 +4158,7 @@ elfNN_aarch64_relocate_section (bfd *output_bfd, rel, 1, relend, howto, 0, contents); if (info->relocatable) - { - /* This is a relocatable link. We don't have to change - anything, unless the reloc is against a section symbol, - in which case we have to adjust according to where the - section symbol winds up in the output section. */ - if (sym != NULL && ELF_ST_TYPE (sym->st_info) == STT_SECTION) - rel->r_addend += sec->output_offset; - continue; - } + continue; if (h != NULL) name = h->root.root.string; @@ -7288,6 +7280,7 @@ const struct elf_size_info elfNN_aarch64_size_info = #define elf_backend_may_use_rel_p 0 #define elf_backend_may_use_rela_p 1 #define elf_backend_default_use_rela_p 1 +#define elf_backend_rela_normal 1 #define elf_backend_got_header_size (GOT_ENTRY_SIZE * 3) #define elf_backend_default_execstack 0 -- cgit v1.1