Last active
November 26, 2024 12:43
-
-
Save MestreLion/b2691c2a9f471487332777bd5109bb66 to your computer and use it in GitHub Desktop.
127-byte Tiny Teensy x86_64 compliant ELF64 using standard tools
This file contains 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
; tiny.asm | |
; 127-byte fully compliant X86-64 ELF64 binary | |
; Inspired by: | |
; - https://www.muppetlabs.com/~breadbox/software/tiny/ | |
; - https://ech0.re/building-the-smallest-elf-program/ | |
; - https://nullprogram.com/blog/2016/11/17/ | |
; Restrictions: | |
; - True x86_64 ELF64 binary, not 32bit-binary-on-64bit-platform | |
; - No handcrafting ELF headers in ASM | |
; - No hex editing or directly manipulating binaries | |
; - Only standard GNU tools (nasm, ld, gcc, etc) | |
; To "compile": | |
; - nasm -f elf64 tiny.asm # tiny.o, 576 bytes | |
; - ld -s -no-pie -z noseparate-code tiny.o -o tiny # tiny, 336 bytes | |
; (~13K without the flags!!!) | |
; - strip --strip-section-headers tiny # 127 bytes | |
BITS 64 | |
SECTION .text align=1 | |
GLOBAL _start | |
_start: | |
; _exit(42) | |
; all registers zeroed by Linux ABI at start, so safe to use al/dil | |
mov al, 60 ; Select the _exit syscall (60 in Linux ABI) | |
mov dil, 42 ; Set the exit code argument for _exit | |
syscall ; Perform the selected syscall |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment