[binutils-gdb] bpf: print failing insn for unexpected register

Jose E. Marchesi jemarch@sourceware.org
Thu Apr 2 16:34:36 GMT 2026


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=0d6dd29467f8a7fcaa6d9d122f93735dc9be72a6

commit 0d6dd29467f8a7fcaa6d9d122f93735dc9be72a6
Author: Vineet Gupta <vineet.gupta@linux.dev>
Date:   Tue Mar 31 13:42:09 2026 -0700

    bpf: print failing insn for unexpected register
    
    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) = w0'
    
    Signed-off-by: Vineet Gupta <vineet.gupta@linux.dev>

Diff:
---
 gas/config/tc-bpf.c                              |  6 ++++--
 gas/testsuite/gas/bpf/regs-for-symbols-pseudoc.l | 14 +++++++-------
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/gas/config/tc-bpf.c b/gas/config/tc-bpf.c
index bc83d3d19d5..57c2b869cba 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 eeda735fb99..b12739ed7a6 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'


More information about the Binutils-cvs mailing list