Add smaller ASM version and Makefile clean target#1
Merged
tchajed merged 2 commits intotchajed:mainfrom Mar 8, 2026
Merged
Conversation
Use the compilation and linking parameters of clang to generate a binary as small as tiny.
Owner
|
Thanks, this is cool! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
By adjusting the compilation and linking parameters, tiny_asm_opt can be as small as tiny.
This is the commands:
-s: Strips all symbol tables (.symtaband.strtab).-Wl,--build-id=none: Directs the linker (ld) to omit the.note.gnu.build-idsection, which normally contains a build hash.-z noseparate-code: A linker option that disables the "separate code" feature. This prevents enforcement of separate, non-writable segments for code and data. Critically, it allows the ELF header, program headers, and code to reside in the same loadable segment, enabling extreme size reduction.objcopy: A GNU Binutils tool for copying and transforming object files.--strip-section-headers: Removes the Section Header Table and all associated section name strings.Resulting ELF Structure
The final binary (
tiny_asm_opt) consists of:Key Optimization
By declaring a segment much larger than the file, the ELF avoids trailing zero-padding for alignment. Combining the ELF header, program headers, and code into a single executable segment—and then stripping non-essential section headers—achieves the minimal possible size while remaining a valid, executable ELF file.