Skip to main content
Be Bitwise

Reverse Engineering Go Binaries

Advanced Reverse Engineering Techniques · Advanced Reverse Engineering track

6 min read

In this module

Go Binaries Are Different

Go binaries are big, fat, and chatty. The runtime, the garbage collector, and the goroutine scheduler all get statically linked into every executable, padding things out by several megabytes minimum. For a reverse engineer, that bloat is a gift. Go binaries carry rich metadata about types, interfaces, and functions, and most of it survives even an aggressive strip.

Go's Calling Convention

Pre-1.17 Go used a stack-based calling convention. Every argument and every return value travelled on the stack rather than in registers — a deliberately old-school choice that made Go functions instantly recognisable in a disassembler.

nasm
; Pre-1.17 Go function call
MOVQ arg1, 0(SP) ; push first argument to stack
MOVQ arg2, 8(SP) ; push second argument
CALL runtime.funcname
MOVQ 16(SP), ret1 ; read first return value from stack
MOVQ 24(SP), ret2 ; read second return value

Go 1.17 finally adopted a register-based ABI for performance, passing arguments in AX, BX, CX, DI, SI, R8 through R11. The fingerprint shifted but didn't vanish. Go functions still announce themselves through their stack growth prologue: goroutine stacks start tiny (a few KB) and grow on demand, so every function opens with a check against the goroutine's stack limit and a branch to runtime.morestack when there's not enough room.

nasm
; Go function prologue (stack check), amd64, Go 1.17+ register ABI
start:
CMPQ SP, 16(R14) ; R14 always holds g; 16(R14) is g.stackguard0
JLS .Lneedstack ; at or below the limit: grow the stack
; ... function body ...
.Lneedstack:
; spill the register arguments to the stack
CALL runtime.morestack_noctxt
; reload them
JMP start ; retry after stack growth

Functions with big frames compute the would-be SP first (LEAQ -432(SP), R12 then CMPQ R12, 16(R14)). Before Go 1.17 the prologue loaded g from thread-local storage instead (MOVQ (TLS), CX / CMPQ SP, 16(CX)), so older binaries look like that. You'll also see small ABI0 wrapper functions in newer binaries, which shuffle arguments between the old stack convention (still used by assembly code) and the register-based ABIInternal.

That prologue pattern is one of the most reliable Go fingerprints, surviving even an aggressive strip.

Goroutine Stacks

C threads get a fat fixed stack — usually 1-8 MB carved out at thread start. Goroutines start with 2 KB (since Go 1.19 the runtime may start them larger, based on the average stack size it has seen) and grow as they need to, shrinking back down later. When a function's prologue check finds the stack short on space, runtime.morestack allocates a bigger one, memcpys the contents over, and updates every pointer that referenced the old stack.

That last detail catches reverse engineers off guard. Go stack frames can physically relocate in memory mid-execution. The compiler keeps it safe by tracking every stack pointer it emits. For analysis, the practical implications are two: stack addresses are unstable, and the runtime.morestack calls bolted onto every function are runtime plumbing, not application logic.

Finding the Main Function

In a Go binary, the ELF entry point is a small runtime stub (_rt0_amd64_linux on Linux/amd64) that jumps to runtime.rt0_go. That sets up the scheduler and memory allocator, then starts a goroutine running runtime.main, which finishes initialisation (including package init functions) before calling the user's main.main. To find the application entry point, search for cross-references to main.main or look for the string "main.main" in the symbol table. Even stripped Go binaries retain a function name table (gopclntab) that maps program counters to function names.

Interface Tables (itabs)

Go interfaces ride on itabs — interface tables. The first time a concrete type is used as a given interface, the runtime builds an itab that wires the interface's methods to that type's implementations.

An itab carries:

  • A pointer to the interface type descriptor
  • A pointer to the concrete type descriptor
  • A function pointer per interface method, tail-packed
go
type itab struct {
inter *interfacetype // interface type
_type *_type // concrete type
hash uint32 // type hash for fast type assertions
_ [4]byte // padding
fun [1]uintptr // method table (variable length)
}

On amd64 that puts the first method pointer at offset 24, after the 4 bytes of padding, with any further methods following at 32, 40 and so on. The interface value that points at an itab is itself just two words: the itab pointer, then a pointer to the data. Spot a 16-byte pair where the first word leads to a structure shaped like the one below, and you've found an interface.

Interface value (iface)

0x00x10
OffsetFieldSizeNotes
0x0 (0)*itab tab8Interface and concrete type, plus the method table.
0x8 (8)unsafe.Pointer data8Pointer to the concrete value, or the value itself if it is pointer-shaped.

16 bytes shown.

itab (amd64)

0x00x20
OffsetFieldSizeNotes
0x0 (0)*interfacetype inter8
0x8 (8)*_type _type8
0x10 (16)uint32 hash4Copy of _type.hash, used by type switches.
0x14 (20)[4]byte _4
0x18 (24)uintptr fun[0]8First method. fun[0] == 0 means the type doesn't implement the interface.

32 bytes shown.

Locate the itabs and the interface-implementation graph falls out. The two type descriptor pointers each lead to name strings, giving you the interface name on one side and the concrete type's name on the other. Trace cross-references to runtime.getitab, or sweep .rodata for itab-shaped structures.

String Representation

A Go string is a two-word struct: a pointer to bytes and a length. Go strings are not null-terminated — full stop. Forget about scanning for null bytes to find string boundaries, they aren't there.

go
// Go string: struct { data *byte, len int }

A slice header is the same idea with a third word: pointer, length, capacity. Both are small enough that the compiler usually passes them in registers rather than memory.

string and slice headers (amd64)

0x00x18
OffsetFieldSizeNotes
0x0 (0)*byte data / array8Pointer to the bytes or elements.
0x8 (8)int len8Length. Both string and slice have it.
0x10 (16)int cap8Slices only. A string header stops at 16 bytes.

24 bytes shown.

In disassembly, string construction shows up as a paired load: an address and a length, going into adjacent memory slots or register pairs. String constants live in .rodata. If the binary's not stripped, the go.string."..." symbols make them trivial to find; if it is, trace references from the string data section.

Runtime Structures

Go binaries contain rich metadata in several special sections:

  • gopclntab (PC-line table): maps program counters to function names, source file names, and line numbers. Even stripped binaries retain this table because the runtime needs it for stack traces. Tools like go_parser for IDA and GoReSym can parse this table to recover function names.
  • Type descriptors: Go's reflection system requires type information at runtime, so every type used in the program has a descriptor in the binary. These descriptors contain the type name, size, alignment, and method set.
  • Module data: the runtime.moduledata structure ties together all the metadata sections and is the starting point for metadata recovery.

Practical Approach

A working order of operations on a Go binary. Recover function names from gopclntab using GoReSym or similar. Find main.main — that's the application entry point, not runtime.main. Mentally skip the stack-growth prologue at the top of every function; it isn't application code. Locate itabs to build the interface implementation map. Parse type descriptors for struct layouts and method sets. Find string constants by their two-word shape. The accumulated runtime metadata means a stripped Go binary still yields more than a stripped C or C++ binary, often by a wide margin.