From: Will Hawkins <hawkinsw@obs.cr>
To: binutils@sourceware.org
Cc: Will Hawkins <hawkinsw@obs.cr>
Subject: [PATCH] as: fix bpf expression parsing regression
Date: Fri, 16 Feb 2024 09:04:58 -0500 [thread overview]
Message-ID: <20240216140501.1039645-1-hawkinsw@obs.cr> (raw)
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
next reply other threads:[~2024-02-16 14:05 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-16 14:04 Will Hawkins [this message]
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
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=20240216140501.1039645-1-hawkinsw@obs.cr \
--to=hawkinsw@obs.cr \
--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).