[binutils-gdb] gas: bpf: test `gotol' in a compound conditional
Vineet Gupta
vineetg@sourceware.org
Thu Sep 10 03:52:31 GMT 2026
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=31393a5fd0e88f3e1384665352a7e13cfdd70e38
commit 31393a5fd0e88f3e1384665352a7e13cfdd70e38
Author: Vineet Gupta <vineet.gupta@linux.dev>
Date: Thu Sep 10 09:14:22 2026 +0530
gas: bpf: test `gotol' in a compound conditional
The PR gas/34558 coverage added with the fix exercises only the standalone
`gotol'. That case can also be fixed by moving BPF_INSN_JAL above
BPF_INSN_JAR in bpf_opcodes[], so that `gotol%w%d32' is tried before
`goto%w%d16'. The compound conditional jumps embed the same `goto%w%d16'
and have no `gotol' counterpart to reorder ahead of them, so they stay
broken under that approach:
if r1 > r2 gotol +1
assembles silently to JGT with a R_BPF_GNU_64_16 relocation against an
undefined symbol `l'. Conditional jumps only have the 16-bit `off' field,
so there is no `gotol' form of them.
Add a test for the compound forms, so the reordering alternative does not
look equivalent to %t. Verified that it fails when %t is replaced by the
reordering: no diagnostic, and each of its three lines silently encoded as
a conditional jump with a relocation against `l'.
gas/
* testsuite/gas/bpf/jump-gotol-cond-pseudoc.s: New test.
* testsuite/gas/bpf/jump-gotol-cond-pseudoc.d: New test.
* testsuite/gas/bpf/jump-gotol-cond-pseudoc.l: New test.
* testsuite/gas/bpf/bpf.exp: Run it.
Signed-off-by: Vineet Gupta <vineet.gupta@linux.dev>
Diff:
---
gas/testsuite/gas/bpf/bpf.exp | 1 +
gas/testsuite/gas/bpf/jump-gotol-cond-pseudoc.d | 4 ++++
gas/testsuite/gas/bpf/jump-gotol-cond-pseudoc.l | 9 +++++++++
gas/testsuite/gas/bpf/jump-gotol-cond-pseudoc.s | 11 +++++++++++
4 files changed, 25 insertions(+)
diff --git a/gas/testsuite/gas/bpf/bpf.exp b/gas/testsuite/gas/bpf/bpf.exp
index ff52481cda4..9884b36678c 100644
--- a/gas/testsuite/gas/bpf/bpf.exp
+++ b/gas/testsuite/gas/bpf/bpf.exp
@@ -39,6 +39,7 @@ if {[istarget bpf*-*-*]} {
run_dump_test jump32
run_dump_test jump32-pseudoc
run_dump_test jump-gotol-signed-pseudoc
+ run_dump_test jump-gotol-cond-pseudoc
run_dump_test atomic-v1
run_dump_test atomic
run_dump_test atomic-pseudoc
diff --git a/gas/testsuite/gas/bpf/jump-gotol-cond-pseudoc.d b/gas/testsuite/gas/bpf/jump-gotol-cond-pseudoc.d
new file mode 100644
index 00000000000..f33ab7fcb35
--- /dev/null
+++ b/gas/testsuite/gas/bpf/jump-gotol-cond-pseudoc.d
@@ -0,0 +1,4 @@
+#as: -EL -mdialect=pseudoc
+#source: jump-gotol-cond-pseudoc.s
+#error_output: jump-gotol-cond-pseudoc.l
+#name: eBPF gotol in a compound conditional, pseudoc syntax
diff --git a/gas/testsuite/gas/bpf/jump-gotol-cond-pseudoc.l b/gas/testsuite/gas/bpf/jump-gotol-cond-pseudoc.l
new file mode 100644
index 00000000000..a4408334ce5
--- /dev/null
+++ b/gas/testsuite/gas/bpf/jump-gotol-cond-pseudoc.l
@@ -0,0 +1,9 @@
+.*: Assembler messages:
+.*:9: Error: unexpected register name `r2' in instruction `if r1>r2'
+.*:9: Error: unrecognized instruction `if r1>r2 gotol\+1'
+.*:9: Error: expected white space, got 'l\+1'
+.*:10: Error: unrecognized instruction `if r1&5 gotol-1'
+.*:10: Error: expected white space, got 'l-1'
+.*:11: Error: unexpected register name `w2' in instruction `if w1==w2'
+.*:11: Error: unrecognized instruction `if w1==w2 gotol\+1'
+.*:11: Error: expected white space, got 'l\+1'
diff --git a/gas/testsuite/gas/bpf/jump-gotol-cond-pseudoc.s b/gas/testsuite/gas/bpf/jump-gotol-cond-pseudoc.s
new file mode 100644
index 00000000000..14625473a9a
--- /dev/null
+++ b/gas/testsuite/gas/bpf/jump-gotol-cond-pseudoc.s
@@ -0,0 +1,11 @@
+ # PR gas/34558: `gotol' written where a compound conditional jump
+ # expects `goto'. Conditional jumps only have the 16-bit `off'
+ # field, so there is no `gotol' form of them. These used to match
+ # the embedded `goto%w%d16' of the conditional templates, with the
+ # trailing `l' parsed as the start of the branch offset expression,
+ # silently assembling to a conditional jump plus a relocation
+ # against an undefined symbol `l'.
+ .text
+ if r1 > r2 gotol +1
+ if r1 & 5 gotol -1
+ if w1 == w2 gotol +1
More information about the Binutils-cvs
mailing list