]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
morello-binutils: Adjust c64_valid_cap_range calculation
authorMatthew Malcomson <matthew.malcomson@arm.com>
Mon, 20 Sep 2021 15:29:01 +0000 (16:29 +0100)
committerJohn Baldwin <jhb@FreeBSD.org>
Thu, 1 Sep 2022 22:59:24 +0000 (15:59 -0700)
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.

bfd/elfnn-aarch64.c
ld/testsuite/ld-aarch64/aarch64-elf.exp
ld/testsuite/ld-aarch64/emit-relocs-morello-4.d [new file with mode: 0644]
ld/testsuite/ld-aarch64/emit-relocs-morello-4.s [new file with mode: 0644]
ld/testsuite/ld-aarch64/emit-relocs-morello-5.d [new file with mode: 0644]
ld/testsuite/ld-aarch64/emit-relocs-morello-5.s [new file with mode: 0644]
ld/testsuite/ld-aarch64/morello-sec-round.d

index 84286a7ee284daffe68eb100a0b49416d1a845d3..14b149a400780d7fd8ca6230c577eb52c4834deb 100644 (file)
@@ -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 bool
index df1b6dbc2e94213b9cfe0c5a7959fda1f39267ee..21fdfd26a0ec1f948f88124a82f65a81e8738848 100644 (file)
@@ -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 (file)
index 0000000..04cfa79
--- /dev/null
@@ -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 (file)
index 0000000..d91d85a
--- /dev/null
@@ -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 (file)
index 0000000..05bbef1
--- /dev/null
@@ -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 (file)
index 0000000..0493c26
--- /dev/null
@@ -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]
index 00eceb0386a3f8890c2876a4a6bac9569f146e33..b553a604acd92a2b0c5e151546e2c19a04101f70 100644 (file)
@@ -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