angr.analyses.cfg.go_prologue

Recognition of the Go (gc) goroutine stack-growth preamble.

Every non-nosplit Go function starts with a check of the current stack pointer (or of the prospective frame bottom) against g.stackguard0, followed by a forward branch to a runtime.morestack trampoline appended after the function body. The conventional prologue the architecture’s function_prologs describe only comes after that check, so a plain prologue scan reports function starts several instructions past the real entry.

g.stackguard0 sits at 2 * ptrSize in g – [reg + 0x10] on 64-bit targets, [reg + 8] on 32-bit ones. Functions the compiler marks as C functions (//go:systemstack and friends) check g.stackguard1 instead, one pointer further in. The register holding g is architectural on most targets (r14 on amd64, x28 on arm64, r10 on arm), so the compare alone identifies the check. 386 has no dedicated g register and reaches g through TLS with an OS-specific sequence, which is therefore part of the pattern there.

The encodings have drifted across releases, so the tables cover several forms per architecture: windows/386 reaches g through fs:[0x14] up to go1.20 and through runtime.tls_g from go1.21, and the arm64 scratch pair was x1/x2 in go1.17 and is x16/x17 from go1.18 on – where go1.18 still compared through x17 and go1.19 and later compare sp directly.

angr.analyses.cfg.go_prologue.go_preamble_supported(arch_name)

Whether the Go stack-growth preamble is recognized on the named architecture.

Return type:

bool

Parameters:

arch_name (str)

angr.analyses.cfg.go_prologue.find_go_stack_check_preambles(blob, arch_name, base=0)

Find every Go goroutine stack-growth preamble in blob.

Parameters:
  • blob (bytes) – A blob of machine code.

  • arch_name (str) – archinfo name of the architecture blob is code for.

  • base (int) – The address blob starts at, used to enforce instruction alignment.

Return type:

Iterator[tuple[int, int, int]]

Returns:

An iterator of (start, end, branch_target) offsets into blob. Only preambles whose stack-growth branch goes forward are reported; the caller must still check that branch_target lies in the same executable region.