public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] as: fix bpf expression parsing regression
@ 2024-02-16 14:04 Will Hawkins
  2024-02-19 11:16 ` Nick Clifton
  2024-02-19 18:19 ` Jose E. Marchesi
  0 siblings, 2 replies; 7+ messages in thread
From: Will Hawkins @ 2024-02-16 14:04 UTC (permalink / raw)
  To: binutils; +Cc: Will Hawkins

As a result of a switch instead of an if, as would issue non-specific
error messages when it encountered an operand it could not parse in bpf.
This patch fixes that regression and adds a test to prevent it from
reoccurring.

Tested for bpf-unknown-none on x86_64-redhat-linux.

gas/ChangeLog:

	* config/tc-bpf.c (parse_expression): Change switch to if so that error
	* condition is handled.
	* testsuite/gas/bpf/bpf.exp: Invoke new test.
	* testsuite/gas/bpf/indcall-badoperand.d: New test.
	* testsuite/gas/bpf/indcall-badoperand.l: New test.
	* testsuite/gas/bpf/indcall-badoperand.s: New test.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
---
 gas/config/tc-bpf.c                        | 2 +-
 gas/testsuite/gas/bpf/bpf.exp              | 3 +++
 gas/testsuite/gas/bpf/indcall-badoperand.d | 3 +++
 gas/testsuite/gas/bpf/indcall-badoperand.l | 3 +++
 gas/testsuite/gas/bpf/indcall-badoperand.s | 8 ++++++++
 5 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 gas/testsuite/gas/bpf/indcall-badoperand.d
 create mode 100644 gas/testsuite/gas/bpf/indcall-badoperand.l
 create mode 100644 gas/testsuite/gas/bpf/indcall-badoperand.s

diff --git a/gas/config/tc-bpf.c b/gas/config/tc-bpf.c
index 43e098c2a86..86489c72898 100644
--- a/gas/config/tc-bpf.c
+++ b/gas/config/tc-bpf.c
@@ -1240,7 +1240,7 @@ parse_expression (char *s, expressionS *exp)
   s = input_line_pointer;
   input_line_pointer = saved_input_line_pointer;
 
-  switch (exp->X_op == O_absent || exp_parse_failed)
+  if (exp->X_op == O_absent || exp_parse_failed)
     return NULL;
 
   /* The expression parser may consume trailing whitespaces.  We have
diff --git a/gas/testsuite/gas/bpf/bpf.exp b/gas/testsuite/gas/bpf/bpf.exp
index dae8bd924d0..5faae5b859e 100644
--- a/gas/testsuite/gas/bpf/bpf.exp
+++ b/gas/testsuite/gas/bpf/bpf.exp
@@ -77,6 +77,9 @@ if {[istarget bpf*-*-*]} {
     run_dump_test disp32-overflow
     run_dump_test imm32-overflow
 
+    # Bad operand (regression)
+    run_dump_test indcall-badoperand
+
     # In Pseudo-C it is not possible to refer to symbols
     # as operands that have the same name than registers.
     run_dump_test regs-for-symbols-pseudoc
diff --git a/gas/testsuite/gas/bpf/indcall-badoperand.d b/gas/testsuite/gas/bpf/indcall-badoperand.d
new file mode 100644
index 00000000000..bf2e9e8e643
--- /dev/null
+++ b/gas/testsuite/gas/bpf/indcall-badoperand.d
@@ -0,0 +1,3 @@
+#as: -EL -mno-relax
+#source: indcall-badoperand.s
+#error_output: indcall-badoperand.l
diff --git a/gas/testsuite/gas/bpf/indcall-badoperand.l b/gas/testsuite/gas/bpf/indcall-badoperand.l
new file mode 100644
index 00000000000..d791435a2ac
--- /dev/null
+++ b/gas/testsuite/gas/bpf/indcall-badoperand.l
@@ -0,0 +1,3 @@
+.*: Assembler messages:
+.*:7: Error: unrecognized instruction `call %0'
+.*:7: Error: expected register name, got '%0'
diff --git a/gas/testsuite/gas/bpf/indcall-badoperand.s b/gas/testsuite/gas/bpf/indcall-badoperand.s
new file mode 100644
index 00000000000..cf19c0a56b6
--- /dev/null
+++ b/gas/testsuite/gas/bpf/indcall-badoperand.s
@@ -0,0 +1,8 @@
+
+    .text
+    .align 4
+main:
+
+    mov %r0, 1
+    call %0
+    exit
-- 
2.43.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-02-19 22:22 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-16 14:04 [PATCH] as: fix bpf expression parsing regression Will Hawkins
2024-02-19 11:16 ` Nick Clifton
2024-02-19 16:32   ` Will Hawkins
2024-02-19 18:19 ` Jose E. Marchesi
2024-02-19 18:52   ` Jose E. Marchesi
2024-02-19 19:53     ` Jose E. Marchesi
2024-02-19 22:22       ` Will Hawkins

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).