Skip to content

harm: Applying relocations#52

Open
monoid wants to merge 23 commits intomasterfrom
feat/relocations
Open

harm: Applying relocations#52
monoid wants to merge 23 commits intomasterfrom
feat/relocations

Conversation

@monoid
Copy link
Copy Markdown
Owner

@monoid monoid commented Mar 8, 2026

Implement applying relocation to a program memory.

It separates current memory location and the final memory location for better flexibility. For example, to produce static binary files allocating memory at arbitrary position.

Ref #31.

Summary by CodeRabbit

  • Refactor
    • Renamed relocation identifiers to snake_case, redesigned relocation representation into a tag+label model, added many relocation APIs for control, address, data and MOV encodings, and introduced stronger validation with a typed relocation error and bit-patching helpers.
    • Added a public scaled-offset type for 128-bit loads.
  • Tests
    • Added extensive unit and integration tests covering relocation kinds, encoding/decoding, alignment/overflow, error handling, and updated expectations for renamed identifiers.

monoid added 8 commits March 1, 2026 12:35
Separate relocation tag from label, introducing `Rel64Tag` bare enum,
and `Rel64` struct.  Applying relocation requires real offsets, not
labels.
@monoid monoid self-assigned this Mar 8, 2026
@monoid monoid added enhancement New feature or request runtime The `harm`'s runtime: memory mappings, applying relocations, etc. labels Mar 8, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 8, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Replaces enum-style Rel64 with a tagged struct and Rel64Tag, renames many relocation constructors to snake_case, centralizes relocation application via Rel64Tag::apply, adds relocator modules (addr, control, data, movs), updates instruction emitters/tests to new constructors, and adds extensive relocation unit tests. (43 words)

Changes

Cohort / File(s) Summary
Core relocation engine
harm/src/reloc.rs
Replaces pub enum Rel64 with pub struct Rel64 { rel: Rel64Tag, label: LabelRef }; adds Rel64Tag, Rel64Error, Rel64::new, many snake_case constructor helpers, Rel64Tag::apply, helpers (get_bytes_mut, calc_delta, calc_page_offset, patch_instruction_bits) and expanded unit tests.
New relocation backends
harm/src/reloc/addr.rs, harm/src/reloc/control.rs, harm/src/reloc/data.rs, harm/src/reloc/movs.rs
Adds per-instruction relocation patchers for ADR/ADRP/LO12, control branches (jump26/call26/tst_br14/cond_br19), data abs/prel/plt, and MOVW/MOVZ/MOVN relocations; all expose pub fn ... -> Result<(), Rel64Error>.
Instruction emitters & tests
harm/src/instructions/.../branch_imm.rs, harm/src/instructions/.../testbranch.rs, harm/src/instructions/dpimm/movewide/movewide_reloc.rs, harm/src/instructions/ldst/ldr.rs, harm/src/instructions/ldst/ldrsw.rs, harm/src/instructions/control/testbranch.rs
Updated relocation constructor usages and tests to snake_case variants (e.g., Jump26 → jump26, CondBr19 → cond_br19, TstBr14 → tst_br14, LdPrelLo19 → ld_prel_lo19, movw variants) across emitters and assertions.
Relocation integration tests
harm/src/reloc/claude_tests.rs
Adds an extensive test module validating byte helpers, error variants, many relocation kinds, encoding edge cases, checked vs non-checked semantics, and dispatcher routing.
Load/Store helpers
harm/src/instructions/ldst.rs
Adds pub type ScaledOffset128 = UBitValue<12, 4> to support 128-bit scaled immediates.
Small tweaks
harm/src/instructions/control/branch_imm.rs, harm/src/instructions/control/testbranch.rs (individual files)
Renamed several Rel64 variant usages to snake_case in reloc-returning code paths and tests (e.g., TstBr14 → tst_br14).

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Caller as Rel64 (caller)
    participant Tag as Rel64Tag
    participant Reloc as Reloc Module (addr/control/data/movs)
    participant Mem as Memory (byte slice)
    participant Instr as Instruction (u32)

    Caller->>Tag: Tag::apply(base, value/target, mem, offset)
    Tag->>Reloc: dispatch to specific *_reloc(base, value, mem, offset)
    Reloc->>Mem: get_bytes_mut(offset)
    Reloc->>Instr: read instruction word
    Reloc->>Instr: compute delta/immediate and patch bits
    Reloc->>Mem: write patched bytes
    Reloc-->>Tag: Result<(), Rel64Error>
    Tag-->>Caller: propagate Result
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • harm: some relocations #47: Overlapping relocation-system refactor and variant renames; touches reloc.rs and many relocation call sites.
  • harm: ADR/ADRP #43: Introduces ADR/ADRP addressing/offset types used by the new ADR/ADRP relocation helpers.

Poem

🐰 I hop through bytes and tag each spot,

snake_case footprints where the enums are not,
I nudge imm bits, nibble overflows with glee,
stash tests like carrots for the devs to see,
and twitch my whiskers when relocations agree.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: implementing the application of relocations to program memory, which is the core objective of this PR.
Docstring Coverage ✅ Passed Docstring coverage is 96.22% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 feat/relocations

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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
harm/src/reloc/movs.rs (1)

19-178: Consider a shared helper for MOV field patching.

The unpack/mask/write sequence is duplicated across every MOV relocator here. Pulling that into a small helper that accepts the imm16 chunk plus optional opcode override would make later fixes much less likely to drift between variants.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@harm/src/reloc/movs.rs` around lines 19 - 178, The MOV relocators
(mov_w_abs_g0_reloc, mov_w_abs_g0nc_reloc, mov_w_abs_g0s_reloc,
mov_w_abs_g1_reloc, mov_w_abs_g1nc_reloc, mov_w_abs_g1s_reloc,
mov_w_abs_g2_reloc, mov_w_abs_g2nc_reloc, mov_w_abs_g2s_reloc,
mov_w_abs_g3_reloc) all duplicate the unpack/mask/write sequence using
InstructionCode and MOV_IMM16_OFFSET/ MOV_OPCODE_OFFSET; extract that into a
small helper (e.g., patch_mov_instruction(bytes: &mut [u8], imm16: u16, opcode:
Option<u32>)) that computes INST_MASK, unpacks InstructionCode, clears the
imm/opcode bits, ORs in (imm16 as u32) << MOV_IMM16_OFFSET and, when
opcode.is_some(), ORs opcode << MOV_OPCODE_OFFSET, then writes back
InstructionCode::from_u32(...).0; update each relocator to compute its
imm16/opcode (use MOV_OPCODE_MOVN or MOV_OPCODE_MOVZ where appropriate in mov_*s
variants) and call the helper to remove the repeated logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@harm/src/reloc.rs`:
- Around line 262-264: The ABS16/ABS32 cases currently pre-cast Addr to signed
via Addr::cast_signed in the Rel64Tag match, which causes valid unsigned bit
patterns (e.g. 0xffff_ffff or 0xffff) to be rejected; change the Rel64Tag::Abs32
and Rel64Tag::Abs16 arms to pass the original unsigned Addr value into
abs32_reloc and abs16_reloc (i.e., remove the cast_signed usage) so the overflow
checks in harm/src/reloc/data.rs operate on the original unsigned value; keep
Rel64Tag::Abs64 using abs64_reloc as-is.

In `@harm/src/reloc/addr.rs`:
- Around line 82-98: The add_abs_lo_12_nc_reloc function currently computes
delta using calc_offset(base, symbol, offset) which makes the low-12 relocation
depend on P; instead encode the absolute low 12 bits of symbol (symbol & 0xfff).
Replace the calc_offset-based delta with a value derived from symbol: compute
low12 = (symbol as u64) & MASK (cast to u32 when applying) and use that to set
the ADD_IMM12 field (keep the existing masking and shifting logic with
ADD_IMM12_OFFSET and MASK). Keep get_bytes_mut, InstructionCode unpack/pack
usage unchanged and preserve error handling/return type.

In `@harm/src/reloc/claude_tests.rs`:
- Around line 595-613: The tests adrp_overflow_positive and
adrp_overflow_negative assert
Err(Rel64Error::InvalidBits(BitError::Unsupported)) but the comment states the
correct outcome should be an overflow; update these tests to stop codifying the
wrong behavior by either asserting
Err(Rel64Error::InvalidBits(BitError::Overflow)) for both tests or loosening the
match to assert Err(Rel64Error::InvalidBits(_)) so the suite no longer freezes
the current bug in adrp_prel_pg_hi21_reloc and allows proper overflow handling
to be implemented.

---

Nitpick comments:
In `@harm/src/reloc/movs.rs`:
- Around line 19-178: The MOV relocators (mov_w_abs_g0_reloc,
mov_w_abs_g0nc_reloc, mov_w_abs_g0s_reloc, mov_w_abs_g1_reloc,
mov_w_abs_g1nc_reloc, mov_w_abs_g1s_reloc, mov_w_abs_g2_reloc,
mov_w_abs_g2nc_reloc, mov_w_abs_g2s_reloc, mov_w_abs_g3_reloc) all duplicate the
unpack/mask/write sequence using InstructionCode and MOV_IMM16_OFFSET/
MOV_OPCODE_OFFSET; extract that into a small helper (e.g.,
patch_mov_instruction(bytes: &mut [u8], imm16: u16, opcode: Option<u32>)) that
computes INST_MASK, unpacks InstructionCode, clears the imm/opcode bits, ORs in
(imm16 as u32) << MOV_IMM16_OFFSET and, when opcode.is_some(), ORs opcode <<
MOV_OPCODE_OFFSET, then writes back InstructionCode::from_u32(...).0; update
each relocator to compute its imm16/opcode (use MOV_OPCODE_MOVN or
MOV_OPCODE_MOVZ where appropriate in mov_*s variants) and call the helper to
remove the repeated logic.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4fd0deca-f57e-4c6b-9088-3641ca95ef69

📥 Commits

Reviewing files that changed from the base of the PR and between 42f1e29 and 96013ee.

📒 Files selected for processing (11)
  • harm/src/instructions/control/branch_imm.rs
  • harm/src/instructions/control/testbranch.rs
  • harm/src/instructions/dpimm/movewide/movewide_reloc.rs
  • harm/src/instructions/ldst/ldr.rs
  • harm/src/instructions/ldst/ldrsw.rs
  • harm/src/reloc.rs
  • harm/src/reloc/addr.rs
  • harm/src/reloc/claude_tests.rs
  • harm/src/reloc/control.rs
  • harm/src/reloc/data.rs
  • harm/src/reloc/movs.rs

The relocation uses "S+A", not "S+A-P".
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
harm/src/reloc.rs (1)

262-264: ⚠️ Potential issue | 🔴 Critical

Keep ABS16/ABS32 on the original unsigned value.

These arms still reinterpret Addr as signed before narrowing, so valid unsigned bit patterns like 0xffff_ffff for Abs32 and 0xffff for Abs16 are rejected before harm/src/reloc/data.rs can do the proper width check. Pass the original value through unchanged here.

Suggested fix
-            Rel64Tag::Abs32 => abs32_reloc(value.cast_signed(), memory, offset),
-            Rel64Tag::Abs16 => abs16_reloc(value.cast_signed(), memory, offset),
+            Rel64Tag::Abs32 => abs32_reloc(value, memory, offset),
+            Rel64Tag::Abs16 => abs16_reloc(value, memory, offset),
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@harm/src/reloc.rs` around lines 262 - 264, The Abs32 and Abs16 arms are
incorrectly calling value.cast_signed() before narrowing which rejects valid
unsigned patterns; change the Rel64Tag::Abs32 and Rel64Tag::Abs16 match arms to
pass the original value (without cast_signed()) into abs32_reloc and abs16_reloc
respectively so the unsigned bit patterns are preserved; leave Rel64Tag::Abs64
and abs64_reloc unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@harm/src/reloc.rs`:
- Around line 262-264: The Abs32 and Abs16 arms are incorrectly calling
value.cast_signed() before narrowing which rejects valid unsigned patterns;
change the Rel64Tag::Abs32 and Rel64Tag::Abs16 match arms to pass the original
value (without cast_signed()) into abs32_reloc and abs16_reloc respectively so
the unsigned bit patterns are preserved; leave Rel64Tag::Abs64 and abs64_reloc
unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4a740d91-43dc-4177-85b8-ccd80475424c

📥 Commits

Reviewing files that changed from the base of the PR and between 96013ee and fe1a029.

📒 Files selected for processing (3)
  • harm/src/reloc.rs
  • harm/src/reloc/addr.rs
  • harm/src/reloc/claude_tests.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • harm/src/reloc/claude_tests.rs

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
harm/src/reloc.rs (1)

411-417: Address the TODO comment about PRel64 test correctness.

The comment on line 412 questions whether the test expectation is correct. Since PRel64 computes value - (base + offset), the test with base=0x1000, value=0x123456789abcdef0, offset=0 should produce 0x123456789abcdef0 - 0x1000 which matches the assertion. Consider removing the TODO if verified, or fixing if incorrect.

Would you like me to help verify this test expectation or open an issue to track it?

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@harm/src/reloc.rs` around lines 411 - 417, The TODO questioning the PRel64
test expectation should be resolved: confirm that PRel64 computes value - (base
+ offset) and therefore with base=0x1000, value=0x123456789abcdef0 and offset=0
the expected result is value - 0x1000, so remove the TODO and replace it with a
short explanatory comment referencing the PRel64 semantics and the assertion
that compares mem to 0x123456789abcdef0u64.wrapping_sub(0x1000). If you want
stronger verification, add a brief comment above the assert or a second case
verifying non-zero offset behavior (referencing mem and the existing assert)
rather than leaving the TODO.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@harm/src/reloc.rs`:
- Around line 411-417: The TODO questioning the PRel64 test expectation should
be resolved: confirm that PRel64 computes value - (base + offset) and therefore
with base=0x1000, value=0x123456789abcdef0 and offset=0 the expected result is
value - 0x1000, so remove the TODO and replace it with a short explanatory
comment referencing the PRel64 semantics and the assertion that compares mem to
0x123456789abcdef0u64.wrapping_sub(0x1000). If you want stronger verification,
add a brief comment above the assert or a second case verifying non-zero offset
behavior (referencing mem and the existing assert) rather than leaving the TODO.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0d56074f-3205-40be-8137-4f896f7f294f

📥 Commits

Reviewing files that changed from the base of the PR and between fe1a029 and 0cbe6da.

📒 Files selected for processing (4)
  • harm/src/instructions/ldst.rs
  • harm/src/reloc.rs
  • harm/src/reloc/addr.rs
  • harm/src/reloc/claude_tests.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • harm/src/reloc/claude_tests.rs

@monoid monoid force-pushed the feat/relocations branch 2 times, most recently from edee315 to fdd5502 Compare March 15, 2026 09:57
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
harm/src/reloc.rs (1)

76-94: Consider making these constructors const fn for consistency.

The address-related constructors (adr_prel_lo21, adr_prel_pg_hi21, etc.) use regular fn while similar branch/mov constructors use const fn. Since they all just create struct instances, making them all const fn would be consistent and enable compile-time construction.

♻️ Example fix for one function
     #[inline]
-    pub fn adr_prel_lo21(label: LabelRef) -> Self {
+    pub const fn adr_prel_lo21(label: LabelRef) -> Self {
         Self::new(Rel64Tag::AdrPrelLo21, label)
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@harm/src/reloc.rs` around lines 76 - 94, The four address-related
constructors (adr_prel_lo21, adr_prel_pg_hi21, adr_prel_pg_hi21nc,
add_abs_lo12nc) should be changed to const fn to match other constructors;
update each signature from `pub fn` to `pub const fn` and ensure they still call
`Self::new(Rel64Tag::..., label)` so the constructors remain usable in const
contexts while referring to the same Rel64Tag variants (AdrPrelLo21,
AdrPrelPgHi21, AdrPrelPgHi21Nc, AddAbsLo12Nc).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@harm/src/reloc.rs`:
- Around line 6-22: CI found rustfmt formatting issues in the module-level
documentation at the top of reloc.rs; run `cargo fmt` to automatically fix
formatting and ensure the block comment uses a valid Rust doc delimiter (replace
the non-standard "/**!" opener with a proper "/*!" block-doc or convert to `//!`
line docs) so the header comment in reloc.rs is formatted according to rustfmt.

---

Nitpick comments:
In `@harm/src/reloc.rs`:
- Around line 76-94: The four address-related constructors (adr_prel_lo21,
adr_prel_pg_hi21, adr_prel_pg_hi21nc, add_abs_lo12nc) should be changed to const
fn to match other constructors; update each signature from `pub fn` to `pub
const fn` and ensure they still call `Self::new(Rel64Tag::..., label)` so the
constructors remain usable in const contexts while referring to the same
Rel64Tag variants (AdrPrelLo21, AdrPrelPgHi21, AdrPrelPgHi21Nc, AddAbsLo12Nc).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1cdb41de-46b4-4b52-8dc8-247c921aeb01

📥 Commits

Reviewing files that changed from the base of the PR and between 0cbe6da and edee315.

📒 Files selected for processing (5)
  • harm/src/instructions/ldst.rs
  • harm/src/reloc.rs
  • harm/src/reloc/addr.rs
  • harm/src/reloc/claude_tests.rs
  • harm/src/reloc/movs.rs

@monoid monoid force-pushed the feat/relocations branch from fdd5502 to 6579bf4 Compare March 15, 2026 10:00
@monoid monoid force-pushed the feat/relocations branch from 6579bf4 to e549c5d Compare March 15, 2026 10:03
@monoid
Copy link
Copy Markdown
Owner Author

monoid commented Mar 15, 2026

@coderabbitai please, review.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 15, 2026

@monoid Sure, I'll start reviewing the PR right away!

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
harm/src/reloc/addr.rs (1)

148-226: Consider extracting a macro or helper to reduce duplication.

The ldst16, ldst32, ldst64, and ldst128 variants follow an identical pattern differing only in the ScaledOffset* type and constants. If the pattern needs modification in the future, all four implementations would need consistent updates.

That said, this is a minor maintainability concern—the current implementation is correct and clear.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@harm/src/reloc/addr.rs` around lines 148 - 226, These four functions
(ldst16_abs_lo12_nc_reloc, ldst32_abs_lo12_nc_reloc, ldst64_abs_lo12_nc_reloc,
ldst128_abs_lo12_nc_reloc) duplicate the same logic; extract a single helper or
macro that takes the ScaledOffset type and the three constants (CLEAR_MASK,
VALUE_MASK, and *_OFFSET) as parameters to centralize: implement a generic
helper (e.g., apply_ldst_abs_lo12_reloc) that accepts symbol, mem, offset, a
closure or trait to construct the ScaledOffset (ScaledOffset16/32/64/128::new),
and the CLEAR/VALUE/OFFSET constants, then have each specific function call that
helper with the appropriate ScaledOffset constructor and constants to remove the
duplicated unpack/clear/set/*bytes assignment logic.
harm/src/reloc.rs (1)

17-20: Minor: Trailing whitespace on line 19.

Line 19 appears to have trailing whitespace after the //! doc comment. This may cause cargo fmt or linting tools to flag it.

-//!   
+//!
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@harm/src/reloc.rs` around lines 17 - 20, The doc comment block in reloc.rs
contains trailing whitespace on the line describing `offset` (the `//!` comment
around "the offset in the memory to apply the relocation at."); remove the
trailing spaces from that doc comment line so the line ends immediately after
the comment text (then run cargo fmt or your editor's trim-trailing-whitespace
action to ensure no other doc lines have trailing whitespace).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@harm/src/reloc.rs`:
- Around line 328-330: The current use of value.cast_signed() for
Rel64Tag::Abs32 and Rel64Tag::Abs16 reinterprets bit patterns and causes
try_into failures for high unsigned ranges; locate the match arms for
Rel64Tag::Abs32 and Rel64Tag::Abs16 in reloc.rs and replace value.cast_signed()
with a bit-preserving cast (value as i32 for Abs32 and value as i16 for Abs16),
or alternatively change the signatures of abs32_reloc and abs16_reloc to accept
u32/u16 and perform the necessary narrowing internally; ensure you update all
call sites to match the chosen approach so high-bit unsigned inputs are handled
without runtime try_into errors.

---

Nitpick comments:
In `@harm/src/reloc.rs`:
- Around line 17-20: The doc comment block in reloc.rs contains trailing
whitespace on the line describing `offset` (the `//!` comment around "the offset
in the memory to apply the relocation at."); remove the trailing spaces from
that doc comment line so the line ends immediately after the comment text (then
run cargo fmt or your editor's trim-trailing-whitespace action to ensure no
other doc lines have trailing whitespace).

In `@harm/src/reloc/addr.rs`:
- Around line 148-226: These four functions (ldst16_abs_lo12_nc_reloc,
ldst32_abs_lo12_nc_reloc, ldst64_abs_lo12_nc_reloc, ldst128_abs_lo12_nc_reloc)
duplicate the same logic; extract a single helper or macro that takes the
ScaledOffset type and the three constants (CLEAR_MASK, VALUE_MASK, and *_OFFSET)
as parameters to centralize: implement a generic helper (e.g.,
apply_ldst_abs_lo12_reloc) that accepts symbol, mem, offset, a closure or trait
to construct the ScaledOffset (ScaledOffset16/32/64/128::new), and the
CLEAR/VALUE/OFFSET constants, then have each specific function call that helper
with the appropriate ScaledOffset constructor and constants to remove the
duplicated unpack/clear/set/*bytes assignment logic.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 38de3498-5db1-4acc-b6db-93a54261d20c

📥 Commits

Reviewing files that changed from the base of the PR and between edee315 and e549c5d.

📒 Files selected for processing (5)
  • harm/src/instructions/ldst.rs
  • harm/src/reloc.rs
  • harm/src/reloc/addr.rs
  • harm/src/reloc/claude_tests.rs
  • harm/src/reloc/movs.rs
🚧 Files skipped from review as they are similar to previous changes (3)
  • harm/src/reloc/claude_tests.rs
  • harm/src/instructions/ldst.rs
  • harm/src/reloc/movs.rs

@monoid monoid force-pushed the feat/relocations branch 4 times, most recently from 4576689 to 7f449ce Compare March 15, 2026 20:04
@monoid monoid force-pushed the feat/relocations branch 2 times, most recently from ac0c1a4 to 900c2ad Compare March 21, 2026 20:23
@monoid monoid force-pushed the feat/relocations branch from 900c2ad to 0ab8f2f Compare March 22, 2026 19:20
@monoid
Copy link
Copy Markdown
Owner Author

monoid commented Mar 22, 2026

@coderabbitai please, review the recent changes.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 22, 2026

@monoid Sure! I'll start reviewing the recent changes right away.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
harm/src/reloc.rs (1)

338-339: Add boundary regression coverage for ABS32 and ABS16.

The dispatcher path here is only exercised with a mid-range ABS32 value, and ABS16 has no visible success-path coverage. The spec-sensitive edge is the high unsigned boundary (0xffff_ffff / 0xffff), so please pin that behavior in tests.

✅ Suggested regression tests
     #[test]
     fn test_abs32() {
         let mut mem = [0; 4];
         Rel64Tag::ABS32.apply(0, 0x12345678, &mut mem, 0).unwrap();
         assert_eq!(mem, 0x12345678u32.to_le_bytes());
     }
+
+    #[test]
+    fn test_abs32_high_unsigned_boundary() {
+        let mut mem = [0; 4];
+        Rel64Tag::ABS32.apply(0, 0xffff_ffff, &mut mem, 0).unwrap();
+        assert_eq!(mem, 0xffff_ffffu32.to_le_bytes());
+    }
+
+    #[test]
+    fn test_abs16_high_unsigned_boundary() {
+        let mut mem = [0; 2];
+        Rel64Tag::ABS16.apply(0, 0xffff, &mut mem, 0).unwrap();
+        assert_eq!(mem, 0xffffu16.to_le_bytes());
+    }

Also applies to: 467-482

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@harm/src/reloc.rs` around lines 338 - 339, Add explicit regression tests that
exercise the Rel64Tag dispatcher branches for Rel64Tag::ABS32 and
Rel64Tag::ABS16 using the high unsigned boundary values (0xffff_ffff for ABS32
and 0xffff for ABS16) so the abs32_reloc and abs16_reloc success paths are
covered; locate the dispatcher in reloc.rs (the match arm mapping
Rel64Tag::ABS32 => abs32_reloc(...) and Rel64Tag::ABS16 => abs16_reloc(...)) and
write tests that construct the corresponding Reloc value/Reloc64Tag, call the
relocation path with memory and offset fixtures, and assert the expected success
behavior/outcome at those edge values.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@harm/src/reloc.rs`:
- Around line 338-339: Add explicit regression tests that exercise the Rel64Tag
dispatcher branches for Rel64Tag::ABS32 and Rel64Tag::ABS16 using the high
unsigned boundary values (0xffff_ffff for ABS32 and 0xffff for ABS16) so the
abs32_reloc and abs16_reloc success paths are covered; locate the dispatcher in
reloc.rs (the match arm mapping Rel64Tag::ABS32 => abs32_reloc(...) and
Rel64Tag::ABS16 => abs16_reloc(...)) and write tests that construct the
corresponding Reloc value/Reloc64Tag, call the relocation path with memory and
offset fixtures, and assert the expected success behavior/outcome at those edge
values.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 81772391-dc77-43c6-a854-f13f43957920

📥 Commits

Reviewing files that changed from the base of the PR and between edee315 and 0ab8f2f.

⛔ Files ignored due to path filters (1)
  • aarchmrs-instructions/src/lib.rs is excluded by !aarchmrs-instructions/src/**
📒 Files selected for processing (7)
  • harm/src/instructions/ldst.rs
  • harm/src/reloc.rs
  • harm/src/reloc/addr.rs
  • harm/src/reloc/claude_tests.rs
  • harm/src/reloc/control.rs
  • harm/src/reloc/data.rs
  • harm/src/reloc/movs.rs
✅ Files skipped from review due to trivial changes (2)
  • harm/src/instructions/ldst.rs
  • harm/src/reloc/control.rs
🚧 Files skipped from review as they are similar to previous changes (3)
  • harm/src/reloc/data.rs
  • harm/src/reloc/claude_tests.rs
  • harm/src/reloc/movs.rs

@monoid monoid force-pushed the feat/relocations branch from 0ab8f2f to 47f395d Compare March 28, 2026 13:55
@monoid monoid force-pushed the feat/relocations branch from 47f395d to 446a864 Compare March 28, 2026 14:08
@monoid monoid added harm The `harm` dynamic assembler and removed runtime The `harm`'s runtime: memory mappings, applying relocations, etc. labels Mar 29, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
harm/src/reloc.rs (1)

63-111: Normalize the acronym-based constructor names before this API settles.

ab_s64 / pre_l64 / pl_t32 read like tokenization artifacts, while the rest of the helpers follow the relocation names directly. Since these are public constructors, I'd expose the conventional spellings (abs64, prel64, plt32, etc.) or at least keep them as aliases for ergonomics.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@harm/src/reloc.rs` around lines 63 - 111, The public constructor names like
ab_s64, ab_s32, ab_s16, pre_l64, pre_l32, pre_l16, and pl_t32 should be
normalized to conventional spellings (abs64, abs32, abs16, prel64, prel32,
prel16, plt32); add new pub const fn wrappers with those canonical names that
return Self and delegate to the existing implementations (preserving #[inline]
and the LabelRef signature), and keep the current odd-named functions for
back-compatibility (optionally mark them #[deprecated] with a note pointing to
the new name) so callers can migrate without breaking changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@harm/src/reloc/movs.rs`:
- Around line 159-167: The movw_prel_g3_reloc currently always delegates to
movw_uabs_g3_reloc which only rewrites imm16 and fails for negative deltas;
change movw_prel_g3_reloc to use signed MOV patching: compute delta via
calc_delta(base, value, offset) as now, then if delta is negative call the
signed MOV handler (e.g., movw_sabs_g3_reloc or the module's MOVN/MOVZ-path
function) with the signed delta, otherwise call movw_uabs_g3_reloc for
non‑negative deltas; ensure you pass the correctly-typed delta to the chosen
function and add a small regression test that uses a negative delta for
MOVW_PREL_G3 to prevent regressions.

---

Nitpick comments:
In `@harm/src/reloc.rs`:
- Around line 63-111: The public constructor names like ab_s64, ab_s32, ab_s16,
pre_l64, pre_l32, pre_l16, and pl_t32 should be normalized to conventional
spellings (abs64, abs32, abs16, prel64, prel32, prel16, plt32); add new pub
const fn wrappers with those canonical names that return Self and delegate to
the existing implementations (preserving #[inline] and the LabelRef signature),
and keep the current odd-named functions for back-compatibility (optionally mark
them #[deprecated] with a note pointing to the new name) so callers can migrate
without breaking changes.
🪄 Autofix (Beta)

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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 252d2a64-9cc6-446c-8156-e14c53fe1812

📥 Commits

Reviewing files that changed from the base of the PR and between 0ab8f2f and c067f39.

📒 Files selected for processing (7)
  • harm/src/instructions/dpimm/movewide/movewide_reloc.rs
  • harm/src/reloc.rs
  • harm/src/reloc/addr.rs
  • harm/src/reloc/claude_tests.rs
  • harm/src/reloc/control.rs
  • harm/src/reloc/data.rs
  • harm/src/reloc/movs.rs
✅ Files skipped from review due to trivial changes (2)
  • harm/src/reloc/control.rs
  • harm/src/reloc/claude_tests.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • harm/src/instructions/dpimm/movewide/movewide_reloc.rs
  • harm/src/reloc/addr.rs

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
harm/src/reloc/claude_tests.rs (1)

729-748: Acknowledged: TODO comments document known ADRP overflow behavior.

The tests at lines 729-747 assert BitError::Unsupported with TODO comments noting this should ideally be BitError::Overflow. This is acceptable documentation of current behavior, though worth tracking for future improvement.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@harm/src/reloc/claude_tests.rs` around lines 729 - 748, Tests
adrp_overflow_positive and adrp_overflow_negative currently assert
Err(Rel64Error::InvalidBits(BitError::Unsupported)) even though the expected
semantic error should be BitError::Overflow; keep the current assertions for now
but make the intent explicit by updating the TODO comment to reference a
tracking issue and clarify that adrp_prel_pg_hi21_reloc currently returns
BitError::Unsupported (not Overflow) for the tested operands — change the
comments in the two tests (adrp_overflow_positive, adrp_overflow_negative) to
state the current behavior and include an issue/PR ID to fix
adrp_prel_pg_hi21_reloc's error mapping in future.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@harm/src/reloc/claude_tests.rs`:
- Around line 729-748: Tests adrp_overflow_positive and adrp_overflow_negative
currently assert Err(Rel64Error::InvalidBits(BitError::Unsupported)) even though
the expected semantic error should be BitError::Overflow; keep the current
assertions for now but make the intent explicit by updating the TODO comment to
reference a tracking issue and clarify that adrp_prel_pg_hi21_reloc currently
returns BitError::Unsupported (not Overflow) for the tested operands — change
the comments in the two tests (adrp_overflow_positive, adrp_overflow_negative)
to state the current behavior and include an issue/PR ID to fix
adrp_prel_pg_hi21_reloc's error mapping in future.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0c1b3db3-49c6-47fb-b00e-5b9b3a31b9b0

📥 Commits

Reviewing files that changed from the base of the PR and between 0ab8f2f and 3d824ba.

📒 Files selected for processing (7)
  • harm/src/instructions/dpimm/movewide/movewide_reloc.rs
  • harm/src/reloc.rs
  • harm/src/reloc/addr.rs
  • harm/src/reloc/claude_tests.rs
  • harm/src/reloc/control.rs
  • harm/src/reloc/data.rs
  • harm/src/reloc/movs.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • harm/src/reloc/control.rs

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
harm/src/reloc/addr.rs (1)

149-231: LGTM!

The scaled load/store relocations correctly apply alignment validation via the ScaledOffset* types before encoding the immediate. The UBitValue<12, N> constructors (per the bits.rs context) verify that the symbol's low 12 bits are properly aligned to the datum size (2/4/8/16 bytes), matching the ELF spec requirement that linkers check alignment.

The four functions follow an identical pattern—consider a macro to reduce duplication if this module grows, but the current explicit implementation is clear and maintainable.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@harm/src/reloc/addr.rs` around lines 149 - 231, These four nearly identical
functions (ldst16_abs_lo12_nc_reloc, ldst32_abs_lo12_nc_reloc,
ldst64_abs_lo12_nc_reloc, ldst128_abs_lo12_nc_reloc) duplicate the same
masking/unpacking logic; replace them with a small macro that parametrizes the
ScaledOffset type (ScaledOffset16/32/64/128) and the LDST*_IMM12 constant names
(CLEAR_WIDTH, VALUE_WIDTH, IMM12_OFFSET) and emits each function, reusing
get_bytes_mut, InstructionCode::unpack/from_u32 and the same mask/insert pattern
so the implementation is generated once and less error-prone.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@harm/src/reloc/addr.rs`:
- Around line 149-231: These four nearly identical functions
(ldst16_abs_lo12_nc_reloc, ldst32_abs_lo12_nc_reloc, ldst64_abs_lo12_nc_reloc,
ldst128_abs_lo12_nc_reloc) duplicate the same masking/unpacking logic; replace
them with a small macro that parametrizes the ScaledOffset type
(ScaledOffset16/32/64/128) and the LDST*_IMM12 constant names (CLEAR_WIDTH,
VALUE_WIDTH, IMM12_OFFSET) and emits each function, reusing get_bytes_mut,
InstructionCode::unpack/from_u32 and the same mask/insert pattern so the
implementation is generated once and less error-prone.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 05cf2563-6e59-45ef-81d3-ebc661f98245

📥 Commits

Reviewing files that changed from the base of the PR and between 3d824ba and f824c8c.

📒 Files selected for processing (3)
  • harm/src/reloc.rs
  • harm/src/reloc/addr.rs
  • harm/src/reloc/claude_tests.rs
✅ Files skipped from review due to trivial changes (1)
  • harm/src/reloc/claude_tests.rs

@monoid monoid force-pushed the feat/relocations branch from f824c8c to 5a90709 Compare April 4, 2026 17:56
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
harm/src/reloc/claude_tests.rs (1)

729-747: ⚠️ Potential issue | 🟡 Minor

Don’t bake the known-wrong ADRP overflow error into the tests.

These assertions still require BitError::Unsupported, so a real overflow fix will look like a regression. Either switch them to Overflow with the implementation change or loosen the match until then.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@harm/src/reloc/claude_tests.rs` around lines 729 - 747, The tests
adrp_overflow_positive and adrp_overflow_negative are asserting a specific
BitError::Unsupported which will make a future correct overflow fix look like a
regression; update the assertions against adr_prel_pg_hi21_reloc to not require
Unsupported specifically — either assert Err(Rel64Error::InvalidBits(_)) or
match both BitError::Unsupported and BitError::Overflow (or otherwise loosen the
pattern) so the tests accept a real overflow error without failing; locate these
tests by the function names adrp_overflow_positive, adrp_overflow_negative and
the call to adr_prel_pg_hi21_reloc.
🧹 Nitpick comments (1)
harm/src/reloc/claude_tests.rs (1)

2312-2320: Make this a real backward MOVW_PREL_G3 regression test.

With base = 0 and symbol = 0x1000_0000_0000_0000, this is still a forward delta, so the backward/wrapping G3 path remains uncovered. Swapping the operands or renaming the test/comment would make the intent match the case.

Based on learnings: MOVW_PREL_G3 intentionally uses the unsigned path, so the backward/wrapping case is the one worth pinning down.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@harm/src/reloc/claude_tests.rs` around lines 2312 - 2320, The test
movw_prel_g3_backward currently uses base=0 and symbol=0x1000_0000_0000_0000
which is a forward delta; to exercise the backward/wrapping MOVW_PREL_G3 path
swap the operands passed to movw_prel_g3_reloc (use base=0x1000_0000_0000_0000
and symbol=0) and update the expected immediate from 0x1000 to 0x0FFF (and
adjust the test comment/name if desired) so the call movw_prel_g3_reloc(...),
the MOVZ/MOVN handling in movw_prel_g3_reloc, and the dec_movw(i) assertion
reflect the backward/wrapping case.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@harm/src/reloc/claude_tests.rs`:
- Around line 729-747: The tests adrp_overflow_positive and
adrp_overflow_negative are asserting a specific BitError::Unsupported which will
make a future correct overflow fix look like a regression; update the assertions
against adr_prel_pg_hi21_reloc to not require Unsupported specifically — either
assert Err(Rel64Error::InvalidBits(_)) or match both BitError::Unsupported and
BitError::Overflow (or otherwise loosen the pattern) so the tests accept a real
overflow error without failing; locate these tests by the function names
adrp_overflow_positive, adrp_overflow_negative and the call to
adr_prel_pg_hi21_reloc.

---

Nitpick comments:
In `@harm/src/reloc/claude_tests.rs`:
- Around line 2312-2320: The test movw_prel_g3_backward currently uses base=0
and symbol=0x1000_0000_0000_0000 which is a forward delta; to exercise the
backward/wrapping MOVW_PREL_G3 path swap the operands passed to
movw_prel_g3_reloc (use base=0x1000_0000_0000_0000 and symbol=0) and update the
expected immediate from 0x1000 to 0x0FFF (and adjust the test comment/name if
desired) so the call movw_prel_g3_reloc(...), the MOVZ/MOVN handling in
movw_prel_g3_reloc, and the dec_movw(i) assertion reflect the backward/wrapping
case.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 285b4fdb-9ea6-480d-ae32-c980e5e61850

📥 Commits

Reviewing files that changed from the base of the PR and between f824c8c and 5a90709.

📒 Files selected for processing (3)
  • harm/src/reloc.rs
  • harm/src/reloc/addr.rs
  • harm/src/reloc/claude_tests.rs

@monoid monoid force-pushed the feat/relocations branch from 5a90709 to 4568444 Compare April 6, 2026 17:19
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
harm/src/reloc/claude_tests.rs (1)

729-747: ⚠️ Potential issue | 🟡 Minor

Don’t re-freeze the wrong ADRP overflow error.

These two assertions still require BitError::Unsupported, so a real fix in adr_prel_pg_hi21_reloc will read like a regression. Prefer BitError::Overflow, or at least loosen the match until the implementation is corrected.

🧪 Minimal test-side change
-        Err(Rel64Error::InvalidBits(BitError::Unsupported))
+        Err(Rel64Error::InvalidBits(_))

-        Err(Rel64Error::InvalidBits(BitError::Unsupported))
+        Err(Rel64Error::InvalidBits(_))
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@harm/src/reloc/claude_tests.rs` around lines 729 - 747, The tests
adrp_overflow_positive and adrp_overflow_negative assert the wrong BitError
variant; update their expectations in the assertions that call
adr_prel_pg_hi21_reloc to accept the correct overflow error (use
Err(Rel64Error::InvalidBits(BitError::Overflow))) or loosen the match to
Err(Rel64Error::InvalidBits(_)) until adr_prel_pg_hi21_reloc is fixed; locate
the two tests by name (adrp_overflow_positive and adrp_overflow_negative) and
replace the BitError::Unsupported match with BitError::Overflow or a wildcard.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@harm/src/reloc/claude_tests.rs`:
- Around line 2313-2320: The test movw_prel_g3_backward is misnamed and
exercises the forward (non-wrapping) path because movw_prel_g3_reloc(0x0,
0x1000_0000_0000_0000, ...) yields a positive value-place; either rename the
test to reflect the forward case or swap the first two args to
movw_prel_g3_reloc(0x1000_0000_0000_0000, 0x0, ...) so the value-place is
negative and triggers the wrapping/backward G3 branch, then update the assertion
to match the unsigned G3 encoding produced (check dec_movw(i) for expected
0x0FFF or the correct 16-bit chunk depending on chosen arguments) while keeping
the MOVZ/MOVK context in mind.

---

Duplicate comments:
In `@harm/src/reloc/claude_tests.rs`:
- Around line 729-747: The tests adrp_overflow_positive and
adrp_overflow_negative assert the wrong BitError variant; update their
expectations in the assertions that call adr_prel_pg_hi21_reloc to accept the
correct overflow error (use Err(Rel64Error::InvalidBits(BitError::Overflow))) or
loosen the match to Err(Rel64Error::InvalidBits(_)) until adr_prel_pg_hi21_reloc
is fixed; locate the two tests by name (adrp_overflow_positive and
adrp_overflow_negative) and replace the BitError::Unsupported match with
BitError::Overflow or a wildcard.
🪄 Autofix (Beta)

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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0a5b00b4-0af0-4348-9835-681c44ad6237

📥 Commits

Reviewing files that changed from the base of the PR and between 5a90709 and 4568444.

📒 Files selected for processing (4)
  • harm/src/reloc.rs
  • harm/src/reloc/addr.rs
  • harm/src/reloc/claude_tests.rs
  • harm/src/reloc/control.rs
✅ Files skipped from review due to trivial changes (1)
  • harm/src/reloc/addr.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • harm/src/reloc/control.rs

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (3)
harm/src/reloc/claude_tests.rs (3)

734-746: Typo: "obsure" → "obscure".

Minor spelling fix in the TODO comments.

✏️ Suggested fix
-        // TODO Unsupported seems to have obsure semantics.
+        // TODO Unsupported seems to have obscure semantics.

And similarly on line 744.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@harm/src/reloc/claude_tests.rs` around lines 734 - 746, Fix the typo "obsure"
→ "obscure" in the TODO comment(s) inside the test function
adrp_overflow_negative (and the earlier related TODO above it) so the comments
read "Unsupported seems to have obscure semantics." Locate the TODO comments
near the calls to adr_prel_pg_hi21_reloc and update both occurrences to use
"obscure".

1395-1403: Comment doesn't match the actual test values.

The comment references -0x8000 and 0x7FFF, but the code tests -0x10000 and expects 0xFFFF. The test logic is correct; only the comment needs updating.

✏️ Suggested fix
 #[test]
 fn mov_w_abs_g0s_max_negative() {
-    // ~i16::MIN = −0x8000~;  imm = ~(−0x8000)[15:0] = 0x7FFF
+    // −0x10000;  imm = ~(−0x10000)[15:0] = 0xFFFF
     let mut mem = insn_buf(MOVZ);
     movw_sabs_g0_reloc(-0x10000, &mut mem, 0).unwrap();
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@harm/src/reloc/claude_tests.rs` around lines 1395 - 1403, Update the
incorrect explanatory comment in the test mov_w_abs_g0s_max_negative: it
currently mentions −0x8000 and 0x7FFF but the test actually uses -0x10000 and
expects 0xFFFF; edit the comment above the test (near
mov_w_abs_g0s_max_negative, movw_sabs_g0_reloc, MOVZ, insn_buf, u32_at,
movw_opc, dec_movw) to reflect the actual values used (-0x10000 and 0xFFFF) so
the comment matches the test logic.

776-776: Typo: "Additionaly" → "Additionally".

✏️ Suggested fix
-// Additionaly ADRP tests
+// Additionally ADRP tests
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@harm/src/reloc/claude_tests.rs` at line 776, Fix the typo in the comment
string "Additionaly ADRP tests" by updating it to "Additionally ADRP tests"
(look for the exact comment "Additionaly ADRP tests" in claude_tests.rs and
correct the spelling to "Additionally").
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@harm/src/reloc/claude_tests.rs`:
- Around line 734-746: Fix the typo "obsure" → "obscure" in the TODO comment(s)
inside the test function adrp_overflow_negative (and the earlier related TODO
above it) so the comments read "Unsupported seems to have obscure semantics."
Locate the TODO comments near the calls to adr_prel_pg_hi21_reloc and update
both occurrences to use "obscure".
- Around line 1395-1403: Update the incorrect explanatory comment in the test
mov_w_abs_g0s_max_negative: it currently mentions −0x8000 and 0x7FFF but the
test actually uses -0x10000 and expects 0xFFFF; edit the comment above the test
(near mov_w_abs_g0s_max_negative, movw_sabs_g0_reloc, MOVZ, insn_buf, u32_at,
movw_opc, dec_movw) to reflect the actual values used (-0x10000 and 0xFFFF) so
the comment matches the test logic.
- Line 776: Fix the typo in the comment string "Additionaly ADRP tests" by
updating it to "Additionally ADRP tests" (look for the exact comment
"Additionaly ADRP tests" in claude_tests.rs and correct the spelling to
"Additionally").

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a4179f31-396a-415c-8c17-063956a34848

📥 Commits

Reviewing files that changed from the base of the PR and between 4568444 and ce16373.

📒 Files selected for processing (1)
  • harm/src/reloc/claude_tests.rs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request harm The `harm` dynamic assembler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant