系统与基础设施justine.lol
在 400 字节的 ELF 可执行文件中支持四种操作系统
Supporting four operating systems in a 400 byte ELF executable
2022 — 2025,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这是 Justine Tunney(justine.lol)《Size Tricks》一文中关于 ELF 的一节:通过压缩 ELF 头和程序头、去掉多余段等手法,把一个真正可执行的 ELF 文件压到 400 字节以内,并且同一份文件能在四个操作系统上运行。作者用这种极端的最小化演示,指出各系统在 ELF/POSIX 层面其实高度相似,只差少量约定。
为什么经久不衰:它把「可执行文件格式到底有多少字节是必需的」这个问题推到极限,既是有趣的工程炫技,也给出了跨系统 ABI 兼容性成本有多低的具体证据。
HN 评论精选
历史上曾有统一的 Unix ABI 标准(iBCS),作者自己也有更极端的跨 DOS/Windows 小体积 Hello World。
值得一提的是,Unix 类系统上曾经有过统一 ABI 的努力(Intel Binary Compatibility Standard,见维基百科),但互联网基本已经把它忘了。我用一个 26 字节的 Hello World 就能在 DOS 1.x–6.x、Windows 1.x–10 上跑;如果改用 CALL 5,也许能进 CP/M 的地盘,但可能就跑不了较新的系统了。四个系统不到 400 字节,相当厉害!
userbinator查看英文原文
It's worth noting that at one point there was an effort to standardise ABIs on Unix-like OSs, https://en.wikipedia.org/wiki/Intel_Binary_Compatibility_Standard although it seems to have mostly been forgotten by the Internet. (I dug into that a little bit, inspired by a previous article here: https://news.ycombinator.com/item?id=31456401 ) Four operating systems is under 400 bytes is pretty good! I have a 26-byte Hello World that works in DOS 1.x, 2.x, 3.x, 4.x, 5.x, 6.x, Windows 1.x, 2.x, 3.x, 95, 98, 98se, Me, 2k, XP, Vista, 7, 8, 10. If I used CALL 5 I might get down into CP/M-land but possibly miss some of the newer OSs ;-)
顺带推荐作者站点的项目列表,唯一遗憾是没有 RSS。
索引页上的项目都很有意思,只希望能提供 RSS 订阅。
bArray查看英文原文
Really interesting projects on the index [1], just wish there was an RSS feed! [1] https://justine.lol/index.html
点出文章的真正诉求:跨系统通用 ABI 的技术成本很低,瓶颈在于协调成本。
除了做出超小二进制这个结果之外,我理解 Justine 是想让各操作系统维护者意识到:支持一个通用 ABI 是有价值的,而且在他们已经统一了 CPU 架构和 POSIX 之后,为此要做的改动其实很少。但这些改动需要在所有系统间同步,沟通成本很高。所以归根结底取决于大家希望系统 ABI 层面有多少创新。
erwan577查看英文原文
Beyond the tiny binary result, I understand that Justine want the OS maintainers to understand that there is value in supporting a common ABI and that there are very little changes to do for that once they already standardized on the CPU arch and POSIX. But changes would need to be synchronized accross all OS, so there would be a large communication cost. So this bogs down to how much innovation is expected in system ABIs.
提醒这种极度精简的二进制对格式细节极其敏感、非常脆弱。
我在 CTF 里写的 shellcode 大概都没这个脆弱吧 :P
saagarjha查看英文原文
I think I’ve written shellcode for CTFs that’s less fragile than this :P
历次讨论
同类还值得读
TTY 揭秘(2008)
The TTY demystified (2008)
经典文章深入剖析了 Unix/Linux 中 TTY 子系统的工作原理,包括线路规程、终端驱动、信号与控制字符等机制。
系统与基础设施上首页 11 次 · 2009–2025linusakesson.net编辑精选为什么 GNU grep 这么快
Why GNU grep is Fast
FreeBSD 邮件列表上一篇广为流传的帖子,解释 GNU grep 为什么快:核心在于 Boyer-Moore 字符串搜索算法配合精心优化的内部循环和 I/O,让程序在搜索时“…
系统与基础设施上首页 9 次 · 2010–2022lists.freebsd.orgXplain:为普通人讲解 X11
Xplain – Explaining X11 for the rest of us
《Xplain》是作者(HN 用户 Jasper_)写的一系列 X11 长文,用他在浏览器中重建的 X11 绘图模型做交互演示,讲解 X11 的绘图模型与窗口系统设计。
系统与基础设施上首页 6 次 · 2013–2020magcius.github.io编辑精选旋风教程:为 Linux 创建极小 ELF 可执行文件(1999)
A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux (1999)
breadbox 写于 1999 年的经典教程,主题是如何为 Linux 手工构造并裁剪出体积极小的 ELF 可执行文件。
系统与基础设施上首页 6 次 · 2007–2025muppetlabs.comPostgreSQL 内部原理
The internals of PostgreSQL
《The Internals of PostgreSQL》是一本免费在线书籍,系统讲解 PostgreSQL 的内部实现,包括查询处理、并发控制、WAL、缓冲区管理等核心机制。
系统与基础设施上首页 5 次 · 2017–2025interdb.jp编辑精选