Skip to content

fix(gc): parse GNU-as symbol assignments in the stack-map block - #7390

Merged
proggeramlug merged 2 commits into
mainfrom
fix/gcmap-elf-symbol-assignment
Aug 4, 2026
Merged

fix(gc): parse GNU-as symbol assignments in the stack-map block#7390
proggeramlug merged 2 commits into
mainfrom
fix/gcmap-elf-symbol-assignment

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Fixes the red native-roots-rs4gc (ubuntu-24.04-arm, aarch64, ELF) arm. Statepoints are on by default for aarch64, and aarch64-Linux is inside the allowed set — so this was a hard compile failure on a default-on path, not just a CI annoyance.

The bug

gc_map's parser walks the stack-map block directive by directive, because the block is a byte stream decoded by structural offset: one unmodelled directive that does emit bytes shifts everything after it. So anything unrecognised is a hard error rather than a skip — the right default, and why this surfaced as a refusal instead of a corrupt decode.

What it did not model is the GNU-as symbol assignmentsym = expr, the bare spelling of .set. Zero bytes, no leading directive, so the dispatch reported the symbol as the mnemonic:

line 5114: unrecognised directive `perry_class_keys__…__AnonShape_…`
           inside the stack-map block

Only -O3 emits it — the optimiser materialises absolute-symbol aliases like perry_null_guard_zero = 0 and .Lperry_ic_8 = .Ltmp3-4 — and only on ELF. Mach-O's asm printer doesn't use this spelling, which is why every macOS arm stayed green.

The guard tests for "not a directive this module already models" rather than "no leading dot": ELF local labels start with .L and appear on the left of exactly these assignments. Expression operators (==, !=, >=, <=) are excluded so an .if is never mistaken for one.

Reproduced locally, without a Linux host

My first instinct was to defer this as unverifiable from macOS. That was wrong — the parser is a pure function over assembly text, so what I needed was ELF text, not an ELF machine:

  1. --trace llvm on the failing probe
  2. retarget the module to aarch64-unknown-linux-gnu, drop the Mach-O-only .no_dead_strip module asm
  3. opt -passes=rewrite-statepoints-for-gc → 109 statepoints
  4. llc -mattr=+jsconv,+v8.3a (generic ARMv8.0 can't select fjcvtzs)

The real assembly then parses at -O2 and refuses at -O3 exactly as CI reported — and parses at both with the fix.

Verification

before after
real ELF asm -O2 OK (6400 B) OK (6400 B)
real ELF asm -O3 refused OK (6656 B)
gc_map suite 15 pass 17 pass

Both new tests fail with the guard disabled — checked, not assumed.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed stack-map processing for optimized AArch64 ELF builds containing GNU assembler symbol assignments.
    • Prevented valid zero-byte symbol assignments from causing parsing failures while preserving correct handling of comparisons and supported directives.
    • Improved AArch64 assembly compatibility by applying the compiler’s CPU, architecture, and tuning settings during assembly, including configurations using SVE features.
  • Tests

    • Added coverage for symbol assignments, expression operators, and matching compilation and assembly settings.

proggeramlug pushed a commit that referenced this pull request Aug 4, 2026
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The stack-map parser now accepts valid GNU-as symbol assignments as zero-byte content. The assembly step receives the compiler’s CPU-selection flags. Tests cover parser exclusions and assembler argument filtering. The changelog documents the AArch64 ELF failures and fixes.

Changes

AArch64 ELF stack-map and assembler fixes

Layer / File(s) Summary
Assignment parsing and validation
crates/perry-codegen/src/gc_map.rs, changelog.d/7390-gcmap-elf-symbol-assignment.md
The parser recognizes valid GNU-as symbol assignments as zero-byte content and excludes comparisons, directives, and other expressions. Tests and changelog entries document the behavior.
Assembler CPU argument propagation
crates/perry-codegen/src/gc_map.rs, crates/perry-codegen/src/linker.rs, changelog.d/7390-gcmap-elf-symbol-assignment.md
compact_and_assemble receives compiler arguments from both linker paths and forwards only -mcpu=, -march=, and -mtune= flags to Clang. Tests verify the filtering.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • PerryTS/perry#7314: Both changes modify the gc_map.rs stack-map assembler/parser pipeline.
  • PerryTS/perry#7331: Both changes modify stack-map parsing and compaction in gc_map.rs.
  • PerryTS/perry#7344: The related AArch64 ELF CI coverage exercises the assembly cases fixed here.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: parsing GNU-as symbol assignments in the stack-map block.
Description check ✅ Passed The description explains the bug, implementation, affected platform, reproduction steps, and verification results, though it omits some template sections.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/gcmap-elf-symbol-assignment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

The compact stack-map rewrite refused every module on aarch64-ELF at -O3,
so native-roots-rs4gc (ubuntu-24.04-arm) could never pass and statepoints
-- on by default for aarch64 -- could not compile on Linux arm64.

gc_map's parser walks the block directive by directive because it is a
byte stream decoded by structural offset: one unmodelled directive that
emits bytes shifts everything after it. Refusing the unknown is right,
and it is why this surfaced as a refusal rather than a corrupt decode.

What it did not model is the GNU-as symbol assignment `sym = expr` -- the
bare spelling of `.set`, zero bytes, no leading directive -- so the
dispatch reported the SYMBOL as an unrecognised directive. Only -O3 emits
it (absolute-symbol aliases like `perry_null_guard_zero = 0` and
`.Lperry_ic_8 = .Ltmp3-4`) and only on ELF, so every macOS arm stayed
green.

The guard tests for "not a directive this module already models" rather
than "no leading dot": ELF local labels start with `.L` and appear on the
left of these assignments. Expression operators are excluded so an `.if`
is never mistaken for one.

Reproduced without a Linux host by retargeting a traced module to
aarch64-unknown-linux-gnu, running rewrite-statepoints-for-gc, and
emitting with `llc -O3 -mattr=+jsconv,+v8.3a`: the real assembly parses
at -O2, refuses at -O3 exactly as CI reported, and parses at both with
the fix. Both regression tests fail with the guard disabled.
@proggeramlug
proggeramlug force-pushed the fix/gcmap-elf-symbol-assignment branch from 19e7564 to 7a28460 Compare August 4, 2026 18:14

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/perry-codegen/src/gc_map.rs`:
- Around line 166-196: Exclude the exact symbol name "." in is_symbol_assignment
so ". = . + 4" is not treated as a zero-byte assignment and remains available
for proper width accounting. Preserve existing handling for other symbol
assignments; only add explicit width modeling and a regression case if
supporting this spelling is required.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 856dea56-51e6-41fb-aeae-d3a1eaeff924

📥 Commits

Reviewing files that changed from the base of the PR and between e1762d8 and 7a28460.

📒 Files selected for processing (2)
  • changelog.d/7390-gcmap-elf-symbol-assignment.md
  • crates/perry-codegen/src/gc_map.rs

Comment on lines +166 to +196
/// Is this a GNU-as symbol assignment (`sym = expr`) rather than a directive?
///
/// Assemblers accept `.set sym, expr` and the bare `sym = expr` for the same
/// thing. Only the former starts with a `.`, so the directive dispatch sees the
/// SYMBOL as the mnemonic and refuses it. Both emit zero bytes.
///
/// Deliberately narrow: the name must be a single token that is not itself a
/// directive, and the `=` must not be part of a comparison inside a longer
/// expression. `.size sym, .-sym` and `.byte 1` are unaffected.
fn is_symbol_assignment(line: &str) -> bool {
let Some((lhs, _rhs)) = line.split_once('=') else {
return false;
};
// `==`, `>=`, `<=`, `!=` are expression operators, not an assignment.
if lhs.ends_with(['=', '>', '<', '!']) {
return false;
}
let name = lhs.trim();
// ELF local labels start with `.L`, so "does not start with a dot" is the
// wrong test -- it would reject `.Lperry_ic_8 = …`, which -O3 emits. Test
// what actually matters instead: the LHS must not be a directive this
// module already models. Anything else that is a single bare token before
// an `=` is a symbol assignment.
!name.is_empty()
&& !name.contains(char::is_whitespace)
&& directive_width(name, 8).is_none()
&& !is_zero_width_directive(name)
&& name
.chars()
.all(|c| c.is_alphanumeric() || c == '_' || c == '$' || c == '.')
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

rg -n 'name != "\."' crates/perry-codegen/src/gc_map.rs
rg -n '\. = \. \+ 4' crates/perry-codegen/src/gc_map.rs
cargo check -p perry --profile perry-dev

Repository: PerryTS/perry

Length of output: 151


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

echo "files matching gc_map:"
fd -a 'gc_map\.rs$' . || true

echo "relevant sections:"
if [ -f crates/perry-codegen/src/gc_map.rs ]; then
  wc -l crates/perry-codegen/src/gc_map.rs
  sed -n '130,220p' crates/perry-codegen/src/gc_map.rs
  sed -n '250,310p' crates/perry-codegen/src/gc_map.rs
  rg -n 'directive_width|is_zero_width_directive|is_symbol_assignment|RawBlock::bytes' crates/perry-codegen/src/gc_map.rs
fi

Repository: PerryTS/perry

Length of output: 7390


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

echo "behavior probe for is_symbol_assignment conditions:"
python3 - <<'PY'
def is_symbol_assignment(line: str) -> bool:
    if '=' not in line:
        return False
    lhs, _rhs = line.split('=', 1)
    if lhs.endswith(['=', '>', '<', '!']):
        return False
    name = lhs.strip()
    return bool(
        name
        and not any(c.isspace() for c in name)
        and name != "."
        and all(c.isalnum() or c in '_$. ' for c in name)
    )
for line in [". = . + 4", ". =.+4", "sym = 42", "perry_null_guard_zero = 0"]:
    stripped = line.strip()
    lhs = stripped.split("=", 1)[0].strip()
    print(stripped, "lhs=", repr(lhs), "matches=", "dot assignment" if lhs == "." else str(is_symbol_assignment(stripped)))
PY

echo "around line 1377-1395:"
sed -n '1360,1405p' crates/perry-codegen/src/gc_map.rs

echo "targeted searches:"
rg -n '"\."\s*(\+|-|=)|\s*=.*\s*\.|local labels|Elf|ELF|location counter' crates/perry-codegen/src/gc_map.rs

echo "cargo check:"
cargo check -p perry --profile perry-dev

Repository: PerryTS/perry

Length of output: 480


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

echo "behavior probe for dot assignment:"
python3 - <<'PY'
lines = [". = . + 4", ". =.+4", "sym = 42"]
for line in lines:
    if '=' not in line:
        print(line, "no equals")
        continue
    lhs, _ = line.split("=", 1)
    if lhs.strip() == ".":
        print(line, "matches dot assignment guard")
PY

echo "around line 1377-1395:"
sed -n '1360,1405p' crates/perry-codegen/src/gc_map.rs

echo "cargo check:"
cargo check -p perry --profile perry-dev

Repository: PerryTS/perry

Length of output: 2076


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

echo "cargo check:"
cargo "+nightly" check -p perry --profile perry-dev || true

echo "current diff/stat around modified file (if available):"
git diff --stat crates/perry-codegen/src/gc_map.rs || true

Repository: PerryTS/perry

Length of output: 143


Do not treat . as a zero-byte symbol assignment.

name == "." passes is_symbol_assignment, so . = . + 4 is skipped before byte-width accounting. GNU as treats assignment to . like .org, so this emits four bytes. Skipping it removes emitted padding and can shift later stack-map offsets.

Exclude . from is_symbol_assignment. If this spelling must be supported, model the width instead of skipping it, and add a . = . + 4 regression case.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/perry-codegen/src/gc_map.rs` around lines 166 - 196, Exclude the exact
symbol name "." in is_symbol_assignment so ". = . + 4" is not treated as a
zero-byte assignment and remains available for proper width accounting. Preserve
existing handling for other symbol assignments; only add explicit width modeling
and a regression case if supporting this spelling is required.

Source: Coding guidelines

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@changelog.d/7390-gcmap-elf-symbol-assignment.md`:
- Around line 1-3: The opening sentence in the changelog entry is ungrammatical
as written—it incorrectly combines "Fixed" with "refused" creating a broken
clause structure. Rewrite the sentence to be grammatically correct by clearly
stating that the compact stack-map rewrite had an issue, while preserving the
specific details about the aarch64-ELF rejection at -O3, the native-roots-rs4gc
test failure, and the statepoint compilation problem on Linux arm64.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 14473598-4c0d-4aa5-b94c-7673fe8e0cdf

📥 Commits

Reviewing files that changed from the base of the PR and between e1762d8 and 7a28460.

📒 Files selected for processing (2)
  • changelog.d/7390-gcmap-elf-symbol-assignment.md
  • crates/perry-codegen/src/gc_map.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/perry-codegen/src/gc_map.rs

Comment on lines +1 to +3
**Fixed** the compact stack-map rewrite refused every module on aarch64-ELF at
`-O3`, so `native-roots-rs4gc (ubuntu-24.04-arm)` could never pass and statepoints
— on by default for aarch64 — could not compile on Linux arm64.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Fix the opening sentence.

The sentence is not grammatical. State that the rewrite had an issue.

Proposed fix
-**Fixed** the compact stack-map rewrite refused every module on aarch64-ELF at
-`-O3`, so `native-roots-rs4gc (ubuntu-24.04-arm)` could never pass and statepoints
+**Fixed** an issue where the compact stack-map rewrite refused every module on
+aarch64-ELF at `-O3`, so `native-roots-rs4gc (ubuntu-24.04-arm)` could never pass and statepoints
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
**Fixed** the compact stack-map rewrite refused every module on aarch64-ELF at
`-O3`, so `native-roots-rs4gc (ubuntu-24.04-arm)` could never pass and statepoints
— on by default for aarch64 — could not compile on Linux arm64.
**Fixed** an issue where the compact stack-map rewrite refused every module on
aarch64-ELF at `-O3`, so `native-roots-rs4gc (ubuntu-24.04-arm)` could never pass and statepoints
— on by default for aarch64 — could not compile on Linux arm64.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@changelog.d/7390-gcmap-elf-symbol-assignment.md` around lines 1 - 3, The
opening sentence in the changelog entry is ungrammatical as written—it
incorrectly combines "Fixed" with "refused" creating a broken clause structure.
Rewrite the sentence to be grammatically correct by clearly stating that the
compact stack-map rewrite had an issue, while preserving the specific details
about the aarch64-ELF rejection at -O3, the native-roots-rs4gc test failure, and
the statepoint compilation problem on Linux arm64.

Second aarch64-linux failure, surfaced once the symbol-assignment parse
was fixed:

    error: instruction requires: sve or sme
            mov     z1.d, #0x7fffffffffffffff

Perry compiles with `-mcpu=native`. On a host whose CPU has SVE --
Graviton, and any aarch64 server part -- LLVM emits SVE instructions.
`compact_and_assemble` then handed that text to clang with no `-mcpu` at
all, so the assembler applied the portable baseline and rejected what the
generator had just produced.

The two invocations describe the same machine and now say so: the codegen
argv's -mcpu=/-march=/-mtune= flags are forwarded to the assembler.
Optimisation and output flags deliberately are not -- they mean nothing
to an assembler, and forwarding wholesale would be a second way for the
two to disagree.

Invisible on the macOS arms, whose runner CPUs have no SVE.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@changelog.d/7390-gcmap-elf-symbol-assignment.md`:
- Around line 34-35: Revise the changelog sentence beginning “Also fixed the
assembler…” so it explicitly states that the assembler CPU mismatch issue was
fixed, while preserving the existing details about the code generator CPU and
aarch64-linux failure.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 767f2a67-71e5-4e34-9058-a182c19dcd15

📥 Commits

Reviewing files that changed from the base of the PR and between 7a28460 and e671c81.

📒 Files selected for processing (3)
  • changelog.d/7390-gcmap-elf-symbol-assignment.md
  • crates/perry-codegen/src/gc_map.rs
  • crates/perry-codegen/src/linker.rs

Comment on lines +34 to +35
**Also fixed** the assembler was invoked without the CPU the code generator was
given, so aarch64-linux failed a second time once the parse was fixed:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Fix the sentence structure.

Also fixed the assembler was invoked... is not grammatical. State that an issue was fixed.

Proposed wording
-**Also fixed** the assembler was invoked without the CPU the code generator was
-given, so aarch64-linux failed a second time once the parse fix was fixed:
+**Also fixed an issue where** the assembler was invoked without the CPU the
+code generator was given, so aarch64-linux failed a second time after the parse fix:
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@changelog.d/7390-gcmap-elf-symbol-assignment.md` around lines 34 - 35, Revise
the changelog sentence beginning “Also fixed the assembler…” so it explicitly
states that the assembler CPU mismatch issue was fixed, while preserving the
existing details about the code generator CPU and aarch64-linux failure.

@proggeramlug
proggeramlug merged commit 7797198 into main Aug 4, 2026
7 of 15 checks passed
@proggeramlug
proggeramlug deleted the fix/gcmap-elf-symbol-assignment branch August 4, 2026 18:51
proggeramlug added a commit that referenced this pull request Aug 4, 2026
* docs(plan): fold in the 2026-08-04 findings

Two things this plan treated as measured were not.

Statepoints could not compile on aarch64-ELF at all -- a hard failure on
a default-on path, from two stacked bugs (#7390: the compact stack-map
parser did not model GNU-as `sym = expr`, emitted only at -O3 and only on
ELF; and the assembler was not told the -mcpu the code generator was
told, so Graviton-emitted SVE was rejected) behind two toolchain ones
(#7384, #7388).

And three of the four RS4GC matrix arms had NEVER executed, in any run,
for want of a concurrency group (#7393). Every "the ELF arm is the only
one red" conclusion rested on arms that never reached a runner. That is a
fifth way a gate cannot fail, and it is now written down.

Also folded in: nine Layer 3 rooting fixes and the rule they share
(ordering, not missing roots; a fault that MOVES is a real fix, one that
does not move by a byte was already dead before you rooted it); #7380's
type confusion and the `gc_type == GC_TYPE_OBJECT` generalisation; RSS
-69% (#7377); and the first honest performance measurement -- two
benchmarks that measure nothing (#7395) and the array-store guard's
siting cost (#7396).

The Layer 1 framing is corrected: lower_exprs_rooted already implements
the RFC's proposal for codegen operands, gated on
any_later_ref_may_trigger_gc, and all four arms of func_ref.rs use it. So
the gap is Layer 3, where #7389 supplies the first structural answer.

* docs: name the fragment for its real PR (#7397)

---------

Co-authored-by: Ralph Küpper <ralph@skelpo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant