From 79e741920446582bd0e09f3e2b9f899c258efa56 Mon Sep 17 00:00:00 2001 From: Renlin Li Date: Wed, 13 Dec 2017 12:11:25 +0000 Subject: [BFD][AARCH64]Disallow R_AARCH64_ABS32(LP64) & R_AARCH64_ABS16 in const section of shared object. R_AARCH64_ABS64, R_AARCH64_ABS32 and R_AARCH64_ABS16 are data relocations supported in AArch64 elf ABI. R_AARCH64_ABS64 under LP64 is allowed in shared object and a dynamic relocation entry will be generated. This allows the dynamic linker to do further symbol resolution. R_AARCH64_ABS32 likewise is allowed in shared object, however under ILP32 abi. The original behavior for R_AARCH64_ABS32 under LP64 is that, it's allowed in shared object and silently resolved at static linking time. No dynamic relocation entry is generate for it. R_AARCH64_ABS16 is allowed in shared object under both L64 and ILP32. It's resolved at static linking time as well. Under LP64, the address should be 64-bit. R_AARCH64_ABS32 relocation indicates an address that is only sized 32 bits which is meaningless in LP64 shared object. It's useful to error out. I have checked glibc dynamic linker code, R_AARCH64_ABS16 is not supported at all. So R_AARCH64_ABS16 should be reject in shared object completely. In this patch, R_AARCH64_ABS32 is rejected under LP64 in constant section of shared object. R_AARCH64_ABS16 is rejected in constant section of shared object in both ABI. This will sometimes provide useful information for buggy code. --- bfd/elfnn-aarch64.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'bfd/elfnn-aarch64.c') diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c index 212d335abc..52da856df7 100644 --- a/bfd/elfnn-aarch64.c +++ b/bfd/elfnn-aarch64.c @@ -7070,6 +7070,27 @@ elfNN_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info, switch (bfd_r_type) { + case BFD_RELOC_AARCH64_16: +#if ARCH_SIZE == 64 + case BFD_RELOC_AARCH64_32: +#endif + if (bfd_link_pic (info) + && (sec->flags & SEC_ALLOC) != 0 + && (sec->flags & SEC_READONLY) != 0) + { + int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; + _bfd_error_handler + /* xgettext:c-format */ + (_("%B: relocation %s against `%s' can not be used when making " + "a shared object"), + abfd, elfNN_aarch64_howto_table[howto_index].name, + (h) ? h->root.root.string : "a local symbol"); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + else + break; + case BFD_RELOC_AARCH64_MOVW_G0_NC: case BFD_RELOC_AARCH64_MOVW_G1_NC: case BFD_RELOC_AARCH64_MOVW_G2_NC: -- cgit v1.2.3