Skip to content

[AArch64][LFI] Consolidate LFI metadata and automate addressing-mode/base mapping#6

Draft
nickdesaulniers wants to merge 11 commits into
lfi-project:llvm-pr/lfi/aarch64-rewriter-3from
nickdesaulniers:aarch64_lfi2a
Draft

[AArch64][LFI] Consolidate LFI metadata and automate addressing-mode/base mapping#6
nickdesaulniers wants to merge 11 commits into
lfi-project:llvm-pr/lfi/aarch64-rewriter-3from
nickdesaulniers:aarch64_lfi2a

Conversation

@nickdesaulniers

Copy link
Copy Markdown

Refactor AArch64 Lightweight Fault Isolation(LFI) metadata TableGen architecture
to automate scalar variant and SIMD post-index mappings.

This approach improves upon the previous design by centralizing all
suffix-to-base instruction conversions into a single, unified
LFIScalarVariant helper class. This eliminates the need for scattered,
multiclass-specific string substitutions. Furthermore, size and scale
checks have been fully prefixed (e.g., matching LDR/STR or LDP/STP
structures), resolving previous prefix collisions where doubleword
instructions were incorrectly classified.

  • Move LFI-specific TableGen classes into a dedicated, isolated target file:
    AArch64LFIInstrFormats.td.
  • Introduce a unified LFIScalarVariant base class that dynamically resolves
    an instruction's addressing mode (AddrMode) and base register-offset
    instruction (RoWInst) at TableGen compile-time.
  • Centralize the LFIInst instruction cast inside LFIInstruction to simplify
    LFIInst definitions across all subclasses.
  • Automate SIMD post-index writeback scaling via TableGen, removing over 200
    lines of manual foreach mapping loops in AArch64LFI.td.
  • Maintain a clean separation of concerns, leaving AArch64InstrFormats.td
    focused strictly on core memory layout properties for the MemInfoTable.
  • Synchronize structure fields in AArch64MCLFIRewriter.cpp with TableGen's
    generated searchable primary keys.

zyedidia and others added 11 commits May 12, 2026 19:09
…base mapping

Refactor AArch64 Lightweight Fault Isolation(LFI) metadata TableGen architecture
to automate scalar variant and SIMD post-index mappings.

This approach improves upon the previous design by centralizing all
suffix-to-base instruction conversions into a single, unified
LFIScalarVariant helper class. This eliminates the need for scattered,
multiclass-specific string substitutions. Furthermore, size and scale
checks have been fully prefixed (e.g., matching LDR/STR or LDP/STP
structures), resolving previous prefix collisions where doubleword
instructions were incorrectly classified.

- Move LFI-specific TableGen classes into a dedicated, isolated target file:
  AArch64LFIInstrFormats.td.
- Introduce a unified LFIScalarVariant base class that dynamically resolves
  an instruction's addressing mode (AddrMode) and base register-offset
  instruction (RoWInst) at TableGen compile-time.
- Centralize the LFIInst instruction cast inside LFIInstruction to simplify
  LFIInst definitions across all subclasses.
- Automate SIMD post-index writeback scaling via TableGen, removing over 200
  lines of manual foreach mapping loops in AArch64LFI.td.
- Maintain a clean separation of concerns, leaving AArch64InstrFormats.td
  focused strictly on core memory layout properties for the MemInfoTable.
- Synchronize structure fields in AArch64MCLFIRewriter.cpp with TableGen's
  generated searchable primary keys.
@nickdesaulniers nickdesaulniers marked this pull request as draft May 21, 2026 21:10
@zyedidia zyedidia force-pushed the llvm-pr/lfi/aarch64-rewriter-3 branch from eb6e583 to f2b56f1 Compare June 2, 2026 20:10
zyedidia pushed a commit that referenced this pull request Jul 7, 2026
A `breakpoint set -P <class>` with an invalid-UTF-8 class name crashes
lldb with `EXC_BAD_ACCESS`.  The class name is passed through
unmodified, so the byte sequence `\xd0p` (an incomplete two-byte UTF-8
sequence) reaches the Python layer:

```
 ./bin/lldb -b -o $'breakpoint set -P \xd0p -f main.cpp' ./bin/lldb
...
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/
Stack dump:
 #4 PythonDictionary::GetItem(PythonObject const&) const
 #6 PythonDictionary::GetItemForKey(PythonObject const&) const
 llvm#7 PythonObject::ResolveNameWithDictionary(StringRef, PythonDictionary const&)
 llvm#9 ScriptedPythonInterface::CreatePluginObject<...>(...)
```

`ResolveNameWithDictionary` builds a `PythonString` from the class name
and looks it up in the module dictionary.  When the name is not valid
UTF-8, `PyUnicode_FromStringAndSize` returns `NULL`, so the
`PythonString` is left with `m_py_obj == NULL`. `GetItemForKey` forwards
that object to `GetItem`, which passed the `NULL` `PyObject *` straight
to `PyDict_GetItemWithError`.

Debugging the crashing lldb under lldb shows the `NULL` key arriving in
`GetItem`:

```
(lldb) break set -n lldb_private::python::PythonDictionary::GetItem
(lldb) run --no-use-colors -b -s /tmp/bp_cmds.txt
* stop reason = breakpoint 1.1
(lldb) up
(lldb) frame variable key.m_py_obj
(PyObject *) key.m_py_obj = nullptr
```

Continuing lands on the dereference of that `NULL` inside CPython:

```
(lldb) continue
* stop reason = EXC_BAD_ACCESS (code=1, address=0x8)
    frame #0: PyDict_GetItemWithError + 40
->  ldr    x8, [x1, #0x8]
```

`x1` holds the key argument, which is `NULL`, so reading the type field
at offset `0x8` faults at address `0x8`.

`GetItem` already guards against an invalid dictionary (`!IsValid()`);
extend that guard to reject an invalid key as well and return
`nullDeref()`.  `GetItemForKey` consumes the error and returns an empty
`PythonObject`, so existing callers such as `ResolveNameWithDictionary`
keep working and the breakpoint command now fails cleanly instead of
crashing.

This was found by `lldb-commandinterpreter-fuzzer`.

Adds `PythonDataObjectsTest.TestPythonDictionaryGetItemWithInvalidKey`,
which feeds an invalid-UTF-8 key to `GetItem`.  Without the fix the test
dereferences the `NULL` key and crashes (`SIGSEGV`).
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.

2 participants