Technique:Recognizing compiler-generated code
Appearance
| On this wiki | Facts · Code · Notes · Topics |
|---|
Code a compiler adds that a reverser should skip or name at a glance: stack cookies, Control Flow Guard call sites, x86 SEH frames, switch jump tables, division by constants, stack probes and inlined memory idioms. A checklist with the symbol names, constants and instruction shapes of MSVC, GCC and Clang.
Much of a function in a release build is not the author's logic but code the compiler (or the C runtime) inserted. Recognizing these shapes saves hours: they are the same in every program built by the same toolchain, they carry symbol names and constants that identify the toolchain and its flags, and the decompiler often renders them as noise.
Quick table
| You see | It is | Page |
|---|---|---|
load of fs:[0x28] (x64) or gs:[0x14] (x86) at entry, compare and call __stack_chk_fail at exit |
GCC/Clang stack protector | Technique:Recognizing compiler-generated code/Stack cookies |
xor rax, rsp / xor ecx, ebp then call __security_check_cookie, global __security_cookie |
MSVC /GS cookie | Technique:Recognizing compiler-generated code/Stack cookies |
call [__guard_dispatch_icall_fptr] or call [__guard_check_icall_fptr] before an indirect call |
Control Flow Guard | Technique:Recognizing compiler-generated code/Control Flow Guard |
push -2, push offset scopetable, call __SEH_prolog4 |
x86 MSVC structured exception handling | Technique:Recognizing compiler-generated code/x86 SEH frames |
cmp eax, N; ja default; jmp [table + eax*4] |
switch as jump table | Technique:Recognizing compiler-generated code/Switch jump tables |
imul/mul by a large odd constant followed by a shift, no div |
division by a constant | Technique:Recognizing compiler-generated code/Division by constants |
mov eax, 1000h or larger, call __chkstk / ___chkstk_ms / __rust_probestack, or a loop touching every 4096 bytes |
stack probe | Technique:Recognizing compiler-generated code/Stack probes |
rep movsq, rep stosd, movups runs, repne scasb |
inlined memcpy / memset / strlen, new/delete pairs, EH funclets | Technique:Recognizing compiler-generated code/Inlined library idioms |
How to use it
- Name the helper symbols first (they are imports or CRT functions, see Technique:Library function recognition); the surrounding prologue/epilogue then explains itself.
- Delete the scaffolding mentally: cookie store and check, guard call, probe call. What remains is the author's code.
- Use the scaffolding as evidence of the toolchain and flags: /GS, /guard:cf, /EHsc, -fstack-protector, optimization level. See Technique:Identifying the toolchain of a binary.
- For C++ runtime structures (RTTI, exception tables) see Platform:Microsoft Visual C++ ABI and Platform:Itanium C++ ABI; for PE fields that point at cookies and guard tables see Format:PE (Portable Executable)/Load config directory.
Topics
- Stack cookies — MSVC /GS security cookies (__security_cookie, __security_check_cookie, __GSHandlerCheck) and the GCC/Clang stack protector (fs:0x28 canary, __stack_chk_fail)…
- Control Flow Guard — How Microsoft Control Flow Guard (CFG) shows up in code: indirect calls routed through __guard_check_icall_fptr or __guard_dispatch_icall_fptr, with the…
- x86 SEH frames — The 32-bit MSVC structured exception handling frame: the push/call prolog with __SEH_prolog4, the SCOPETABLE of (previous try level, filter, handler) entries…
- Switch jump tables — How compilers lower a dense C switch to an unsigned bounds check followed by an indirect jump through a table, and how the table entries are encoded on x86…
- Division by constants — Compilers replace division by a constant with a multiply by a magic number and shifts. How to spot it, the Hacker's Delight algorithm LLVM implements, worked…
- Stack probes — Calls and loops that touch every page of a large stack frame so the guard page is hit in order: MSVC __chkstk, MinGW/Clang ___chkstk_ms, AArch64 __chkstk and…
- Inlined library idioms — Compiler-inlined memcpy, memset and strlen (rep movs/stos, SIMD loops, repne scasb) and C++ new/delete pairs with their cleanup funclets: how to read them as…
Code & repositories
- https://github.com/llvm/llvm-project @
8c3ef3bef883424fa714b307f8b52c0685496008· license: Apache-2.0 WITH LLVM-exception (declared by the contributor for the files used; GitHub reports MIT (read from LICENSE.TXT; GitHub's API was busy) for the repository)
LLVM: llvm/lib/Support/DivisionByConstantInfo.cpp (magic division), llvm/lib/Transforms/CFGuard/CFGuard.cpp, compiler-rt/lib/builtins/{x86_64,i386,aarch64}/chkstk.S, llvm/lib/Target/X86/X86ISelLoweringCall.cpp (stack protector), llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp (jump table lowering).
Tested on: source read, not run: Read the named files at the head of main; not built. · checked 2026-10-18 - https://github.com/rust-lang/compiler-builtins @
f521807de24520770991263387ba8c06e462edf8· license: (MIT AND Apache-2.0 WITH LLVM-exception) (read from LICENSE.txt; GitHub's API was busy)
Rust compiler-builtins: src/probestack.rs defines __rust_probestack for x86 and x86-64.
Tested on: source read, not run: Read probestack.rs; not built. · checked 2026-10-18 - https://github.com/gcc-mirror/gcc @
c7d983e54c1dbcf7906a0f359920cb5b54aa9bba· license: GPL-3.0-or-later WITH GCC-exception-3.1 (declared by the contributor; GitHub's detector did not recognize COPYING)
GCC mirror: libssp/ssp.c is the stack-protector runtime (__stack_chk_guard, __stack_chk_fail).
Tested on: source read, not run: Read libssp/ssp.c; not built. · checked 2026-10-18 - https://github.com/wine-mirror/wine @
7298a818b79446bae153b8d5aa27235ab3703bf9· license: LGPL-2.1-or-later (declared by the contributor; GitHub's detector did not recognize LICENSE)
Wine: dlls/msvcrt/except_i386.c implements SEH3/SEH4 scope tables, _except_handler3/4 and local unwind.
Tested on: source read, not run: Read except_i386.c; not built. · checked 2026-10-18
Evidence & references
- llvm/llvm-project (Apache-2.0 WITH LLVM-exception), compiler-rt/lib/builtins, llvm/lib/Target, llvm/lib/Support/DivisionByConstantInfo.cpp.
- Per-topic evidence is on the subpages.