fix(parser): read the segment-absolute rendering FS:0

The toolchain's disassembler prints the segment-prefixed disp32
absolute as FS:0, but the bare-name branch read the segment register
alone and dropped the offset, so MOVQ FS:0, DX silently encoded a
register move.  The colon-offset form now lowers to the same
segment-absolute operand the 0(FS) spelling takes.

Assisted-by: GLM 5.3 Flash
This commit is contained in:
petrbalvin committed 2026-10-07 02:12:21 +02:00
1 parent abc2d32b83
commit a829b8f321
2 files changed
+63

No files matched your search

+15
View File
@@ -678,6 +678,21 @@ func parseAddress(g []token.Token) ast.Address {
i++
}
}
// Segment-absolute in the rendering spelling: FS:0 and GS:0. The
// colon-offset form is what the toolchain's disassembler prints for the
// segment-prefixed disp32 absolute, so the rendered text must re-encode;
// without it the segment register alone parsed and the offset vanished.
// The base field naming the segment lowers to the same operand the
// 0(FS) spelling takes.
if len(g) >= 3 && g[0].Kind == token.Ident && g[1].Kind == token.Colon &&
(g[0].Text == "FS" || g[0].Text == "GS") {
if v, rest, ok := foldExpr(g[2:]); ok && len(rest) == 0 {
addr.Base = g[0].Text
addr.Offset = v
addr.HasOff = true
return addr
}
}
// Bare name (register, label or symbol) possibly with an arm64 shift.
if addr.Base == "" && addr.Sym == nil && g[0].Kind == token.Ident {
sym := &ast.Symbol{Pos: g[0].Pos}