← blackwellsmatter.com / #001 · 2026-12-05
note #001 · compiler internals & ld_preload
ptxas 12.8.93 · w^x lock-free trampolines
Mercury: Exposing All 949 ROT13-Obfuscated Scheduling Knobs Inside ptxas 12.8.93
mercury · x86_64 LD_PRELOAD · triple target validation · immutable r-x trampolines · safe under --split-compile
949
INTERNAL KNOBS
37 categories · O(1) table
W^X
OUT-OF-LINE HOOKS
r-x trampoline · zero RWX
1.6M
8-THREAD STRESS
safe under --split-compile
0 B
DISK BINARY PATCH
clean skip on CUDA 13.0
01 Inside ptxas's ROT13-Obfuscated Knob Table
Behind NVIDIA's public ptxas flags sits an internal compiler tuning surface of 949 integer and boolean scheduling, register-allocation, scoreboard, and latency knobs spanning 37 categories — stored inside ptxas with ROT13-obfuscated ASCII names (starting at entry 0: AddWaitForCCOrPOffDeck).
mercury is a standalone C11 LD_PRELOAD library that decodes all 949 knob names at startup and intercepts knob_check_value and knob_get_int inside ptxas 12.8.93 (CUDA 12.8), letting kernel engineers sweep and diff SM120 SASS heuristics from a plain-text INI file without touching the binary on disk.
02 Triple Target Validation & Lock-Free W^X Trampolines
Startup (constructor, runs once before main):
1. Verify /proc/self/maps RX mapping
2. Match exact 13-byte ptxas 12.8.93 prologues + ROT13 sentinel [0]
└─ mismatch (e.g. ptxas 13.0.88 or child proc) ──► clean notice, exit untouched!
3. Emit relocated 13B prologue + back-jump onto dedicated r-x trampoline page
4. Patch entry once (movabs rax, hook; jmp rax; nop) → restore .text to r-x
Runtime (--split-compile N, lock-free across all threads):
ptxas caller ──► entry jmp ──► mercury_hook() ──► O(1) override[knob_id]
│ (not overridden)
└──► r-x trampoline (13B orig + jmp entry+13)
- Zero runtime self-modification: Earlier hooking prototypes restored/re-patched live
.textbytes on every call, leaving code pages permanentlyRWXand racing immediately under multi-threaded compilation (ptxas --split-compile 4). Out-of-linePROT_READ | PROT_EXECtrampolines are immutable once installed and verified under an 8-thread 1.6M-call stress test. - Full 949-knob O(1) direct table: Direct-indexed 949-entry override arrays support overriding every knob simultaneously with zero locks and zero linear scan.
# Build & run self-contained test suite (gcc & clang -Wall -Wextra -Wpedantic -Werror) git clone https://github.com/kacper-daftcode/mercury.git && cd mercury make && make test # Override internal ptxas scheduling knobs on the fly (zero binary edits) LD_PRELOAD=./mercury.so MERCURY_KNOBS=examples/aggressive_sched.txt \ ptxas -arch=sm_120 -O3 examples/test_kernel.ptx -o /tmp/out.cubin