summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Malcomson <matthew.malcomson@arm.com>2022-10-13 11:20:16 +0100
committerMatthew Malcomson <matthew.malcomson@arm.com>2022-10-13 11:22:54 +0100
commiteee3fada8163443b4bb5eeccf84f45a1accd03c4 (patch)
tree79c612037b584234ee586e611736c2d6d7cf4063
parent36b6002396dc0898b6f7097bca4589fefabaac87 (diff)
downloadbinutils-gdb-eee3fada8163443b4bb5eeccf84f45a1accd03c4.tar.gz
Only check for valid Morello bounds on non-exec syms
Capabilities pointing to symbols in SEC_CODE sections are given the bounds of the entire PCC. We ensure that the PCC bounds are padded and aligned as needed in the linker. Capabilities pointing to other symbols (e.g. in data sections) are given the bounds of the symbol that they point to. It is the responsibility of the assembly generator (i.e. usually the compiler) to ensure these bounds are correctly aligned and padded as necessary. We emit a warning for imprecise bounds in the second case, until this patch that warning also looked at the first case. This was a mistake and is rectified in this commit.
-rw-r--r--bfd/elfnn-aarch64.c21
-rw-r--r--ld/testsuite/ld-aarch64/aarch64-elf.exp2
-rw-r--r--ld/testsuite/ld-aarch64/morello-large-function.d23
-rw-r--r--ld/testsuite/ld-aarch64/morello-large-function.s9
4 files changed, 44 insertions, 11 deletions
diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
index be4c735753d..d32b0740184 100644
--- a/bfd/elfnn-aarch64.c
+++ b/bfd/elfnn-aarch64.c
@@ -7131,17 +7131,6 @@ c64_fixup_frag (bfd *input_bfd, struct bfd_link_info *info,
bfd_vma base = value, limit = value + size;
unsigned align = 0;
- if (!bounds_ok && !c64_valid_cap_range (&base, &limit, &align))
- {
- /* Just warn about this. It's not a requirement that bounds on
- objects should be precise, so there's no reason to error out on
- such an object. */
- /* xgettext:c-format */
- _bfd_error_handler
- (_("%pB: capability range for '%s' may exceed object bounds"),
- input_bfd, sym_name);
- }
-
if (perm_sec && perm_sec->flags & SEC_CODE)
{
/* Any symbol pointing into an executable section gets bounds according
@@ -7160,6 +7149,16 @@ c64_fixup_frag (bfd *input_bfd, struct bfd_link_info *info,
data or jump to other functions. */
size = pcc_high - pcc_low;
}
+ else if (!bounds_ok && !c64_valid_cap_range (&base, &limit, &align))
+ {
+ /* Just warn about this. It's not a requirement that bounds on
+ objects should be precise, so there's no reason to error out on
+ such an object. */
+ /* xgettext:c-format */
+ _bfd_error_handler
+ (_("%pB: capability range for '%s' may exceed object bounds"),
+ input_bfd, sym_name);
+ }
if (perm_sec != NULL)
{
diff --git a/ld/testsuite/ld-aarch64/aarch64-elf.exp b/ld/testsuite/ld-aarch64/aarch64-elf.exp
index 73c414ad7b4..b32cb235ead 100644
--- a/ld/testsuite/ld-aarch64/aarch64-elf.exp
+++ b/ld/testsuite/ld-aarch64/aarch64-elf.exp
@@ -392,6 +392,8 @@ run_dump_test_lp64 "morello-illegal-tls"
run_dump_test_lp64 "morello-illegal-tls-pie"
run_dump_test_lp64 "morello-illegal-tls-shared"
+run_dump_test_lp64 "morello-large-function"
+
run_dump_test "no-morello-syms-static"
run_dump_test "reloc-overflow-bad"
diff --git a/ld/testsuite/ld-aarch64/morello-large-function.d b/ld/testsuite/ld-aarch64/morello-large-function.d
new file mode 100644
index 00000000000..dc0af92e12f
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/morello-large-function.d
@@ -0,0 +1,23 @@
+# Mainly here to check that this actually links.
+# This testcase used to complain that the function capability may have
+# imprecise bounds, but since such capabilities are given PCC bounds that error
+# was invalid.
+#
+# Even though the only point is to check that the testcase links, we still
+# ensure that the dump of the .data section contains a relocation with the
+# correct permissions.
+#as: -march=morello+c64
+#ld: -pie -static
+#objdump: -DR -j .data
+
+.*: file format .*
+
+
+Disassembly of section \.data:
+
+[0-9a-f]+ <__data_start>:
+ *[0-9a-f]+: .*
+ .*: R_MORELLO_RELATIVE \*ABS\*\+.*
+ *[0-9a-f]+: .* udf #0
+ *[0-9a-f]+: .*
+ *[0-9a-f]+: 04000000 .*
diff --git a/ld/testsuite/ld-aarch64/morello-large-function.s b/ld/testsuite/ld-aarch64/morello-large-function.s
new file mode 100644
index 00000000000..46cb51e0c68
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/morello-large-function.s
@@ -0,0 +1,9 @@
+.data
+ .chericap _start
+.text
+ .globl _start
+ .type _start,@function
+_start:
+ ret
+ .zero 0x8000
+ .size _start, .-_start