[v2,0/2] bpf: fix gotol with a signed offset, and run the spacing test

Message ID 20260824214138.3964162-1-vineet.gupta@linux.dev
Headers
Series bpf: fix gotol with a signed offset, and run the spacing test |

Message

Vineet Gupta Aug. 24, 2026, 9:41 p.m. UTC
  In the pseudo-C dialect `gotol +1' is silently assembled as `goto l+1'
leading to libbpf load time failures. LLVM obviously supports this so gas
needs fixing.

Ran into this when trying to enable certain selftests which are
currently clang built only while GCC can build them fine. Moreover those
not run tests are declared passing too [1].

Patch 1: Orthogonal issue discovered in the process. Directed tests for
exactly this exist: spacing-pseudoc.{s,d} but are never run.

Patch 2 fixes the actual mis-assembly.

As part of v1 review [2] it was suggested to simply use 'W%' to mandate
at least whitespace i.e. `goto%W%d16'. However that does not work.
gas strips the whitespace next to a sign in the operand field before
md_assemble sees the line, so rejects valid insn: `if rX > N goto +M'
The registered testsuite does not catch either, as it only ever
writes conditional jumps with label operands. So v2 retains the v1
approach to reject a template whose literal text stops in the
middle of a name, letting a later template match the whole mnemonic.

Tested on bpf-unknown-none: 59 expected passes, no failures.

[1] https://lore.kernel.org/bpf/20260821201316.1059129-1-vineet.gupta@linux.dev/
[2] https://gcc.gnu.org/pipermail/bpf/2026-August/000192.html

Vineet Gupta (2):
  gas: bpf: actually run the pseudo-C spacing test
  PR 34558: bpf: don't mis-assemble `gotol' with signed offset

 gas/config/tc-bpf.c                           | 28 ++++++++++++++++++-
 gas/testsuite/gas/bpf/bpf.exp                 |  3 ++
 .../gas/bpf/jump-gotol-signed-pseudoc.d       | 15 ++++++++++
 .../gas/bpf/jump-gotol-signed-pseudoc.s       | 10 +++++++
 gas/testsuite/gas/bpf/spacing-pseudoc.d       |  2 +-
 5 files changed, 56 insertions(+), 2 deletions(-)
 create mode 100644 gas/testsuite/gas/bpf/jump-gotol-signed-pseudoc.d
 create mode 100644 gas/testsuite/gas/bpf/jump-gotol-signed-pseudoc.s
  

Comments

Vineet Gupta Sept. 3, 2026, 3:39 a.m. UTC | #1
Ping !

On 8/25/26 3:11 AM, Vineet Gupta wrote:
> In the pseudo-C dialect `gotol +1' is silently assembled as `goto l+1'
> leading to libbpf load time failures. LLVM obviously supports this so gas
> needs fixing.
>
> Ran into this when trying to enable certain selftests which are
> currently clang built only while GCC can build them fine. Moreover those
> not run tests are declared passing too [1].
>
> Patch 1: Orthogonal issue discovered in the process. Directed tests for
> exactly this exist: spacing-pseudoc.{s,d} but are never run.
>
> Patch 2 fixes the actual mis-assembly.
>
> As part of v1 review [2] it was suggested to simply use 'W%' to mandate
> at least whitespace i.e. `goto%W%d16'. However that does not work.
> gas strips the whitespace next to a sign in the operand field before
> md_assemble sees the line, so rejects valid insn: `if rX > N goto +M'
> The registered testsuite does not catch either, as it only ever
> writes conditional jumps with label operands. So v2 retains the v1
> approach to reject a template whose literal text stops in the
> middle of a name, letting a later template match the whole mnemonic.
>
> Tested on bpf-unknown-none: 59 expected passes, no failures.
>
> [1] https://lore.kernel.org/bpf/20260821201316.1059129-1-vineet.gupta@linux.dev/
> [2] https://gcc.gnu.org/pipermail/bpf/2026-August/000192.html
>
> Vineet Gupta (2):
>    gas: bpf: actually run the pseudo-C spacing test
>    PR 34558: bpf: don't mis-assemble `gotol' with signed offset
>
>   gas/config/tc-bpf.c                           | 28 ++++++++++++++++++-
>   gas/testsuite/gas/bpf/bpf.exp                 |  3 ++
>   .../gas/bpf/jump-gotol-signed-pseudoc.d       | 15 ++++++++++
>   .../gas/bpf/jump-gotol-signed-pseudoc.s       | 10 +++++++
>   gas/testsuite/gas/bpf/spacing-pseudoc.d       |  2 +-
>   5 files changed, 56 insertions(+), 2 deletions(-)
>   create mode 100644 gas/testsuite/gas/bpf/jump-gotol-signed-pseudoc.d
>   create mode 100644 gas/testsuite/gas/bpf/jump-gotol-signed-pseudoc.s
>