From: Matthew Malcomson Date: Mon, 20 Sep 2021 15:29:01 +0000 (+0100) Subject: morello-binutils: Adjust c64_valid_cap_range calculation X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dbd880c7c11191db9690f0dc26f42e4e3e2a9a40;p=thirdparty%2Fbinutils-gdb.git morello-binutils: Adjust c64_valid_cap_range calculation This function had a buggy implementation of rounding a value up to a given power of 2. Aligning to a multiple of 16 would align to a multiple of 32 and so on. This was observable when linking object files that had very large objects in them. The compiler would ensure that these objects are large enough that they are exactly representable, but the linker would complain that they are not because the linker asserted extra alignment than the compiler. Here we fix the bug, add a few testcases, and adjust an existing testcase in the area. --- diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c index 94f5cbca3ba..55bf288a754 100644 --- a/bfd/elfnn-aarch64.c +++ b/bfd/elfnn-aarch64.c @@ -4797,7 +4797,7 @@ exponent (uint64_t len) #undef CAP_MAX_EXPONENT } -#define ONES(x) ((1ULL << ((x) + 1)) - 1) +#define ONES(x) ((1ULL << (x)) - 1) #define ALIGN_UP(x, a) (((x) + ONES (a)) & (~ONES (a))) static bfd_boolean diff --git a/ld/testsuite/ld-aarch64/aarch64-elf.exp b/ld/testsuite/ld-aarch64/aarch64-elf.exp index e9cb95d5e17..228cfe224c5 100644 --- a/ld/testsuite/ld-aarch64/aarch64-elf.exp +++ b/ld/testsuite/ld-aarch64/aarch64-elf.exp @@ -244,6 +244,8 @@ run_dump_test_lp64 "emit-relocs-morello-2" run_dump_test_lp64 "emit-relocs-morello-2-a64c" run_dump_test_lp64 "emit-relocs-morello-3" run_dump_test_lp64 "emit-relocs-morello-3-a64c" +run_dump_test_lp64 "emit-relocs-morello-4" +run_dump_test_lp64 "emit-relocs-morello-5" run_dump_test_lp64 "morello-capinit" run_dump_test_lp64 "morello-stubs" diff --git a/ld/testsuite/ld-aarch64/emit-relocs-morello-4.d b/ld/testsuite/ld-aarch64/emit-relocs-morello-4.d new file mode 100644 index 00000000000..04cfa79a042 --- /dev/null +++ b/ld/testsuite/ld-aarch64/emit-relocs-morello-4.d @@ -0,0 +1,14 @@ +#source: emit-relocs-morello-4.s +#as: -march=morello+c64 +#ld: -static +#readelf: --relocs --syms + + +#... +Relocation section[^\n]*contains 1 entry: +#... +Symbol table[^\n]*contains[^\n]*: + Num: Value Size.* +#... + [0-9]+: [0-9a-f]+0 64016 [^\n]* bigarray +#pass diff --git a/ld/testsuite/ld-aarch64/emit-relocs-morello-4.s b/ld/testsuite/ld-aarch64/emit-relocs-morello-4.s new file mode 100644 index 00000000000..d91d85ab5eb --- /dev/null +++ b/ld/testsuite/ld-aarch64/emit-relocs-morello-4.s @@ -0,0 +1,17 @@ +// Checking that having a relocation against very large arrays that are not +// problematic w.r.t. capability bounds representation do not error. +// The below is somthing that requires being padded +.bss +.globl bigarray +.p2align 4 +bigarray: + .zero 64004 + .zero 12 // Tail padding to ensure precise bounds. + .size bigarray, 64016 + +.text +.globl _start +.type _start STT_FUNC +_start: + adrp c0, :got:bigarray + ldr c0, [c0, #:got_lo12:bigarray] diff --git a/ld/testsuite/ld-aarch64/emit-relocs-morello-5.d b/ld/testsuite/ld-aarch64/emit-relocs-morello-5.d new file mode 100644 index 00000000000..05bbef145e0 --- /dev/null +++ b/ld/testsuite/ld-aarch64/emit-relocs-morello-5.d @@ -0,0 +1,6 @@ +#source: emit-relocs-morello-5.s +#as: -march=morello+c64 +#ld: -static +#error: .*: capability range may exceed object bounds +#error: .*: in function `_start':.* +#error: .*: dangerous relocation: unsupported relocation diff --git a/ld/testsuite/ld-aarch64/emit-relocs-morello-5.s b/ld/testsuite/ld-aarch64/emit-relocs-morello-5.s new file mode 100644 index 00000000000..0493c26065c --- /dev/null +++ b/ld/testsuite/ld-aarch64/emit-relocs-morello-5.s @@ -0,0 +1,15 @@ +// Checking that having a relocation against very large arrays whose size can +// not be represented gives the corresponding error. +.bss +.globl bigarray +.p2align 4 +bigarray: + .zero 64004 + .size bigarray, 64004 + +.text +.globl _start +.type _start STT_FUNC +_start: + adrp c0, :got:bigarray + ldr c0, [c0, #:got_lo12:bigarray] diff --git a/ld/testsuite/ld-aarch64/morello-sec-round.d b/ld/testsuite/ld-aarch64/morello-sec-round.d index 00eceb0386a..b553a604acd 100644 --- a/ld/testsuite/ld-aarch64/morello-sec-round.d +++ b/ld/testsuite/ld-aarch64/morello-sec-round.d @@ -7,5 +7,5 @@ Idx Name Size VMA LMA File off Algn #... 1 .text_sec 00020004 ...........20000 [0-9a-f]+ [0-9a-f]+ 2\*\*17 CONTENTS, ALLOC, LOAD, READONLY, CODE - 2 \..* [0-9a-f]+ ...........40080 [0-9a-f]+ [0-9a-f]+ .* + 2 \..* [0-9a-f]+ ...........40040 [0-9a-f]+ [0-9a-f]+ .* #pass