TE
TechEcho
AccueilTop 24hRécentsMeilleursQuestionsPrésentationsEmplois
GitHubTwitter
Accueil

TechEcho

Une plateforme d'actualités technologiques construite avec Next.js, fournissant des nouvelles et discussions technologiques mondiales.

GitHubTwitter

Accueil

AccueilRécentsMeilleursQuestionsPrésentationsEmplois

Ressources

HackerNews APIHackerNews OriginalNext.js

© 2025 TechEcho. Tous droits réservés.

Writing a Self-Mutating x86_64 C Program (2013)

116 pointspar kepler471il y a 3 jours

9 comments

ivanjermakovil y a 3 jours
I had a great experience writing self modified programs is a single instruction programming game SIC-1: <a href="https:&#x2F;&#x2F;store.steampowered.com&#x2F;app&#x2F;2124440&#x2F;SIC1&#x2F;" rel="nofollow">https:&#x2F;&#x2F;store.steampowered.com&#x2F;app&#x2F;2124440&#x2F;SIC1&#x2F;</a>
评论 #44101159 未加载
DrZhvagoil y a 2 jours
Someone correct me if I am wrong, but self-mutating code is not as uncommon as the author portrays it. I thought the whole idea of hotspot optimization in a compiler is essentially self-mutating code.<p>Also, I spent a moderately successful internship at Microsoft working on dynamic assemblies. I never got deep enough into that to fully understand when and how customers where actually using it.<p><a href="https:&#x2F;&#x2F;learn.microsoft.com&#x2F;en-us&#x2F;dotnet&#x2F;fundamentals&#x2F;reflection&#x2F;emitting-dynamic-methods-and-assemblies" rel="nofollow">https:&#x2F;&#x2F;learn.microsoft.com&#x2F;en-us&#x2F;dotnet&#x2F;fundamentals&#x2F;reflec...</a>
Cloudefil y a 2 jours
Kaze Emanuar&#x27;s &quot;Optimizing with Bad Code&quot; video also goes briefly go through self-modifying code <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=4LiP39gJuqE" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=4LiP39gJuqE</a>
pfdietzil y a 2 jours
A program that can generate, compile, and execute new code is nothing special in the Common Lisp world. One can build lambda expressions, invoke the compile function on them, and call the resulting compiled functions. One can even assign these functions to the symbol-function slot of symbols, allowing them to be called from pre-existing code that had been making calls to that function named by that symbol.
评论 #44100268 未加载
xixixaoil y a 3 jours
I’ve been thinking a lot about this topic lately, even studying how executables look on arm macOS. My motivation was exploring truly fast incremental compilation for native code.<p>The only way to do this now on macOS is remapping whole pages as JIT. This makes it quite a challenge but still it might work…
alcoveril y a 3 jours
I often think this could maybe allow fantastic runtime optimisations. I realise this would be hardly debuggable but still..
评论 #44092769 未加载
评论 #44090517 未加载
评论 #44090592 未加载
评论 #44090453 未加载
评论 #44094212 未加载
oxcabeil y a 3 jours
It&#x27;s impressive how well laid out the content in this article is. The spacing, tables, and code segments all look pristine to me, which is especially helpful given how dense and technical the content is.
评论 #44094848 未加载
评论 #44093401 未加载
belteril y a 3 jours
I guess in OpenBSD because of W ^ X this would not work?
评论 #44090086 未加载
评论 #44089962 未加载
评论 #44089917 未加载
评论 #44089938 未加载
Someoneil y a 3 jours
Fun article, but the resulting code is extremely brittle:<p>- assumes x86_64<p>- makes the invalid assumption that functions get compiled into a contiguous range of bytes (I’m not aware of any compiler that violates that, but especially with profile-guided optimization or compilers that try to minimize program size, that may not be true, and there is nothing in the standard that guarantees it)<p>- assumes (as the article acknowledges) that “to determine the length of foo(), we added an empty function, bar(), that immediately follows foo(). By subtracting the address of bar() from foo() we can determine the length in bytes of foo().”. Even simple “all functions align at cache lines” slightly violates that, and I can see a compiler or a linker move the otherwise unused <i>bar</i> away from <i>foo</i> for various reasons.<p>- makes assumptions about the OS it is running on.<p>- makes assumptions about the instructions that its source code gets compiled into. For example, in the original example, a sufficiently smart compiler could compile<p><pre><code> void foo(void) { int i=0; i++; printf(&quot;i: %d\n&quot;, i); } </code></pre> as<p><pre><code> void foo(void) { printf(&quot;1\n&quot;); } </code></pre> or maybe even<p><pre><code> void foo(void) { puts(&quot;1&quot;); } </code></pre> Changing compiler flags can already break this program.<p>Also, why does this example work without flushing the instruction cache after modifying the code?
评论 #44094584 未加载
评论 #44096355 未加载
评论 #44095305 未加载
评论 #44096231 未加载