From patchwork Mon Aug 24 21:41:37 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vineet Gupta X-Patchwork-Id: 142120 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 703384BA79A3 for ; Mon, 24 Aug 2026 21:42:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 703384BA79A3 Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=SVYguhf4 X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mta0.migadu.com (out-166.mta0.migadu.com [IPv6:2001:41d0:1004:224b::a6]) by sourceware.org (Postfix) with ESMTPS id A0BEC4BA798D for ; Mon, 24 Aug 2026 21:41:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A0BEC4BA798D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.dev ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A0BEC4BA798D Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2001:41d0:1004:224b::a6 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1787607709; cv=none; b=hflyD4W9dZ0NoGEG5GKhlQcKDhLPt8SvPoxNSBLCfbP+oX1zLEW6zWJ/V3C0uFT2eroIn5XH7kt51kpRJidO1UwQjLX1kamReJ+Uk4z4A2MXoUlZyMWTYVWeWRiwf/jlDmNRdb/C3O/UqQQqA/HTMH+ELdMhTa7cbnsxtEMV0tA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1787607709; c=relaxed/simple; bh=D69S4l9zCc6rLU/PO2G+f/9iQbB7Xcy+XNoHoeaT9oQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=KlL6LxmOHpsqchPpdDNQH0nudTZbOnOX2o9PJ52zleTuA17zgpXQw707aPLFEaVmWkOE9NpmYMov8hitQgHXPfFWrVO1nH/i2EIvnTkmZ5LaLX+tIQ802OyxEB7qPEvHd+2h99k5LHqkA7oztn6WHsNw5Ax/qSEllDCK5KCKyTU= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=SVYguhf4 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A0BEC4BA798D X-Envelope-To: binutils@sourceware.org DKIM-Signature: a=rsa-sha256; bh=D69S4l9zCc6rLU/PO2G+f/9iQbB7Xcy+XNoHoeaT9oQ=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1787607708; v=1; x=1788212508; b=SVYguhf4mtX+u76MVR7PgHQmSmOYoh0la2aUCFBnI/mRlyx6hxy8FD/X3uY2dD1v9nxoHx38 rqmUhRxHsYD99OYsyI0aNg9S8hr4d7YqIqKMOtzntemjEdghCTEv0J6rFcgHrGPoJALdbA8t2iv 6BBJbQgweYHoASMV17fMBKaE= X-Envelope-To: binutils@sourceware.org Received: from gvineet-fedora-PF5JGVFY.thefacebook.com (2620:10d:c090:500::4:2c42) by smtp.migadu.com with ESMTPS id 4af32cc1290901f3; Mon, 24 Aug 2026 21:41:48 +0000 X-Mizu-Trace-ID: 4af32cc1290901f3 X-Migadu-Flow: FLOW_OUT From: Vineet Gupta To: binutils@sourceware.org Cc: bpf@gcc.gnu.org, jose.marchesi@oracle.com, ast@kernel.org, Vineet Gupta Subject: [PATCH v2 1/2] gas: bpf: actually run the pseudo-C spacing test Date: Mon, 24 Aug 2026 14:41:37 -0700 Message-ID: <20260824214138.3964162-2-vineet.gupta@linux.dev> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260824214138.3964162-1-vineet.gupta@linux.dev> References: <20260824214138.3964162-1-vineet.gupta@linux.dev> MIME-Version: 1.0 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_PASS, SPF_PASS, TXREP shortcircuit=no autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org spacing-pseudoc.{s,d} has been present since the pseudo-C dialect tests were added, but bpf.exp never had a run_dump_test entry for it, so it has never been executed. Enabling it exposes a second problem: the .d declares -EB while its expected encodings are little endian, so the test fails on byte order alone. Every other big endian BPF test carries a -be suffix in its name, and this file does not, so -EL is what was meant. With both fixed the test passes, and the flexible spacing it documents -- goto+1, goto1 and the same forms inside a conditional jump -- is covered from now on. gas/ * testsuite/gas/bpf/bpf.exp: Run spacing-pseudoc. * testsuite/gas/bpf/spacing-pseudoc.d: Assemble little endian, to match the expected encodings and the file name. --- gas/testsuite/gas/bpf/bpf.exp | 2 ++ gas/testsuite/gas/bpf/spacing-pseudoc.d | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/gas/testsuite/gas/bpf/bpf.exp b/gas/testsuite/gas/bpf/bpf.exp index f19322122527..74b0461f0bcb 100644 --- a/gas/testsuite/gas/bpf/bpf.exp +++ b/gas/testsuite/gas/bpf/bpf.exp @@ -76,6 +76,8 @@ if {[istarget bpf*-*-*]} { run_dump_test jcond-be run_dump_test jcond-be-pseudoc + run_dump_test spacing-pseudoc + # Overflow tests run_dump_test offset16-overflow run_dump_test disp16-overflow diff --git a/gas/testsuite/gas/bpf/spacing-pseudoc.d b/gas/testsuite/gas/bpf/spacing-pseudoc.d index 16f5763aeb00..48ea4d9a1a92 100644 --- a/gas/testsuite/gas/bpf/spacing-pseudoc.d +++ b/gas/testsuite/gas/bpf/spacing-pseudoc.d @@ -1,4 +1,4 @@ -#as: -EB -mdialect=pseudoc +#as: -EL -mdialect=pseudoc #source: spacing-pseudoc.s #objdump: -dr -M hex,pseudoc #name: spacing, pseudoc syntax From patchwork Mon Aug 24 21:41:38 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vineet Gupta X-Patchwork-Id: 142121 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 02B164BA7996 for ; Mon, 24 Aug 2026 21:44:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 02B164BA7996 Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=PVPSifdX X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mta1.migadu.com (out-20.mta1.migadu.com [IPv6:2001:41d0:203:375::14]) by sourceware.org (Postfix) with ESMTPS id EB8FD4BA798F for ; Mon, 24 Aug 2026 21:41:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EB8FD4BA798F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.dev ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EB8FD4BA798F Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2001:41d0:203:375::14 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1787607715; cv=none; b=dDuIbeeebBEFdA/UAVjprRBgJ2HsabtbkSwyGlOYsB0JhdFLAhxvB79nxsc3/HwbrZf663UsRCmHLFJAAjaHELJptXN5HtpKopA+lNm5yve4spSRzBWm9YxriIvWbsIgMbMdCWvsMK13/aUMrIRTSy6DgYzESpt9YMFeGLBaGCk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1787607715; c=relaxed/simple; bh=RrCQ4MY+UXVi2MOn2OpR8aG3tJ2RW5NAB6h+djAOPBU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Nx/0SdrrXTe81vySbN2kyIhO+as3tefsoMa+Osrnamw8CaE1TQU1LZ1qOVN/h7/QYy1MBc9TzsWVxWqpkANyTfUpJWjZU3z/t8hiYA6gjNkHSkYrHJ7/EQX5WG9ozwd2xdqXbqdEEGMZj6s1TXJs9ikS52llTHjzvkULWrO03lE= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=PVPSifdX DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EB8FD4BA798F X-Envelope-To: binutils@sourceware.org DKIM-Signature: a=rsa-sha256; bh=RrCQ4MY+UXVi2MOn2OpR8aG3tJ2RW5NAB6h+djAOPBU=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1787607713; v=1; x=1788212513; b=PVPSifdXImjM09lNFIqMJjRknOSlUeMei01Brce0mX2juckYIOCULEC/nBN7FdcW4ceFXWf3 J3BtSacmxmQ4ffhZ+MQO8YLq7Rbo0jmUPn+dy1PC4xzGNTbFvpve8Zfa6N/XfheDH6ikL7cTLNR GZECK8oAh4Um8z1kjrGG/xhs= X-Envelope-To: binutils@sourceware.org Received: from gvineet-fedora-PF5JGVFY.thefacebook.com (2620:10d:c090:500::4:2c42) by smtp.migadu.com with ESMTPS id faafb77129c71d21; Mon, 24 Aug 2026 21:41:53 +0000 X-Mizu-Trace-ID: faafb77129c71d21 X-Migadu-Flow: FLOW_OUT From: Vineet Gupta To: binutils@sourceware.org Cc: bpf@gcc.gnu.org, jose.marchesi@oracle.com, ast@kernel.org, Vineet Gupta Subject: [PATCH v2 2/2] PR 34558: bpf: don't mis-assemble `gotol' with signed offset Date: Mon, 24 Aug 2026 14:41:38 -0700 Message-ID: <20260824214138.3964162-3-vineet.gupta@linux.dev> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260824214138.3964162-1-vineet.gupta@linux.dev> References: <20260824214138.3964162-1-vineet.gupta@linux.dev> MIME-Version: 1.0 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_PASS, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org `gotol +1' is assembled as if it were `goto l +1' `gotol +imm' is the canonical form in the BPF instruction set documentation, and it is what LLVM emits and accepts, so it needs to work. The reason is the asm templates for the two unconditional jumps: BPF_INSN_JAR "goto%w%d16" BPF_INSN_JAL "gotol%w%d32" where %w matches zero or more whitespace characters. JAR sorts before JAL in the opcode table so it tries to match first and succeeds as `goto' and `l +1', with `l' being an undefined symbol. This ends up as JA (opcode 0x05, with the displacement in the 16-bit `off' field) plus an R_BPF_GNU_64_16 relocation against an undefined symbol `l', rather than as JAL (opcode 0x06, displacement in the 32-bit `imm' field). No diagnostic is emitted. The signed form -1 is similarly affected. For non-signed forms, `gotol 1' or `gotol 1f', the remainder does not parse as a single expression, the JAR template fails, and JAL is reached and matched correctly. The normal dialect is not affected either, as `ja%W%d16' requires at least one whitespace character after the mnemonic. Simply changing the JAR template to `goto%W%d16' does not work. The pseudo-C dialect deliberately supports flexible spacing, so `goto+1' and `goto1' must keep assembling, and gas removes the whitespace next to a sign in the operand field before md_assemble sees the line, which breaks the extremely common `if rX > N goto +M' outright. Instead reject a template whose literal text stops in the middle of a name: if the character last matched from the template is part of a name and the input continues with a name beginner, then the template has only matched a prefix of a longer mnemonic and does not apply. Other templates are then given a chance to match the whole mnemonic. This also covers the compound conditional jumps, whose templates embed `goto%w%d16'. Testing is_name_beginner rather than is_part_of_name keeps `goto1' working, a digit continuing an operand rather than a mnemonic. Existing coverage exercised `gotol' only with a label operand, which is why this went unnoticed. PR gas/34558 gas/ * config/tc-bpf.c (md_assemble): Do not let a template match when its literal text ends mid-name and the input continues with a name beginner. * testsuite/gas/bpf/jump-gotol-signed-pseudoc.s: New test. * testsuite/gas/bpf/jump-gotol-signed-pseudoc.d: New test. * testsuite/gas/bpf/bpf.exp: Run it. --- gas/config/tc-bpf.c | 28 ++++++++++++++++++- gas/testsuite/gas/bpf/bpf.exp | 1 + .../gas/bpf/jump-gotol-signed-pseudoc.d | 15 ++++++++++ .../gas/bpf/jump-gotol-signed-pseudoc.s | 10 +++++++ 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 gas/testsuite/gas/bpf/jump-gotol-signed-pseudoc.d create mode 100644 gas/testsuite/gas/bpf/jump-gotol-signed-pseudoc.s diff --git a/gas/config/tc-bpf.c b/gas/config/tc-bpf.c index 8d48b128fb90..72e97327e542 100644 --- a/gas/config/tc-bpf.c +++ b/gas/config/tc-bpf.c @@ -1506,7 +1506,33 @@ md_assemble (char *str ATTRIBUTE_UNUSED) } else if (*(p + 1) == 'w') { - /* Expect zero or more spaces. */ + /* Expect zero or more spaces. + + If the template text matched so far ends in a name + character and the input continues with a letter, then + the template only matched a prefix of a longer mnemonic + written in the input, and this template does not apply. + Rejecting it here lets a subsequent template have a go + at the whole mnemonic. + + Without this, `gotol +1' matches the `goto%w%d16' + template, with `l +1' parsed as the branch offset + expression, silently assembling to JA (opcode 0x05) plus + a relocation against an undefined symbol `l' instead of + to JAL (opcode 0x06). + + is_name_beginner rather than is_part_of_name: a digit + continues an operand rather than a mnemonic, and the + pseudo-C dialect accepts it with no separating space, as + in `goto1'. */ + if (!is_whitespace (*s) + && p > template + && is_part_of_name (*(p - 1)) + && is_name_beginner (*s)) + { + PARSE_ERROR ("expected white space, got '%s'", s); + break; + } while (is_whitespace (*s)) s += 1; p += 2; diff --git a/gas/testsuite/gas/bpf/bpf.exp b/gas/testsuite/gas/bpf/bpf.exp index 74b0461f0bcb..bcedb0c98f7b 100644 --- a/gas/testsuite/gas/bpf/bpf.exp +++ b/gas/testsuite/gas/bpf/bpf.exp @@ -38,6 +38,7 @@ if {[istarget bpf*-*-*]} { run_dump_test jump-pseudoc run_dump_test jump32 run_dump_test jump32-pseudoc + run_dump_test jump-gotol-signed-pseudoc run_dump_test atomic-v1 run_dump_test atomic run_dump_test atomic-pseudoc diff --git a/gas/testsuite/gas/bpf/jump-gotol-signed-pseudoc.d b/gas/testsuite/gas/bpf/jump-gotol-signed-pseudoc.d new file mode 100644 index 000000000000..ee4146acd996 --- /dev/null +++ b/gas/testsuite/gas/bpf/jump-gotol-signed-pseudoc.d @@ -0,0 +1,15 @@ +#as: -EL -mdialect=pseudoc +#objdump: -dr -M dec,pseudoc +#source: jump-gotol-signed-pseudoc.s +#name: eBPF gotol with signed offsets, pseudoc syntax + +.*: +file format .*bpf.* + +Disassembly of section .text: + +0+ <.text>: + 0: 06 00 00 00 01 00 00 00 gotol 1 + 8: 06 00 00 00 ff ff ff ff gotol -1 + 10: 06 00 00 00 01 00 00 00 gotol 1 + 18: 06 00 00 00 00 00 00 00 gotol 0 + 20: 06 00 00 00 00 00 00 00 gotol 0 diff --git a/gas/testsuite/gas/bpf/jump-gotol-signed-pseudoc.s b/gas/testsuite/gas/bpf/jump-gotol-signed-pseudoc.s new file mode 100644 index 000000000000..295afd6313d5 --- /dev/null +++ b/gas/testsuite/gas/bpf/jump-gotol-signed-pseudoc.s @@ -0,0 +1,10 @@ + # Signed branch offsets for the pseudo-C `gotol'. PR gas/34558: + # these used to match the shorter `goto' template, with the + # trailing `l' parsed as the start of the offset expression. + .text + gotol +1 + gotol -1 + gotol 1 + gotol 1f +1: + gotol 0