News for hackers. Stuff that matters.
Re:SectorC: A C Compiler in 512 bytes by gigel82 on Wednesday May 24, 2023 @08:09PM (#36065606)
I'm wondering if you can build an actual "Linux from scratch" with this as the lowest level, without the need to use a host system at all.
Re:SectorC: A C Compiler in 512 bytes by vitiral on Wednesday May 24, 2023 @08:11PM (#36065621)
Without structs? Good luck...
Re:SectorC: A C Compiler in 512 bytes by DesiLurker on Wednesday May 24, 2023 @08:14PM (#36065639)
wonder how many extra bytes for structs?
Re:SectorC: A C Compiler in 512 bytes by vitiral on Wednesday May 24, 2023 @08:19PM (#36065689)
In my experience, probably at least a 200-400 lines of C (another 512 bytes minimum? I don't know the conversion).

The problem is not just declaring structs but accessing them, referencing them, accessing/referencing fields and subfields, etc. That has to all be in the syntax. For such a minimal project you can ignore initialization.

I did all this while adding maybe 500 lines of C to GitHub.com/vitiral/fngi. Never tried for this level of minimalism though.

Re:SectorC: A C Compiler in 512 bytes by geocar on Thursday May 25, 2023 @10:12AM (#36070964)
Once upon a time, when += was spelled =+, struct members in C were global names whose "values" were the offsets from the beginning of the struct[1]; a.b is simply a[ptrtab[b]] and a->b is a[0][ptrtab[b]].

[1]: This is why all of the names of struct members in unix are "needlessly" prefixed; i.e. struct stat.st_mode is not struct stat.mode because that could conflict with struct foo.mode until the early 1980s.

Re:SectorC: A C Compiler in 512 bytes by DesiLurker on Friday May 26, 2023 @11:54AM (#36085823)
Ah that explains it, I wondered about those old struct defs.
Re:SectorC: A C Compiler in 512 bytes by gigel82 on Wednesday May 24, 2023 @08:14PM (#36065638)
LFS already has several "stepping stones" where it walks through a whole set of C compilers from very old ones compiling slightly newer / more capable ones and so on.

Perhaps with a few more "layers of compilers" on top you can get a very early GCC going.

Re:SectorC: A C Compiler in 512 bytes by FpUser on Wednesday May 24, 2023 @08:40PM (#36065832)
>"Perhaps with a few more "layers of compilers" on top you can get a very early GCC going."

Applause. Best comment ;)

Re:SectorC: A C Compiler in 512 bytes by mjevans on Wednesday May 24, 2023 @09:56PM (#36066279)
I can't help but wonder if this is written in x86-16 bit mode to implicitly use Real Mode BIOS functions and platform interfaces as well.

There's something to be said for taking advantage of that existing code; but if that's a dependency it should be part of the environment manifest. Everything has (most things have) a context where it might be useful and that should be included in the explanation so a tool isn't misused and so incorrect expectations aren't set.

Re:SectorC: A C Compiler in 512 bytes by xorvoid on Thursday May 25, 2023 @12:26AM (#36067061)
It’s written in x86-16 real mode because all immediates are smaller and switching to 32-bit mode takes a fair amount of code.

I would have preferred 32-bit mode because real mode is awkward with its seg:off addressing scheme.

Using the bios functions just allows it to have “not-boring” examples easily.

Re:SectorC: A C Compiler in 512 bytes by mjevans on Thursday May 25, 2023 @01:35AM (#36067350)
That's true, but it's still a sort of library dependency. Even for very tiny computers with a lot of hardware assistance, the basic ROM for communicating with the world in a useful way is bigger.
Re:SectorC: A C Compiler in 512 bytes by fosslinux on Thursday May 25, 2023 @04:35AM (#36068344)
Not using this, but tangentially related is (full disclosure, i am a maintainer of this project) live-bootstrap, which uses about a KB of binary to do a full "Linux from scratch" style thing - read https://github.com/fosslinux/live-bootstrap/blob/master/part... for all 143 steps you have to go through to get there.
Re:SectorC: A C Compiler in 512 bytes by gigel82 on Thursday May 25, 2023 @01:18PM (#36073426)
Wow, just reading through the list of steps was fascinating!