From: Nick Clifton Date: Thu, 12 Oct 2017 12:38:20 +0000 (+0100) Subject: Force the AArch64 linker backend to refuse to link when it encounters unresoleable... X-Git-Tag: users/ARM/embedded-binutils-master-2017q4~647 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1d75a8e26e6def4f492c84a5f678e41ddebda799;p=external%2Fbinutils.git Force the AArch64 linker backend to refuse to link when it encounters unresoleable relocations. * reloc.c (enum bfd_reloc_status): Start values at 2. * bfd-in2.h: Regenerate. * elfnn-aarch64.c (aarch64_relocate): Invert sense of function, so that a TRUE return indicates success. Compare the result of calling _bfd_aarch64_elf_put_addend against bfd_reloc_ok. (build_one_stub): Change sense of tests against aarch64_relocate return value. (elfNN_aarch64_tls_relax): Return bfd_reloc_notsupported, rather than FALSE, when an error is detected. (elfNN_aarch64_final_link_relocate): Likewise. * testsuite/ld-aarch64/pcrel_pic_defined.d: Expect errors not warnings. Expect errors about unsupported relocations. * testsuite/ld-aarch64/pcrel_pic_undefined.d: Likewise. --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 5651316..a62f7f6 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,16 @@ +2017-10-12 Nick Clifton + + * reloc.c (enum bfd_reloc_status): Start values at 2. + * bfd-in2.h: Regenerate. + * elfnn-aarch64.c (aarch64_relocate): Invert sense of function, so + that a TRUE return indicates success. Compare the result of + calling _bfd_aarch64_elf_put_addend against bfd_reloc_ok. + (build_one_stub): Change sense of tests against aarch64_relocate + return value. + (elfNN_aarch64_tls_relax): Return bfd_reloc_notsupported, rather + than FALSE, when an error is detected. + (elfNN_aarch64_final_link_relocate): Likewise. + 2017-10-12 H.J. Lu * elf32-i386.c (elf_backend_hide_symbol): New. diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 4ba05b1..8265efa 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -2466,8 +2466,9 @@ unsigned int bfd_arch_mach_octets_per_byte typedef enum bfd_reloc_status { - /* No errors detected. */ - bfd_reloc_ok, + /* No errors detected. Note - the value 2 is used so that it + will not be mistaken for the boolean TRUE or FALSE values. */ + bfd_reloc_ok = 2, /* The relocation was performed, but there was an overflow. */ bfd_reloc_overflow, diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c index 9297056..5fd314d 100644 --- a/bfd/elfnn-aarch64.c +++ b/bfd/elfnn-aarch64.c @@ -2610,6 +2610,8 @@ elfNN_aarch64_link_hash_table_create (bfd *abfd) return &ret->root.root; } +/* Perform relocation R_TYPE. Returns TRUE upon success, FALSE otherwise. */ + static bfd_boolean aarch64_relocate (unsigned int r_type, bfd *input_bfd, asection *input_section, bfd_vma offset, bfd_vma value) @@ -2625,7 +2627,7 @@ aarch64_relocate (unsigned int r_type, bfd *input_bfd, asection *input_section, value = _bfd_aarch64_elf_resolve_relocation (r_type, place, value, 0, FALSE); return _bfd_aarch64_elf_put_addend (input_bfd, input_section->contents + offset, r_type, - howto, value); + howto, value) == bfd_reloc_ok; } static enum elf_aarch64_stub_type @@ -2965,22 +2967,22 @@ aarch64_build_one_stub (struct bfd_hash_entry *gen_entry, switch (stub_entry->stub_type) { case aarch64_stub_adrp_branch: - if (aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21), stub_bfd, stub_sec, - stub_entry->stub_offset, sym_value)) + if (!aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21), stub_bfd, stub_sec, + stub_entry->stub_offset, sym_value)) /* The stub would not have been relaxed if the offset was out of range. */ BFD_FAIL (); - if (aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC), stub_bfd, stub_sec, - stub_entry->stub_offset + 4, sym_value)) + if (!aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC), stub_bfd, stub_sec, + stub_entry->stub_offset + 4, sym_value)) BFD_FAIL (); break; case aarch64_stub_long_branch: /* We want the value relative to the address 12 bytes back from the value itself. */ - if (aarch64_relocate (AARCH64_R (PRELNN), stub_bfd, stub_sec, - stub_entry->stub_offset + 16, sym_value + 12)) + if (!aarch64_relocate (AARCH64_R (PRELNN), stub_bfd, stub_sec, + stub_entry->stub_offset + 16, sym_value + 12)) BFD_FAIL (); break; @@ -3001,8 +3003,8 @@ aarch64_build_one_stub (struct bfd_hash_entry *gen_entry, break; case aarch64_stub_erratum_843419_veneer: - if (aarch64_relocate (AARCH64_R (JUMP26), stub_bfd, stub_sec, - stub_entry->stub_offset + 4, sym_value + 4)) + if (!aarch64_relocate (AARCH64_R (JUMP26), stub_bfd, stub_sec, + stub_entry->stub_offset + 4, sym_value + 4)) BFD_FAIL (); break; @@ -4998,7 +5000,7 @@ elfNN_aarch64_final_link_relocate (reloc_howto_type *howto, (_("%B(%A+%#Lx): unresolvable %s relocation against symbol `%s'"), input_bfd, input_section, rel->r_offset, howto->name, name); bfd_set_error (bfd_error_bad_value); - return FALSE; + return bfd_reloc_notsupported; } else if (h->plt.offset == (bfd_vma) -1) goto bad_ifunc_reloc; @@ -5022,7 +5024,7 @@ bad_ifunc_reloc: "symbol `%s' isn't handled by %s"), input_bfd, howto->name, name, __FUNCTION__); bfd_set_error (bfd_error_bad_value); - return FALSE; + return bfd_reloc_notsupported; case BFD_RELOC_AARCH64_NN: if (rel->r_addend != 0) @@ -5038,7 +5040,7 @@ bad_ifunc_reloc: "symbol `%s' has non-zero addend: %Ld"), input_bfd, howto->name, name, rel->r_addend); bfd_set_error (bfd_error_bad_value); - return FALSE; + return bfd_reloc_notsupported; } /* Generate dynamic relocation only when there is a @@ -5362,7 +5364,7 @@ bad_ifunc_reloc: input_bfd, elfNN_aarch64_howto_table[howto_index].name, h->root.root.string); bfd_set_error (bfd_error_bad_value); - return FALSE; + return bfd_reloc_notsupported; } /* Fall through. */ @@ -8766,7 +8768,8 @@ elf_aarch64_update_plt_entry (bfd *output_bfd, { reloc_howto_type *howto = elfNN_aarch64_howto_from_bfd_reloc (r_type); - _bfd_aarch64_elf_put_addend (output_bfd, plt_entry, r_type, howto, value); + /* FIXME: We should check the return value from this function call. */ + (void) _bfd_aarch64_elf_put_addend (output_bfd, plt_entry, r_type, howto, value); } static void diff --git a/bfd/reloc.c b/bfd/reloc.c index 97a17f5..b4d8584 100644 --- a/bfd/reloc.c +++ b/bfd/reloc.c @@ -65,8 +65,9 @@ CODE_FRAGMENT . .typedef enum bfd_reloc_status .{ -. {* No errors detected. *} -. bfd_reloc_ok, +. {* No errors detected. Note - the value 2 is used so that it +. will not be mistaken for the boolean TRUE or FALSE values. *} +. bfd_reloc_ok = 2, . . {* The relocation was performed, but there was an overflow. *} . bfd_reloc_overflow, diff --git a/ld/ChangeLog b/ld/ChangeLog index 80049e0..85353b6 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,9 @@ +2017-10-12 Nick Clifton + + * testsuite/ld-aarch64/pcrel_pic_defined.d: Expect errors not + warnings. Expect errors about unsupported relocations. + * testsuite/ld-aarch64/pcrel_pic_undefined.d: Likewise. + 2017-10-12 H.J. Lu * testsuite/ld-elf/pr22269b.d: Expect warning of diff --git a/ld/testsuite/ld-aarch64/pcrel_pic_defined.d b/ld/testsuite/ld-aarch64/pcrel_pic_defined.d index 743e810..a611e31 100644 --- a/ld/testsuite/ld-aarch64/pcrel_pic_defined.d +++ b/ld/testsuite/ld-aarch64/pcrel_pic_defined.d @@ -1,10 +1,17 @@ #name: PC-Rel relocation against defined #source: pcrel.s #ld: -shared -e0 -defsym global_a=0x1000 -defsym global_b=0x2000 -#warning: .*: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `global_a.*bind externally.*fPIC.* -#warning: .*: relocation R_AARCH64_ADR_PREL_PG_HI21_NC against symbol `global_a.*bind externally.*fPIC.* -#warning: .*: relocation R_AARCH64_ADR_PREL_LO21 against symbol `global_a.*bind externally.*fPIC.* -#warning: .*: relocation R_AARCH64_LD_PREL_LO19 against symbol `global_a.*bind externally.*fPIC.* -#warning: .*: relocation R_AARCH64_PREL16 against symbol `global_a.*bind externally.*fPIC.* -#warning: .*: relocation R_AARCH64_PREL32 against symbol `global_a.*bind externally.*fPIC.* -#warning: .*: relocation R_AARCH64_PREL64 against symbol `global_a.*bind externally.*fPIC.* +#error: .*: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `global_a.*bind externally.*fPIC.* +#error: .*: dangerous relocation: unsupported relocation +#error: .*: relocation R_AARCH64_ADR_PREL_PG_HI21_NC against symbol `global_a.*bind externally.*fPIC.* +#error: .*: dangerous relocation: unsupported relocation +#error: .*: relocation R_AARCH64_ADR_PREL_LO21 against symbol `global_a.*bind externally.*fPIC.* +#error: .*: dangerous relocation: unsupported relocation +#error: .*: relocation R_AARCH64_LD_PREL_LO19 against symbol `global_a.*bind externally.*fPIC.* +#error: .*: dangerous relocation: unsupported relocation +#error: .*: relocation R_AARCH64_PREL16 against symbol `global_a.*bind externally.*fPIC.* +#error: .*: dangerous relocation: unsupported relocation +#error: .*: relocation R_AARCH64_PREL32 against symbol `global_a.*bind externally.*fPIC.* +#error: .*: dangerous relocation: unsupported relocation +#error: .*: relocation R_AARCH64_PREL64 against symbol `global_a.*bind externally.*fPIC.* +#error: .*: dangerous relocation: unsupported relocation diff --git a/ld/testsuite/ld-aarch64/pcrel_pic_undefined.d b/ld/testsuite/ld-aarch64/pcrel_pic_undefined.d index f7f048d..b5d6372 100644 --- a/ld/testsuite/ld-aarch64/pcrel_pic_undefined.d +++ b/ld/testsuite/ld-aarch64/pcrel_pic_undefined.d @@ -1,10 +1,17 @@ #name: PC-Rel relocation against undefined #source: pcrel.s #ld: -shared -e0 -defsym global_b=0x2000 -#warning: .*: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `global_a.*bind externally.*fPIC.* -#warning: .*: relocation R_AARCH64_ADR_PREL_PG_HI21_NC against symbol `global_a.*bind externally.*fPIC.* -#warning: .*: relocation R_AARCH64_ADR_PREL_LO21 against symbol `global_a.*bind externally.*fPIC.* -#warning: .*: relocation R_AARCH64_LD_PREL_LO19 against symbol `global_a.*bind externally.*fPIC.* -#warning: .*: relocation R_AARCH64_PREL16 against symbol `global_a.*bind externally.*fPIC.* -#warning: .*: relocation R_AARCH64_PREL32 against symbol `global_a.*bind externally.*fPIC.* -#warning: .*: relocation R_AARCH64_PREL64 against symbol `global_a.*bind externally.*fPIC.* +#error: .*: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `global_a.*bind externally.*fPIC.* +#error: .*: dangerous relocation: unsupported relocation +#error: .*: relocation R_AARCH64_ADR_PREL_PG_HI21_NC against symbol `global_a.*bind externally.*fPIC.* +#error: .*: dangerous relocation: unsupported relocation +#error: .*: relocation R_AARCH64_ADR_PREL_LO21 against symbol `global_a.*bind externally.*fPIC.* +#error: .*: dangerous relocation: unsupported relocation +#error: .*: relocation R_AARCH64_LD_PREL_LO19 against symbol `global_a.*bind externally.*fPIC.* +#error: .*: dangerous relocation: unsupported relocation +#error: .*: relocation R_AARCH64_PREL16 against symbol `global_a.*bind externally.*fPIC.* +#error: .*: dangerous relocation: unsupported relocation +#error: .*: relocation R_AARCH64_PREL32 against symbol `global_a.*bind externally.*fPIC.* +#error: .*: dangerous relocation: unsupported relocation +#error: .*: relocation R_AARCH64_PREL64 against symbol `global_a.*bind externally.*fPIC.* +#error: .*: dangerous relocation: unsupported relocation