logoalt Hacker News

inigyouyesterday at 3:34 PM3 repliesview on HN

Self-modifying code is cool. It's a shame we had to disable it for security.


Replies

anitiltoday at 12:55 AM

I was re-reading Ian Lance Taylor's series of articles on Linkers [0], and one thing I didn't realise is that using dynamically linked libraries almost requires self-modifying code unless you want to resolve all function calls are start-time (which would make startup slower).

I'm still working my way through it so it's possible that I've misunderstood this section, though, and one question I haven't answered is how they get around the typical restriction on w+x pages.

[0] Particularly this one https://www.airs.com/blog/archives/41

mcculleyyesterday at 4:35 PM

Not just security. Instruction caches must also be aware of self-modifying code.

show 2 replies
Panzerschrekyesterday at 6:37 PM

It was maybe cool 50 years ago or so. Nowadays it's no longer needed. Possible performance gains of such code are marginal and modern programming languages allow generating many specialized and optimized code pieces using the same template, so that self-modification is no longer needed.

There is also JIT (like in regexp engines), but it's different story.

show 1 reply