Re:KolibriOS – operating system written entirely in assembly...
by SomeoneFromCA on Wednesday April 15, 2020 @10:48AM
(#22878346)
The problem not in the language per se, but in the linker settings. By tweaking it, you can achieve almost same size as the assembler version has.
[ Parent
| on HN ]
Re:KolibriOS – operating system written entirely in assembly...
by BubRoss on Wednesday April 15, 2020 @01:00PM
(#22880128)
You say that, but I still haven't seen any compilers link in only parts of libc. Use any of it and it all comes in.
Hello world in C becomes anywhere from 120KB to 1.2MB even if just using puts. Even setting the entry point to a function with no arguments doesn't help.
A tiny hello world ends up needing to ignore the standard library and use a console output function from the OS.
Re:KolibriOS – operating system written entirely in assembly...
by SomeoneFromCA on Wednesday April 15, 2020 @04:44PM
(#22882804)
Just checked on a Ubuntu machine. Hello world takes 6Kb. Uses printf.
Re:KolibriOS – operating system written entirely in assembly...
by BubRoss on Wednesday April 15, 2020 @05:14PM
(#22883163)
That's because it links dynamically to the standard library.
Re:KolibriOS – operating system written entirely in assembly...
by Dylan16807 on Wednesday April 15, 2020 @10:24PM
(#22885445)
Is that a problem? It's there whether you use it or not, and it's not like the asm is running in a vacuum either.
If you go to an embedded point of view where there is nothing already supplied, you can get a hello world, even with a basic printf, down to that size.
Re:KolibriOS – operating system written entirely in assembly...
by snvzz on Thursday April 16, 2020 @06:22AM
(#22887911)
Especially since you use external libraries to do the bulk of the work, 6KB is a lot.
It is an order of magnitude bigger than the assembly version.
Re:KolibriOS – operating system written entirely in assembly...
by SomeoneFromCA on Thursday April 16, 2020 @11:24AM
(#22890344)
After some manipulations with the linker, I was able to cut the size down to 750 bytes. You cannot go below this, without hacking the ELF file format.
Re:KolibriOS – operating system written entirely in assembly...
by snvzz on Thursday April 16, 2020 @01:51PM
(#22891809)
I got my asm one down to 268 without even trying.
It prints (via write syscall) "hello world.\n" and then calls exit(0).
Assembled with fasm, linked with ld -n, then stripped.
Re:KolibriOS – operating system written entirely in assembly...
by SomeoneFromCA on Thursday April 16, 2020 @05:14PM
(#22893649)
Ok fine, I've used the tool called sstrip from a suite called ELFKickers. Now my hello_world.cpp (yes, c++) is 380 bytes long. I could not make it any shorter, so yeah, it is 120 bytes (50%) bigger than yours.
Re:KolibriOS – operating system written entirely in assembly...
by snvzz on Friday April 17, 2020 @01:21AM
(#22896452)
Regarding sstrip, I am familiar with it. Be careful that you know what it actually does.
Re:KolibriOS – operating system written entirely in assembly...
by SomeoneFromCA on Friday April 17, 2020 @09:53AM
(#22898974)
So, not order of magnitude then?
Re:KolibriOS – operating system written entirely in assembly...
by snvzz on Friday April 17, 2020 @12:17PM
(#22900301)
Yes, just look into how much effort you had to put vs my five minutes attempt.
The difference is between just using asm, or going out of the way to try to coerce a C toolchain to minimize the bloat.
Re:KolibriOS – operating system written entirely in assembly...
by SomeoneFromCA on Friday April 17, 2020 @01:18PM
(#22900935)
Yea, large effort (objcopy, strip, sstrip), that I need to do only once, after that I already know how to do this an can just put it in a shell script. Now, I would like to know how quickly you'll be able to write a quicksort implementaion, that would outperform my C code, while being at least 25% smaller . Yeah, and how big your binary will become, once you link libc or opengl or whatever to make it able to do actual work.