Redefining Go Functions

Hacker rewires Go’s time function — commenters split between “cool” and “cursed”

TLDR: A developer showed how to hijack Go’s built‑in time function by rerouting it in memory, proving Go isn’t as untouchable as people think. Commenters split between calling it pointless and dangerous, citing safer test tricks and prior hacks, while jokers warn, “hide this from Rob Pike.”

A Go tinkerer just pulled a stunt straight out of sci‑fi: rerouting Go’s built‑in clock so it tells their time, not reality’s. The trick? A low-level memory rewrite that makes a program jump to a custom function—like swapping a road sign so every car takes your exit. It’s “monkey patching” (rewriting code while it runs), something Go famously avoids… or so we thought.

The crowd? Absolutely losing it. One camp is clutching pearls: “Yikes,” says pstuart, calling it hacking for hacking’s sake. Others are pointing to prior art, linking the notorious bouk/monkey and blog post from years back—proof this ghost has haunted Go before. The pragmatists arrived with water buckets: MadVikingGod basically says “relax, just make now a variable and swap it in tests,” while nasretdinov pitches source‑level fakery with golang-soft-mocks so you never touch the binary at all.

Meanwhile, the meme factory is in overdrive. One commenter jokes, “don’t let Rob Pike see this,” imagining the Go co‑creator having a meltdown. Others called it “magical,” “cursed,” and “the fastest way to summon 3 a.m. bugs.” The author warns not to use it, but that only made the thread more electric: half the room wants to try it on time.Now, the other half wants to salt the earth.

Key Points

  • Perl allows runtime function rewriting via symbol table manipulation, enabling monkey patching.
  • Go lacks a language feature for monkey patching, but its low-level tools allow modifying executable memory.
  • The address of a Go function (e.g., time.Now) can be retrieved with reflect.ValueOf(...).Pointer().
  • Function entry points can be verified by matching addresses and instructions using go tool objdump and unsafe.Slice.
  • Redirecting a function in Go can be done by writing an x86 JMP at the original function’s entry to a replacement with the same signature.

Hottest takes

“Yikes, I don’t see any legitimate use for this” — pstuart
“Just turn it into a variable and change it” — MadVikingGod
“Don’t let Rob Pike see this” — cronelius
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.