News for hackers. Stuff that matters.
Re:Fil-C: A memory-safe C implementation by nielsbot on Tuesday October 28, 2025 @05:00PM (#45739116)
I like to share this every time there's a post about memory safe C:

Apple has a memory-safer C compiler/variant they use to compile their boot loaders:

https://saaramar.github.io/iBoot_firebloom/

Re:Fil-C: A memory-safe C implementation by pizlonator on Tuesday October 28, 2025 @07:21PM (#45740599)
That was my idea and I wrote a good chunk of the compiler and runtime.
Re:Fil-C: A memory-safe C implementation by kragen on Tuesday October 28, 2025 @07:25PM (#45740637)
(For those who didn't make the connection, pizlonator also wrote Fil-C.)
Re:Fil-C: A memory-safe C implementation by frumplestlatz on Tuesday October 28, 2025 @10:30PM (#45741934)
I don’t want to out myself or simply cast vague aspersions against which one cannot easily defend, so I’ll just say that was not the reality on the ground.
Re:Fil-C: A memory-safe C implementation by pizlonator on Tuesday October 28, 2025 @11:08PM (#45742182)
Sounds like you weren't there
Re:Fil-C: A memory-safe C implementation by frumplestlatz on Tuesday October 28, 2025 @11:40PM (#45742360)
Okay. I really don’t want to break HN rules, but it’s interesting to see that your time away hasn’t tempered your myopic ego one bit.
Re:Fil-C: A memory-safe C implementation by jibal on Wednesday October 29, 2025 @01:59AM (#45743158)
That breaks HN rules.
Re:Fil-C: A memory-safe C implementation by kragen on Wednesday October 29, 2025 @02:10AM (#45743219)
(But revealing your identity would not.)
Re:Fil-C: A memory-safe C implementation by actionfromafar on Wednesday October 29, 2025 @06:42AM (#45745033)
You don't want to - so you did it anyway?
Re:Fil-C: A memory-safe C implementation by geocar on Wednesday October 29, 2025 @04:41AM (#45744238)
Why isn't the compiler frontend called fucc?
Re:Fil-C: A memory-safe C implementation by pizlonator on Wednesday October 29, 2025 @08:34AM (#45746012)
I was so tempted to call it that
Re:Fil-C: A memory-safe C implementation by ctrust on Wednesday October 29, 2025 @11:46AM (#45748436)
It isn't too late!
Re:Fil-C: A memory-safe C implementation by RBO2 on Wednesday October 29, 2025 @10:05AM (#45746998)
Why not call it secc ("sexy") ?
Re:Fil-C: A memory-safe C implementation by pizlonator on Wednesday October 29, 2025 @11:30AM (#45748162)
It's poor form to put the word "secure" (or any derivative of it) into a product that aims to provide more security.

Reason: there's no solution to the security problem. Fil-C doesn't solve security. Does it make things more secure? Yes! But there will always be more security issues. So imagine if I had called it "Secure C" (and then had a sexy compiler), and 10 years from now someone finds a comprehensive solution to the string injection problem in Secure C. What do they call their thing? Securer C? Secure C Pro? Secure Secure C?

Re:Fil-C: A memory-safe C implementation by RBO2 on Wednesday October 29, 2025 @11:51AM (#45748521)
These are good points but no name is ever perfect. Just felt that secc was more memorable and would offer more levarage to this great project :-)
Re:Fil-C: A memory-safe C implementation by kragen on Wednesday October 29, 2025 @02:07PM (#45750747)
"Filthy" is already extremely memorable.
Re:Fil-C: A memory-safe C implementation by kragen on Wednesday October 29, 2025 @01:48PM (#45750490)
I agree. I'd add that security is always relative to not just an existing level of security but to a threat model. There are threat models relative to which Fil-C doesn't make things more secure. (I can't think of one under which Fil-C makes things less secure, though.)

A similar criticism applies to "new". Newcastle is named after a castle built 945 years ago. Neuchâtel is named after a castle built 1014 years ago. Xavier (from Basque "etxeberri", "new house") is named after a castle built in the 10th century. Windows NT "new technology", etc.

Re:Fil-C: A memory-safe C implementation by jibal on Thursday October 30, 2025 @01:25AM (#45756697)
Re:Fil-C: A memory-safe C implementation by avadodin on Wednesday October 29, 2025 @05:58AM (#45744716)
Forgive me for not putting in the effort this deserves, but the description of pointers in this thread reads a lot like the current description of Fil-C pointers from the main site.

What is the 64-bit-presenting representation of pointers in Fil-C?

That is, what does %p return and how does that work as a pointer?

Re:Fil-C: A memory-safe C implementation by pizlonator on Wednesday October 29, 2025 @08:34AM (#45746006)
Re:Fil-C: A memory-safe C implementation by avadodin on Wednesday October 29, 2025 @08:44PM (#45755073)
Re-reading tfm, it definitely had an answer to my dumb question(basically the same as any regular C pointer), but I still get the feeling that the explanations make jumps that may be obvious to you but absolutely not to me.

I sort of get a sense of what the flight pointers do after reading the linked page with the assembly listings( which on mobile looks like you're discussing hex dumps until one tries side scrolling, btw ) but my brain would expect something along the lines of: "this is the flight pointer and this is how it is managed for local variables, global variables, etc. This part of it is what your C program sees" at the beginning of the invisicaps article rather than "pointers are 64 bit like in regular C proceeds to talk about a tuple containing two pointers"(at least that's how it reads to me).

Probably just laziness on my part.

Re:Fil-C: A memory-safe C implementation by pizlonator on Wednesday October 29, 2025 @08:55PM (#45755137)
That’s really good feedback about how to better talk about this stuff. Thank you!

InvisiCaps are counterintuitive. Took me a while to come up with them. I still haven’t found a really clean way to explain them to folks

Re:Fil-C: A memory-safe C implementation by kragen on Tuesday October 28, 2025 @05:10PM (#45739232)
Yeah, fat pointers are definitely a viable approach, but a lot of the existing C code that is the main argument for Fil-C assumes it can put a pointer in a long. (Most of the C code that assumed you could put it in an int has been flushed out by now, but that was a big problem when the Alpha came out.) I'm guessing that the amount of existing C code in Apple's bootloader is minimal, maybe 1000 lines, not the billions of lines you can compile with Fil-C.
Re:Fil-C: A memory-safe C implementation by matthewfcarlson on Tuesday October 28, 2025 @06:00PM (#45739804)
You’re off by a few orders of magnitude. I’ll grant you, what is the bootloader becomes a very complex question. Even if you scope it to just “what is the code physically etched into the chip as the mask ROM” (secureROM) you’re talking hundreds of thousands. If you’re talking about all the code that runs before the kernel starts executing you’re talking hundreds of millions.
Re:Fil-C: A memory-safe C implementation by kragen on Tuesday October 28, 2025 @06:06PM (#45739868)
No, I was only talking about the pre-existing C code that wasn't written for the bootloader, which therefore might have incompatibilities with fat pointers you had to hunt down and fix.

Also I'm really skeptical about your "hundreds of millions" number, even if we're talking about all the code that runs before the kernel starts. How do you figure? The entire Linux kernel doesn't contain a hundred millions of lines of code, and that includes all the drivers for network cards, SCSI controllers, and multiport serial boards that nobody's made in 30 years, plus ports to Alpha, HP PA-RISC, Loongson, Motorola 68000, and another half-dozen architectures. All of that contains maybe 30 million lines. glibc is half a million. Firefox 140.4.0esr is 33 million. You're saying that the bootloader is six times the size of Firefox?

Are you really suggesting that tens of gigabytes of source code are compiled into the bootloader? That would make the bootloader at least a few hundred megabytes of executable code, probably gigabytes, wouldn't it?

Re:Fil-C: A memory-safe C implementation by jacquesm on Sunday November 02, 2025 @03:16PM (#45793035)
100's millions is clearly nonsense, but Grub2, which arguably is a (second stage) bootloader is half a million lines. It's interesting that this is a bootloader, and not an operating system in its own right, and a nice example of software bloat.
Re:Fil-C: A memory-safe C implementation by ummonk on Tuesday October 28, 2025 @06:23PM (#45740047)
Couldn’t one just make long bigger then to make it match?
Re:Fil-C: A memory-safe C implementation by kragen on Tuesday October 28, 2025 @06:36PM (#45740183)
Maybe so; I haven't tried. Probably a lot less code depends on unsigned long wrapping at 2⁶⁴ than used to depend on unsigned int wrapping at 2¹⁶, and we got past that. But stability standards were lower then. Any code that runs on both 32-bit and 64-bit LP64 systems can't be too dependent on the exact sizeof long, and sizeof long already isn't sizeof int the way it was on 32-bit platforms.
Re:Fil-C: A memory-safe C implementation by ummonk on Wednesday October 29, 2025 @02:26PM (#45751009)
I'd actually keep it still wrapping at 2^64, with the extra metadata not participating in arithmetic operations...
Re:Fil-C: A memory-safe C implementation by cryptonector on Wednesday October 29, 2025 @01:08AM (#45742848)
It's going to break stuff one way or another.
Re:Fil-C: A memory-safe C implementation by jibal on Wednesday October 29, 2025 @02:08AM (#45743207)
There's a lot of code that makes assumptions about the number of bytes in a long rather than diligently using sizeof ... remember, the whole point here is low quality code.
Re:Fil-C: A memory-safe C implementation by kbolino on Wednesday October 29, 2025 @09:57AM (#45746913)
That seems worse.

For all the wrong code that assumes long can store a pointer, there's likely a lot more wrong code that assumes long can fit in 64 bits, especially when serializing it for I/O and other-language interop.

Also, 128-bit integers can't fit in standard registers on most architectures, and don't have the full suite of ALU operations either. So you're looking at some serious code bloat and slowdowns for code using longs.

You've also now got no "standard" C type (char, short, int, long, long long) which is the "native" size of the architecture. You could widen int too, but a lot of code also assumes an int can fit in 32 bits.

Re:Fil-C: A memory-safe C implementation by ummonk on Wednesday October 29, 2025 @12:54PM (#45749588)
No, it should only do arithmetic on the first 64 (or 32) bits. The extra metadata should be copied unchanged.
Re:Fil-C: A memory-safe C implementation by kbolino on Wednesday October 29, 2025 @01:29PM (#45750188)
Ok, I think I follow. You'd widen the type under the hood but not expose this fact to user code.

However, most longs are just numbers that have no metadata. I guess you'd set the metadata portion to all zeroes in that case. This feels like a reified version of Rust's pointer provenance, and I think you would have to expose some metadata-aware operations to the user. In which case, you're inviting some code rewrites anyway.

While not as bad as the register/ALU ops issue, you're still making all code pay a storage size penalty, and still adding some overhead to handle the metadata propagating through arithmetic operations, just to accommodate bad code, plus it complicates alignment and FFI.

Re:Fil-C: A memory-safe C implementation by ummonk on Wednesday October 29, 2025 @02:24PM (#45750992)
It would still be exposed to user code that checks its size with sizeof, but yeah the long would only have numerical values between 2^-63 and 2^63-1.

And yes, there would still be some overhead for storing and propagating the metadata, and struct alignment would change and FFI wouldn't work with longs.

Re:Fil-C: A memory-safe C implementation by ummonk on Thursday October 30, 2025 @07:35AM (#45758881)
Err I meant -2^63, that’s embarrassing.
Re:Fil-C: A memory-safe C implementation by kragen on Saturday November 01, 2025 @11:11AM (#45782266)
Heh. I missed that.
Re:Fil-C: A memory-safe C implementation by 1718627440 on Thursday October 30, 2025 @04:46AM (#45757724)
Why not assume it fits into an uintptr_t, which is the type for exactly this purpose?
Re:Fil-C: A memory-safe C implementation by conradev on Tuesday October 28, 2025 @05:49PM (#45739672)
and the author of Fil-C worked on that!
Re:Fil-C: A memory-safe C implementation by kragen on Tuesday October 28, 2025 @05:51PM (#45739692)
Oh, somehow I missed that connection!
Re:Fil-C: A memory-safe C implementation by astrange on Tuesday October 28, 2025 @05:07PM (#45739198)
A descendent of this is in clang as -fbounds-safety.
Re:Fil-C: A memory-safe C implementation by pjmlp on Wednesday October 29, 2025 @04:46AM (#45744272)
That is basically clang getting something like MSVC SAL, the more the merrier.
Re:Fil-C: A memory-safe C implementation by EPWN3D on Tuesday October 28, 2025 @08:25PM (#45741127)
You don't even need to reverse it. It's in the public clang, and I'm working on helping my team adopt it in some test cases.

And it's not just the bounds-checking that's great -- it makes a bunch of C anti-patterns much harder, and it makes you think a lot harder about pointer ownership and usage. Really a great addition to the language, and it's source-compatible with empty macro-definitions (with two exceptions).

Re:Fil-C: A memory-safe C implementation by pizlonator on Tuesday October 28, 2025 @11:33PM (#45742314)
> It's in the public clang

I think you’re thinking of something else

Re:Fil-C: A memory-safe C implementation by debugnik on Wednesday October 29, 2025 @03:58AM (#45743934)
It or something similar has apparently been upstreamed to clang as -fbounds-safety. I don't know if they're the same, but the RFC on -fbounds-safety does give some credit to the author of Fil-C, who also took credit for firebloom on this thread as well.
Re:Fil-C: A memory-safe C implementation by pizlonator on Wednesday October 29, 2025 @08:30AM (#45745961)
Not the same
Re:Fil-C: A memory-safe C implementation by debugnik on Wednesday October 29, 2025 @06:15PM (#45753798)
Thanks for clarifying, I had found a past HN comment stating they are the same.
Re:Fil-C: A memory-safe C implementation by kragen on Tuesday October 28, 2025 @08:35PM (#45741184)
Interesting! How do you get started?
Re:Fil-C: A memory-safe C implementation by EPWN3D on Friday October 31, 2025 @09:39AM (#45771861)
Re:Fil-C: A memory-safe C implementation by pjmlp on Wednesday October 29, 2025 @04:45AM (#45744262)
Not for much longer, replacing it with Swift is one of the reasons why Swift Embedded subset came to be.

"Why Embedded Swift"

https://youtu.be/LqxbsADqDI4?t=144