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

Jose E. Marchesi jemarch@gnu.org
Thu Apr 2 11:49:34 GMT 2026


OK.
Thanks.

> 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>
> ---
>  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 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'


More information about the bpf mailing list