<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/redefining-go-functions-xw2qyqen0" -->

---
title: Redefining Go Functions | daily.dev
description: Go functions can be redefined at runtime by manipulating memory directly, despite lacking language-level support for monkey patching. The technique involves...
canonical: https://daily.dev/posts/redefining-go-functions-xw2qyqen0
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Redefining Go Functions | daily.dev
og:description: Go functions can be redefined at runtime by manipulating memory directly, despite lacking language-level support for monkey patching. The technique involves...
og:url: https://daily.dev/posts/redefining-go-functions-xw2qyqen0
og:image: https://api.daily.dev/og/posts/XW2QYQEn0.png
og:image:alt: Redefining Go Functions
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Redefining Go Functions

**[Lobsters](https://daily.dev/sources/lobsters)** · 8 min read · 2 upvotes · 1 comments

## Summary

Go functions can be redefined at runtime by manipulating memory directly, despite lacking language-level support for monkey patching. The technique involves using reflection to get function addresses, modifying memory page permissions with mprotect, and writing JMP instructions to redirect execution. The article provides working x86 and ARM64 implementations, explains how to handle instruction encoding and cache invalidation, and warns about serious limitations including inline functions, generics, and struct layout mismatches that can cause crashes or memory corruption.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://pboyd.io/posts/redefining-go-functions/>

## Community discussion

Top comments from developers on daily.dev.

**@pkraszewski** · 0 upvotes

> For heaven's sake, just **don't**. The _W^X_ paradigm is here for a reason.

## Similar posts on daily.dev

- [macOS code injection for fun and no profit](https://daily.dev/posts/macos-code-injection-for-fun-and-no-profit-0c9d9lwbb) · Hacker News · 0 upvotes · 0 comments
- [A Basic Just-In-Time Compiler](https://daily.dev/posts/a-basic-just-in-time-compiler-mrdvhvck5) · Hacker News · 1 upvotes · 0 comments
- [cloud security, system engineering and compilers](https://daily.dev/posts/cloud-security-system-engineering-and-compilers-sxfl15jgp) · Lobsters · 1 upvotes · 0 comments

---

Tags: [#golang](https://daily.dev/tags/golang), [#assembly](https://daily.dev/tags/assembly)

[View this post on daily.dev](https://daily.dev/posts/redefining-go-functions-xw2qyqen0)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Redefining Go Functions","url":"https://daily.dev/posts/redefining-go-functions-xw2qyqen0","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/redefining-go-functions-xw2qyqen0"},"datePublished":"2026-02-11T12:06:32.735Z","dateModified":"2026-02-11T12:06:55.629Z","description":"Go functions can be redefined at runtime by manipulating memory directly, despite lacking language-level support for monkey patching. The technique involves...","image":"https://media.daily.dev/image/upload/s--qPvKM23u--/f_auto/v1722860399/public/Placeholder%2009","thumbnailUrl":"https://media.daily.dev/image/upload/s--qPvKM23u--/f_auto/v1722860399/public/Placeholder%2009","isAccessibleForFree":true,"articleSection":"Lobsters","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Lobsters","logo":"https://media.daily.dev/image/upload/s--tl8v_Fku--/f_auto,t_logo/v1698841318/logos/lobste.jpg","url":"https://daily.dev/sources/lobsters"},"commentCount":1,"discussionUrl":"https://daily.dev/posts/redefining-go-functions-xw2qyqen0","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":1}],"keywords":"golang,assembly","timeRequired":"PT8M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Lobsters","item":"https://daily.dev/sources/lobsters"},{"@type":"ListItem","position":3,"name":"Redefining Go Functions"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/redefining-go-functions-xw2qyqen0","comment":[{"@type":"Comment","text":"For heaven’s sake, just don’t. The W^X paradigm is here for a reason.","datePublished":"2026-02-11T15:40:07.818Z","dateModified":"2026-02-11T15:40:18.597Z","url":"https://daily.dev/posts/XW2QYQEn0#c-kFCymgRY1","author":{"@type":"Person","name":"Paweł Kraszewski","url":"https://daily.dev/pkraszewski","image":"https://avatars.githubusercontent.com/u/1206223?v=4"}}]}
```

