Repository navigation
synctools: generalize asmwriter.py's AArch64-only alias/mnemonic logic - #3053
StilesCrisis wants to merge 1 commit into
Conversation
While attempting to regenerate PPC's AsmWriter output end-to-end (see
previous commit), hit several real bugs in this script - all in logic
that was hand-written specifically for AArch64 in 2022 and never
exercised against any other target since:
- getMnemonic/getRegisterName's "const char *AArch64InstPrinter::"
skip rule was hardcoded to the literal string "AArch64InstPrinter::",
so it silently swallowed PPC's real getRegisterName definition line
too (both match "const char *PPCInstPrinter::getRegisterName(...)"),
producing a getRegisterName body with no function signature at all.
Now excludes getRegisterName explicitly.
- getMnemonic's std::pair-returning raw signature had no matching
early-out translation for the "if (Bits == 0) return {nullptr,
Bits};" guard that newer LLVM adds - fixed to fold into the same
uint64_t-returning convention already used for the main return path.
- Newer LLVM wraps register handles in MCRegister, so getRegisterName's
raw definition now reads "getRegisterName(MCRegister Reg) { unsigned
RegNo = Reg.id(); ... }" - this leftover redeclaration line conflicted
with our hardcoded plain-unsigned-parameter signature. Now stripped.
- The injected alias-matching block's AArch64InstPrinterValidateMCOperand
call and its isSME/set_sme_index handling (AArch64 SME tile-slice
indexing syntax, e.g. "za[w8, 0]") were both hardcoded literals.
Parameterized the validator name by target; SME handling now only
applies for AArch64/ARM64, with a plain always-set_mem_access fallback
for every other target (which never has SME bracket syntax).
Each fix was confirmed necessary by direct compiler error (not
speculative) while iterating toward a from-scratch PPC rebuild. See the
previous commit for what remains unverified about that full rebuild.
|
These scripts are no longer in use. We still backport important fixes to v5 or do very small additions, but it is no longer under active development. I suggest to switch to the latest Alpha release. |
|
I can confirm that the new code already solves the issue correctly, but the
toolset I'm using (decomp-toolkit) is still pointing at the v5 release.
I agree that v5 is way behind--I had to use LLVM 7.0.1 to make it work at
all!--but since it's still in real-world use, I thought we would want a fix.
…On Wed, Sep 2, 2026 at 8:30 AM Rot127 ***@***.***> wrote:
*Rot127* left a comment (capstone-engine/capstone#3053)
<#3053 (comment)>
These scripts are no longer in use.
We use AutoSync now as updater on the next branch:
https://github.com/capstone-engine/capstone/blob/next/suite/auto-sync/README.md
We still backport important fixes to v5 or do very small additions, but it
is no longer under active development.
I suggest to switch to the latest Alpha release.
Even though it is called Alpha. It is way better tested and more correct
than the v5 branch.
—
Reply to this email directly, view it on GitHub
<#3053?email_source=notifications&email_token=AGCLRPICARAQWBEENPY43BD5NAHGDA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKNJQHE2TIMZYGIY2M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KYZTPN52GK4S7MNWGSY3L#issuecomment-5509543821>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGCLRPNMTTIE5EWLQNB7TK35NAHGDAVCNFSNUABEKJSXA33TNF2G64TZHMYTINZTGU2DEOJ3JFZXG5LFHM2TEOJSGAYTINZTG2QXMAQ>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/AGCLRPPKXWQLE6VAFRBIGXL5NAHGDA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKNJQHE2TIMZYGIY2M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KUZTPN52GK4S7NFXXG>
and Android
<https://github.com/notifications/mobile/android/AGCLRPPEYJ7OI4X56PNZK2T5NAHGDA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKNJQHE2TIMZYGIY2M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2K4ZTPN52GK4S7MFXGI4TPNFSA>.
Download it today!
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
|
Also to clarify: the PR is large solely because it was made properly
through llvm-tblgen. The alternative would be to bodge in a hack to the
table data manually. This would make a smaller CL but IMO far riskier.
If v6 is still labeled as alpha, I don't think decomp-toolkit would accept
a PR switching to it, even if it's better in this instance.
…On Wed, Sep 2, 2026 at 10:47 AM John Stiles ***@***.***> wrote:
I can confirm that the new code already solves the issue correctly, but
the toolset I'm using (decomp-toolkit) is still pointing at the v5 release.
I agree that v5 is way behind--I had to use LLVM 7.0.1 to make it work at
all!--but since it's still in real-world use, I thought we would want a fix.
On Wed, Sep 2, 2026 at 8:30 AM Rot127 ***@***.***> wrote:
> *Rot127* left a comment (capstone-engine/capstone#3053)
> <#3053 (comment)>
>
> These scripts are no longer in use.
> We use AutoSync now as updater on the next branch:
> https://github.com/capstone-engine/capstone/blob/next/suite/auto-sync/README.md
>
> We still backport important fixes to v5 or do very small additions, but
> it is no longer under active development.
>
> I suggest to switch to the latest Alpha release.
> Even though it is called Alpha. It is way better tested and more correct
> than the v5 branch.
>
> —
> Reply to this email directly, view it on GitHub
> <#3053?email_source=notifications&email_token=AGCLRPICARAQWBEENPY43BD5NAHGDA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKNJQHE2TIMZYGIY2M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KYZTPN52GK4S7MNWGSY3L#issuecomment-5509543821>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AGCLRPNMTTIE5EWLQNB7TK35NAHGDAVCNFSNUABEKJSXA33TNF2G64TZHMYTINZTGU2DEOJ3JFZXG5LFHM2TEOJSGAYTINZTG2QXMAQ>
> .
> Triage notifications, keep track of coding agent tasks and review pull
> requests on the go with GitHub Mobile for iOS
> <https://github.com/notifications/mobile/ios/AGCLRPPKXWQLE6VAFRBIGXL5NAHGDA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKNJQHE2TIMZYGIY2M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KUZTPN52GK4S7NFXXG>
> and Android
> <https://github.com/notifications/mobile/android/AGCLRPPEYJ7OI4X56PNZK2T5NAHGDA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKNJQHE2TIMZYGIY2M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2K4ZTPN52GK4S7MFXGI4TPNFSA>.
> Download it today!
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>
|
I see. Thanks for pointing that out. Still, the v5 branch has not the same amount of testing. So I don't want to merge a ~5000 loc change. Since we worked on the AutoSync update we really try to improve the stability and reliability of Capstone, and that would go against it. Also because these old generating scripts are not tested.
I can recommend to open an issue about it and ask. Many other big projects switched already. PPC in particular was so much improved compared to the v5 branch, I think for most people it is worth the effort. |
That's valuable to know. I will see if it's easy to switch dtk over to v6, and if so, I will push the PR and use this as the rationale. If it's complex for some reason, or it causes regressions, I will be back here. |
|
Just noticed we're chatting on the "wrong" PR (this was fixes to the v5 py setup script, not the meaty PR with all the table changes) but NBD |
Don't forget to check out the release guide: https://github.com/capstone-engine/capstone/blob/next/docs/cs_v6_release_guide.md I tried my best to document any breaking change and new additions there. |
|
Thank you very much for the guidance. capstone v6 is pretty much a win on every axis and resolves my issue. I had Claude exercise the before-and-after on my project:
I asked for more info on mcrxr since that op was unfamiliar to me. It looks like very old versions of CodeWarrior would emit it.
|
That is on purpose. One target of v6 is, that it outputs as closely to LLVM as possible.
You can add it to our LLVM fork and generate the |
|
Check out this PR: capstone-engine/llvm-capstone#78 There I added some proprietary Apple AArch64 instructions. Your case will likely be simpler. |
|
The checked-in PowerPC tables in capstone are pinned to an "LLVM 18"-era snapshot from Dec 2024, so a straight regen pulls in a huge amount of unrelated upstream churn alongside my one-instruction change. I'm going to try and find a period-appropriate snapshot. |
You mean in the v5 branch? That won't work indeed. It is way too outdated. What meant above is, to add the instruction to the |
Problem
suite/synctools/asmwriter.py(the script that converts rawllvm-tblgen -gen-asm-writeroutput into capstone's C style) has AArch64-only logic hardcoded into several places, dating to when the script was written for AArch64 in 2022 and never exercised against another target since. Running it against a non-AArch64 target's raw tblgen output produced by a reasonably modern LLVM breaks in several ways - found while regenerating PowerPC's asm-writer output for #3052.Bugs fixed
getRegisterName/getMnemonic's"const char *AArch64InstPrinter::"skip rule was a literal string match, so for any other target it also matched (and silently swallowed) that target's own realgetRegisterNamedefinition line - e.g. PPC's"const char *PPCInstPrinter::getRegisterName(...)"matches the same substring pattern. Result: agetRegisterNamebody with no function signature at all. Now excludesgetRegisterNameexplicitly, and matches the target's own class name instead of a hardcodedAArch64InstPrinter.getMnemonichad no translation for newer LLVM's early-out guard (if (Bits == 0) return {nullptr, Bits};), which doesn't exist in the older LLVM output this script was originally written against.MCRegister, sogetRegisterName's raw definition now includes aRegNo = Reg.id();redeclaration line that conflicts with this script's hardcoded plain-unsigned-parameter signature.printAliasInstralias-matching block hardcodedAArch64InstPrinterValidateMCOperandand AArch64's SME tile-slice-indexing bracket syntax (za[w8, 0]) unconditionally. Validator name is now parameterized by target; SME bracket handling now only applies for AArch64/ARM64, with a plainset_mem_access()-only fallback for every other target (none of which have SME syntax).Each fix was confirmed necessary by an actual compiler/parse error while iterating toward a from-scratch PPC rebuild, not speculative.
Scope note
This is a synctools script fix, not a PPC-specific change - it generalizes logic that only worked for AArch64 to work for any target regenerated against a comparably modern LLVM. It's independent of #3052, which uses an older (LLVM 7.0.1-vintage) toolchain that doesn't hit any of these code paths at all.
One related note for anyone regenerating a target against modern LLVM specifically: if that target has zero
K_CustomAliasPatternConds (true for PPC, as of writing), the injected<Target>InstPrinterValidateMCOperandcall in the alias-matching block is unreachable but still needs a stub of that name in the target'sInstPrinter.cto link - this script doesn't generate that stub itself, since it's C source, not template output.