[1/3] bpf: print failing insn for unexpected register

Message ID 20260330224203.3110788-2-vineet.gupta@linux.dev
State New
Headers
Series bpf gas updates |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Test passed

Commit Message

Vineet Gupta March 30, 2026, 10:42 p.m. UTC
  prev:

| /tmp/cc7214hK.s: Assembler messages:
| /tmp/cc7214hK.s:40: Error: unexpected register name `w0' in expression

New

| /tmp/cc7214hK.s: Assembler messages:
| /tmp/cc7214hK.s:40: Error: unexpected register name `w0' in instruction `*(u32 *) (r9+0) = w5'

Signed-off-by: Vineet Gupta <vineet.gupta@linux.dev>
---
 gas/config/tc-bpf.c                              |  6 ++++--
 gas/testsuite/gas/bpf/regs-for-symbols-pseudoc.l | 14 +++++++-------
 2 files changed, 11 insertions(+), 9 deletions(-)
  

Comments

Jan Beulich March 31, 2026, 5:58 a.m. UTC | #1
On 31.03.2026 00:42, Vineet Gupta wrote:
> prev:
> 
> | /tmp/cc7214hK.s: Assembler messages:
> | /tmp/cc7214hK.s:40: Error: unexpected register name `w0' in expression
> 
> New
> 
> | /tmp/cc7214hK.s: Assembler messages:
> | /tmp/cc7214hK.s:40: Error: unexpected register name `w0' in instruction `*(u32 *) (r9+0) = w5'

I may be missing something (in which case I'm sorry for my lack of bpf
knowledge), but is this an improvement? There's no "w0" in the quoted
insn.

Jan
  
Vineet Gupta March 31, 2026, 2:43 p.m. UTC | #2
On 3/30/26 10:58 PM, Jan Beulich wrote:
> On 31.03.2026 00:42, Vineet Gupta wrote:
>> prev:
>>
>> | /tmp/cc7214hK.s: Assembler messages:
>> | /tmp/cc7214hK.s:40: Error: unexpected register name `w0' in expression
>>
>> New
>>
>> | /tmp/cc7214hK.s: Assembler messages:
>> | /tmp/cc7214hK.s:40: Error: unexpected register name `w0' in instruction `*(u32 *) (r9+0) = w5'
> I may be missing something (in which case I'm sorry for my lack of bpf
> knowledge), but is this an improvement? There's no "w0" in the quoted
> insn.

The improvement is additional printing of failing insn as opposed to just the
reg that causes the issue.

Thx,
-Vineet
  
Vineet Gupta March 31, 2026, 2:50 p.m. UTC | #3
On 3/31/26 7:43 AM, Vineet Gupta wrote:
>>> | /tmp/cc7214hK.s: Assembler messages:
>>> | /tmp/cc7214hK.s:40: Error: unexpected register name `w0' in instruction `*(u32 *) (r9+0) = w5'
>> I may be missing something (in which case I'm sorry for my lack of bpf
>> knowledge), but is this an improvement? There's no "w0" in the quoted
>> insn.
> The improvement is additional printing of failing insn as opposed to just the
> reg that causes the issue.

Doh ! I see what you mean, will fix it in v2.

Thx,
-Vineet
  

Patch

diff --git a/gas/config/tc-bpf.c b/gas/config/tc-bpf.c
index bc83d3d19d58..57c2b869cbab 100644
--- a/gas/config/tc-bpf.c
+++ b/gas/config/tc-bpf.c
@@ -1235,6 +1235,7 @@  add_relaxed_insn (struct bpf_insn *insn, expressionS *exp)
 
 static int exp_parse_failed = 0;
 static bool parsing_insn_operands = false;
+static char *g_curr_insn_str;
 
 static char *
 parse_expression (char *s, expressionS *exp)
@@ -1357,8 +1358,8 @@  bpf_parse_name (const char *name, expressionS *exp, enum expr_mode mode)
       if (parse_bpf_register ((char *) name, 'r', &regno)
           || parse_bpf_register ((char *) name, 'w', &regno))
         {
-          as_bad (_("unexpected register name `%s' in expression"),
-                  name);
+	  as_bad (_("unexpected register name `%s' in instruction `%s'"),
+		  name, g_curr_insn_str);
           return false;
         }
     }
@@ -1464,6 +1465,7 @@  md_assemble (char *str ATTRIBUTE_UNUSED)
      function above.  */
   partial_match_length = 0;
   errmsg = NULL;
+  g_curr_insn_str = str;
 
 #define PARSE_ERROR(...) parse_error (s > str ? s - str : 0, __VA_ARGS__)
 
diff --git a/gas/testsuite/gas/bpf/regs-for-symbols-pseudoc.l b/gas/testsuite/gas/bpf/regs-for-symbols-pseudoc.l
index eeda735fb993..b12739ed7a68 100644
--- a/gas/testsuite/gas/bpf/regs-for-symbols-pseudoc.l
+++ b/gas/testsuite/gas/bpf/regs-for-symbols-pseudoc.l
@@ -1,8 +1,8 @@ 
 .*: Assembler messages:
-.*:1: Error: unexpected register name `w3' in expression
-.*:2: Error: unexpected register name `r3' in expression
-.*:2: Error: unexpected register name `r3' in expression
-.*:3: Error: unexpected register name `r3' in expression
-.*:3: Error: unexpected register name `r3' in expression
-.*:4: Error: unexpected register name `r3' in expression
-.*:4: Error: unexpected register name `r3' in expression
+.*:1: Error: unexpected register name `w3' in instruction `goto w3'
+.*:2: Error: unexpected register name `r3' in instruction `r2 =r3'
+.*:2: Error: unexpected register name `r3' in instruction `r2 =r3'
+.*:3: Error: unexpected register name `r3' in instruction `r2 =r3'
+.*:3: Error: unexpected register name `r3' in instruction `r2 =r3'
+.*:4: Error: unexpected register name `r3' in instruction `r2 =1\+r3'
+.*:4: Error: unexpected register name `r3' in instruction `r2 =1\+r3'