Open michael105 opened 3 years ago
Did it. Sort of reinventing shared libraries. In mini. Now - it might be possible to get the core tools down to 64kB. I'm however concerned with my original idea, having static tools. I guess I have to think about it. Maybe it is cheating. Maybe I should say, as long the basic functionality is given without loading external "plugins", it's ok. Maybe I've to sort this out thoroughly.
So here is the masterplan for getting the core utils down to 64 kB..
1. Find what is bloating (bello world bloats from 181 to now 241 Bytes.)Found it. It's the elf program header. Can be stripped, but then the stack is marked executable by the kernel. What in fact isn't a problem, (as long you don't write evil code, but there would be better and less obvious possibilities...), however, several "security tools" do think in another way. So I leave the elf program headers in for now.Enable sort of plugin loading. Do all work within a function, which is callen with arguments parsed. (E.g. stat(filename,fd)) Have this function with position independent code. Furthermore, the function needs to be located in the binary at a fixed place. Load, e.g., in ls the binary into memory, and have a wrapper function:
wrap_stat(filename,fd){ if (!addrofstat) mmap(...);... asm("jmp address of stat"); }
Funny enough, the real stat's return will return to the place where wrap_stat is invoked.
I'm not really sure whether that's such a great idea 😂 but might work, also performant, and spare the needed bytes. I'll see ex