4 ms·
I haven't done a proper write-up yet but this is my current technique for emitting minimal ELF files written in freestanding C: 1. hand-written minimal ELF hea
by Retr0id 2y ago
I haven't done a proper write-up yet but this is my current technique for emitting minimal ELF files written in freestanding C:
1. hand-written minimal ELF headers, with enough asm to do `_exit(main(argc, argv))`: https://github.com/DavidBuchanan314/kurl/blob/main/golfed/elf_entry.s https://github.com/DavidBuchanan314/kurl/blob/main/golfed/el... (currently only implemented for aarch64)
2. "Linux Syscall Support" library for conveniently making raw syscalls from C: https://chromium.googlesource.com/linux-syscall-support/ https://chromium.googlesource.com/linux-syscall-support/
3. To avoid custom linker scripts (which I hate with a passion), I embed my hand-crafted ELF within a regular ELF, and slice it out at the end (using a python script). The "container" ELF is a regular full-fat ELF, potentially including working debug symbols, but the inner ELF has none of the cruft.
Using this technique, I wrote a barely-functional TLS1.3 client that fits in ~3.5KB (see the rest of repo from the first link)
- almostgotcaught 2y ago> To avoid custom linker scripts (which I hate with a passion) lol why? i mean the syntax sucks but this seems like howling into the wind...
- Retr0id 2y agoFirstly, yes, the syntax sucks. But most of all it's a a moving target. Every so often the compiler will decide to emit some fancy new segment or other metadata, and your linker script won't know what to do with it, and you have to re-learn linker script syntax to fix it.
- almostgotcaught 2y ago-Wl,--orphan-handling=error but hey whatever floats your boat
- Retr0id 2y agoThat doesn't solve the problem, though. orphan-handling lets you choose between loud breakage and quiet breakage. I want no breakage!
- saurik 2y agoThis is also why I avoid them like the plague. I would be a lot less annoyed by the concept of linker scripts if the mechanism were more set up as a concatenative language where you could provide a pile of modifications to behavior that add up to something useful, rather than having to whole-hog replace all of the behavior the compiler starts with (and like, in a world using clang/lld, which supports linker scripts but doesn't internally use them--meaning there is no "default" linker script you can dump/patch--the situation is even worse than it was before... I honestly have a hard time understanding why anyone considers this system acceptable).
- 1vuio0pswjnm7 2y ago"This is repo hosts my WIP entry to BGGP5. This README acts as a dev log of sorts (It's a bit of an un-edited stream of consciousness right now, I'll do a proper writeup later. hopefully). The main goal of BGGP5 is to download the file at https://binary.golf/5/5 https://binary.golf/5/5 and display its contents, using less than 4KB of code (stored in whatever format you like). Tiny disclaimer: As part of the BGGP staff team I knew about the theme in advance, and I absolutely could not resist getting started a few days early. This entry is more about being cool than being competitive, so I hope you can forgive me!" https://binary.golf/5/ https://binary.golf/5/ "A valid submission will: Be 4096 bytes or less Download the text file at https://binary.golf/5/5 https://binary.golf/5/5 Display the file's contents in some way Example Entry: #!/bin/sh wget https://binary.golf/5/5 https://binary.golf/5/5 cat 5 " Are we excluding the size of sh, wget and cat What is size of busybox with ssl_client as the only applet and wolfssl as the TLS library
- Retr0id 2y ago> Are we excluding the size of sh, wget and cat Yes. It's not very interesting, but you can do that. > What is size of busybox with ssl_client as the only applet and wolfssl as the TLS library Larger than 4096 bytes.
- 1vuio0pswjnm7 2y agoUsing kernel TLS would reduce size but is it compiled into all Linux kernels by default, e.g., Alpine Linux used to disable it