public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Palmer Dabbelt <palmer@rivosinc.com>
To: binutils@sourceware.org
Cc: Palmer Dabbelt <palmer@rivosinc.com>
Subject: [PATCH 2/2] ld: RISC-V: Test R_RISCV_BRANCH truncation errors
Date: Mon, 30 Jan 2023 13:06:42 -0800	[thread overview]
Message-ID: <20230130210642.7579-2-palmer@rivosinc.com> (raw)
In-Reply-To: <20230130210642.7579-1-palmer@rivosinc.com>

We can't actually produce binaries with these errors from the assembler,
since it magically converts far branches into multi-instruction
sequences, so instead use objcopy to make the symbol weak after the
assembler has a chance to know that's going to happen.
---
 ld/testsuite/ld-riscv-elf/far-branch-fail-01.s | 16 ++++++++++++++++
 ld/testsuite/ld-riscv-elf/far-branch-fail-02.s | 12 ++++++++++++
 ld/testsuite/ld-riscv-elf/far-branch-fail.d    |  7 +++++++
 ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp     |  1 +
 4 files changed, 36 insertions(+)
 create mode 100644 ld/testsuite/ld-riscv-elf/far-branch-fail-01.s
 create mode 100644 ld/testsuite/ld-riscv-elf/far-branch-fail-02.s
 create mode 100644 ld/testsuite/ld-riscv-elf/far-branch-fail.d

diff --git a/ld/testsuite/ld-riscv-elf/far-branch-fail-01.s b/ld/testsuite/ld-riscv-elf/far-branch-fail-01.s
new file mode 100644
index 00000000000..4c96671c78e
--- /dev/null
+++ b/ld/testsuite/ld-riscv-elf/far-branch-fail-01.s
@@ -0,0 +1,16 @@
+.text
+.global space1
+space1:
+.rep 1024
+	nop
+.endr
+
+.global glob
+glob:
+	addi x0, x0, 2
+
+.global space2
+space2:
+.rep 1024
+	nop
+.endr
diff --git a/ld/testsuite/ld-riscv-elf/far-branch-fail-02.s b/ld/testsuite/ld-riscv-elf/far-branch-fail-02.s
new file mode 100644
index 00000000000..fc51a0bed6e
--- /dev/null
+++ b/ld/testsuite/ld-riscv-elf/far-branch-fail-02.s
@@ -0,0 +1,12 @@
+.text
+.global _start
+_start:
+	beq a0, a1, space1
+	beq a0, a1, glob
+	beq a0, a1, space2
+
+.global glob
+glob:
+.global glob_orig
+glob_orig:
+	addi x0, x0, 1
diff --git a/ld/testsuite/ld-riscv-elf/far-branch-fail.d b/ld/testsuite/ld-riscv-elf/far-branch-fail.d
new file mode 100644
index 00000000000..668b63a8d08
--- /dev/null
+++ b/ld/testsuite/ld-riscv-elf/far-branch-fail.d
@@ -0,0 +1,7 @@
+#name: fail on branch overflows
+#source: far-branch-fail-01.s
+#source: far-branch-fail-02.s RUN_OBJCOPY
+#objcopy_objects: -W glob
+#objdump: -d
+#ld:
+#error: .*relocation truncated to fit: R_RISCV_BRANCH against symbol.*glob.*
diff --git a/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp b/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
index 0f7ccd92ed5..1edbe8bd67a 100644
--- a/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
+++ b/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
@@ -169,6 +169,7 @@ if [istarget "riscv*-*-*"] {
     run_dump_test "attr-merge-priv-spec-failed-05"
     run_dump_test "attr-merge-priv-spec-failed-06"
     run_dump_test "attr-phdr"
+    run_dump_test "far-branch-fail"
     run_ld_link_tests [list \
 	[list "Weak reference 32" "-T weakref.ld -m[riscv_choose_ilp32_emul]" "" \
 	    "-march=rv32i -mabi=ilp32" {weakref32.s} \
-- 
2.39.0


  reply	other threads:[~2023-01-30 21:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-30 21:06 [PATCH 1/2] gas: RISC-V: Add a test for near->far branch conversion Palmer Dabbelt
2023-01-30 21:06 ` Palmer Dabbelt [this message]
2023-01-31  3:37 ` Nelson Chu
2023-01-31  8:57 ` Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230130210642.7579-2-palmer@rivosinc.com \
    --to=palmer@rivosinc.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).