系统与基础设施muppetlabs.com
旋风教程:为 Linux 创建极小 ELF 可执行文件(1999)
A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux (1999)
2007 — 2025,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这是 breadbox 写于 1999 年的经典教程,主题是如何为 Linux 手工构造并裁剪出体积极小的 ELF 可执行文件。文章从可运行的程序出发,逐层去掉 ELF 头、节表和代码中非必需的部分,展示哪些结构才是加载器真正需要的。它不只是极限压缩技巧,也是理解 ELF 格式、链接与系统调用的动手入门。
为什么经久不衰:因为它用可复现的极限压缩实验把 ELF 的底层结构讲透,短小却常读常新,今天仍是学习可执行文件与汇编/系统调用的极佳入口。
HN 评论精选
作者更新了64位下的结果,并鼓励把艰难学到的东西分享出来。
我没法再补充什么,只好引用2013年的自己:没想到在64位Linux已普及的今天它还能再上HN首页。是的,我也试过最小化64位可执行文件;但64位既更大也更不容胡来,我做出的最小64位ELF是84字节。既然它又来了,感谢所有表达喜爱的人;写这篇文章是我职业生涯中做得较好的事之一——把硬啃出来的东西分享出去,不会白费。
breadbox查看英文原文
I find I need to quote myself from 2013, as I can't really add anything further to it: > Wow. I honestly wasn't expecting to ever see this on the front page of HN again, given the current ubiquity of 64-bit Linux. (And yes, before anyone asks, I've played around with minimizing 64-bit executables. Unfortunately they are both larger and less forgiving of tomfoolery. The smallest 64-bit ELF I've created is 84 bytes.) > Since it is here, though, I want to take the opportunity to say thanks to everyone who's expressed their appreciation of my essay. And I should note here that writing that essay, so many years ago now, is one of the better thing I've done for my career. Share what you have to learn the hard way; the effort won't be wasted.
这篇文章除体积优化外,更是学习底层知识的实用入口。
我向很多人推荐过这篇文章:不只是为了压缩体积,它也是学习 ELF、系统调用、汇编等内容的实用途径。
JoshTriplett查看英文原文
I've recommended this to many people as a practical way to learn more about ELF, system calls, assembly, and various other things, quite aside from size optimization.
受启发用汇编写 ELF,并给出 ABI、elf(5)、OSDev wiki 等学习资源;动态链接是难点。
我偶然看到后受到启发,用 GNU assembler 写了一些 ELF;其实相当直接,还有 elf(5) man page,基本就是32位和64位规范合在一起。若觉得好玩,可以查 System V ABI 参考了解各种重定位,/etc/include/elf.h 也有帮助。我卡住的是动态链接二进制,当时不太懂 PIE 和 GOT,就搁下了;也许该重新捡起来。OSDev wiki 也是这类底层细节的好来源。
xelxebar查看英文原文
Oh cool. I stumbled across this a while back and got inspired wrote some ELFs in gas (GNU assembler). It's surprisingly straightforward and there's even a manpage elf(5), which is pretty much exactly the 32- and 64-bit specifications rolled into one. If this kind of thing sounds fun to you then you'll probably want a System V ABI reference [0] to look up all the different relocations etc. Also, /etc/include/elf.h can be helpful. The part I started having trouble with was getting dynamically linked binares working. At the time I didn't quite understand what the PLE amd GOT were, so set things down. Maybe it's time to pick this back up. As always, the OS Dev wiki [1] is also a really good source for these kinds of low level implementation details. [0]:http://www.sco.com/developers/gabi/latest/contents.html [1]:https://wiki.osdev.org/
提供 PE 格式的对应极简可执行文件教程。
Windows PE 文件格式的同类练习:TinyPE。
sid0查看英文原文
The equivalent exercise for the Windows PE file format: http://www.phreedom.org/solar/code/tinype/
历次讨论
同类还值得读
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编辑精选PostgreSQL 内部原理
The internals of PostgreSQL
《The Internals of PostgreSQL》是一本免费在线书籍,系统讲解 PostgreSQL 的内部实现,包括查询处理、并发控制、WAL、缓冲区管理等核心机制。
系统与基础设施上首页 5 次 · 2017–2025interdb.jp编辑精选给分布式系统新人的笔记(2013)
Notes on Distributed Systems for Young Bloods (2013)
一篇面向分布式系统新手的经验笔记,作者以格言式的短条总结了多年实战中踩过的坑,涵盖一致性、延迟、背压、监控、CAP 定理等主题。
系统与基础设施上首页 5 次 · 2013–2024somethingsimilar.com编辑精选