Apparently this was done intentionally. The rationale given is that we don't want to allow non-safe C to be used in fil-C programs. Fair enough.
But why should we prevent fil-C programs to be used from Rust (or C, for that matter)?
I don't understand much about compilers, but I guess allowing one would also allow the other? i.e. it's not possible to make fil-C ABI compatible with C (so that it can be more easily called), while also not letting you use call C from it?
Yes and AFAIK any fil-C program needs to be linked against fil-C compiled libraries, such as libc/musl/etc. I too would like to know what other challenges exist in making this process more automated.
You're looking too much at the complete memory safety goal; the important part here is the interop non-goal. Designing a foreign function interface between Fil-C and regular C, in a way that upholds both languages' expectations about the environment the code's running in, is a very difficult problem and nobody seems to have much of an idea of how such a thing could work.
I worry that this same problem will doom the extern "Fil-C" idea that this post advocates. Zig is not really an encouraging precedent because Zig's proposed memory-safe mode adds runtime checks to everything just like Fil-C does, whereas the post author wants to avoid those checks for Rust code that's already statically known to be memory-safe. That said, it's possible I'm missing something.
Increment the "fell for fil-C propaganda" counter.
This article fully concede's Filip's categorically incorrect definitions regarding memory safety, accepting them as true.
I don't want extern "fil-C", it legitimises Filip's bad-faith trolling and hypocrisy as an acceptable way to operate a software project, and makes rust dependent on his single ISA single OS fork of clang which is actually just granular ASAN with atomic instrumentation code and a garbage collector, fluffed up with fil's marketing terminology "invisicaps" etc.
It's not a replacement for Fil-C's role as a precise ASAN/Valgrind, but it works great if you want to call a C library without letting it freely spray caller's memory.
Fil-C is more precise than valgrind or asan. Valgrind and asan will allow a buggy access (like an OOB) to succeed if the resulting address is valid at all - which is useless from a security enforcement perspective since clobbering valid addresses is what the attacker is trying to do.
Fil-C only allows an access to succeed if it’s in bounds of that pointer’s capability. That is a useful level of precision for security, since it prevents the attacker from clobbering the addresses of their choice.
Any reason why you don't use clang's `-fbounds-safety`? It offers ABI compatibility and incremental adoption. The author of Fil-C worked on it also :-)
This would also mean that you wouldn't need unsafe{} to call into the Fil-C ffi. The majority of unsafe{} in (non pure-rust) cargo dependencies is calling C ffi. Rust + Fil-C is a great match that fills a particular niche, I'd love to see it happen.
> [...] instead of accidentally linking ordinary C into it
Out of curiosity. If you really needed to, could a language speak both the C ABI and the Fil-C ABI? As I understand Fil-C itself can't do this without having Python-like FFI overhead, but maybe a different compiler implementation could?
Hm on first reading I was confused by the extern "fil-c" framing -- that seems to imply a bridge between C and Fil-C, which introduces some nasty language/runtime inter-op issues.
But I like this part
I want a Rust FFI that speaks the Fil-C ABI. ... We could use Rust for compile-time safety and then pay a performance penalty for using C.
> But the result would give us exactly the right incentives.
Say what you say, but there's plenty in that article looking like it came out of an LLM. This could of course be my own paranoia, since there's a lot of slop coming out right now.
Extern "fil-C" can't be compatible with Rust code or something similar. It requires a metadata block attached to each allocation. So, if a memory block has been allocated in Rust and a pointer to it is passed to a fil-C function, it can't access it correctly. The only way to allow such cross-langauge-and-abi calls is to compile Rust code itself like fil-C, which requires doubled memory consumption, expensive runtime checks and GC overhead.
Even that way will be very difficult to make it work.
The Fil-C side could change the data behind the pointer, which will not reflect on the Rust side due to the copy. Even if you manage to copy back the changes, Fil-C could also persist those pointers in e.g. global memory: at that point you no longer know when it's safe to copy back (or forward) any change.
The only way I can see this work if you cannot pass any Rust-land pointers into Fil-C, but at that point you could also compile the C code to WASM and use the WASM FFI (which has similar restrictions)
LLM-written post, but I think the core idea is okay. I would advocate for more opportunities for safety, even if some of the safety is runtime safety rather than "only" Rust's borrow checker.
andai | 16 hours ago
https://fil-c.org/runtime
Apparently this was done intentionally. The rationale given is that we don't want to allow non-safe C to be used in fil-C programs. Fair enough.
But why should we prevent fil-C programs to be used from Rust (or C, for that matter)?
I don't understand much about compilers, but I guess allowing one would also allow the other? i.e. it's not possible to make fil-C ABI compatible with C (so that it can be more easily called), while also not letting you use call C from it?
Georgelemental | 16 hours ago
sheepscreek | 16 hours ago
ameliaquining | 13 hours ago
pizlonator | 15 hours ago
ameliaquining | 15 hours ago
I worry that this same problem will doom the extern "Fil-C" idea that this post advocates. Zig is not really an encouraging precedent because Zig's proposed memory-safe mode adds runtime checks to everything just like Fil-C does, whereas the post author wants to avoid those checks for Rust code that's already statically known to be memory-safe. That said, it's possible I'm missing something.
Wleddzig | 16 hours ago
This article fully concede's Filip's categorically incorrect definitions regarding memory safety, accepting them as true.
I don't want extern "fil-C", it legitimises Filip's bad-faith trolling and hypocrisy as an acceptable way to operate a software project, and makes rust dependent on his single ISA single OS fork of clang which is actually just granular ASAN with atomic instrumentation code and a garbage collector, fluffed up with fil's marketing terminology "invisicaps" etc.
ameliaquining | 15 hours ago
ModernMech | 4 hours ago
is false because of his admission here:
https://news.ycombinator.com/item?id=49097258
If “Rust isn’t [memory safe] (because unsafe)”, and “Zig isn’t (because uaf)”, then Fil-C isn't (because zunsafe_call/zunsafe_fast_call).
erichocean | 3 hours ago
> If Rust isn’t memory safe (because unsafe), and Zig isn’t (because uaf), then Fil-C isn't (because zunsafe_call/zunsafe_fast_call).
Rust isn’t memory safe (because unsafe) isn't an argument anyone makes, it's that Rust that uses unsafe isn't memory safe!
It's called `unsafe` for a reason dude, not even the Rust people think it's safe.
mirashii | 3 hours ago
This is an argument that Fil-C makes, by choosing a very specific definition of memory safety. It’s even stated explicitly in that tweet linked.
ameliaquining | an hour ago
mirashii | 45 minutes ago
But you can see in a number of his public comments statements that Rust is not memory safe by his definition because it has unsafe as an escape hatch. https://x.com/filpizlo/status/2079244258062766177 and https://news.ycombinator.com/item?id=49053608 as some examples.
pornel | 15 hours ago
https://rlbox.dev/
It's not a replacement for Fil-C's role as a precise ASAN/Valgrind, but it works great if you want to call a C library without letting it freely spray caller's memory.
pizlonator | 15 hours ago
Fil-C is more precise than valgrind or asan. Valgrind and asan will allow a buggy access (like an OOB) to succeed if the resulting address is valid at all - which is useless from a security enforcement perspective since clobbering valid addresses is what the attacker is trying to do.
Fil-C only allows an access to succeed if it’s in bounds of that pointer’s capability. That is a useful level of precision for security, since it prevents the attacker from clobbering the addresses of their choice.
KateLawson | 14 hours ago
https://clang.llvm.org/docs/BoundsSafety.html#overview
pizlonator | 14 hours ago
But it’s strictly less safe than either Fil-C or Rust since it only protects bounds
QuaternionsBhop | 14 hours ago
inigyou | 7 hours ago
aw1621107 | 4 hours ago
creatonez | 13 hours ago
Out of curiosity. If you really needed to, could a language speak both the C ABI and the Fil-C ABI? As I understand Fil-C itself can't do this without having Python-like FFI overhead, but maybe a different compiler implementation could?
throwaway27448 | 13 hours ago
chubot | 13 hours ago
Hm on first reading I was confused by the extern "fil-c" framing -- that seems to imply a bridge between C and Fil-C, which introduces some nasty language/runtime inter-op issues.
But I like this part
I want a Rust FFI that speaks the Fil-C ABI. ... We could use Rust for compile-time safety and then pay a performance penalty for using C.
nnevatie | 13 hours ago
nylonstrung | 9 hours ago
nnevatie | 8 hours ago
Say what you say, but there's plenty in that article looking like it came out of an LLM. This could of course be my own paranoia, since there's a lot of slop coming out right now.
Panzerschrek | 13 hours ago
tracnar | 8 hours ago
SkiFire13 | an hour ago
The Fil-C side could change the data behind the pointer, which will not reflect on the Rust side due to the copy. Even if you manage to copy back the changes, Fil-C could also persist those pointers in e.g. global memory: at that point you no longer know when it's safe to copy back (or forward) any change.
The only way I can see this work if you cannot pass any Rust-land pointers into Fil-C, but at that point you could also compile the C code to WASM and use the WASM FFI (which has similar restrictions)
CyberDildonics | 5 hours ago
hechang1997 | 7 hours ago
While this cannot compile C/C++, it can serve as a fil-C alternative for unsafe pure rust code.
https://news.ycombinator.com/item?id=49284966
erichocean | 3 hours ago
LoganDark | 6 hours ago
cpburns2009 | 3 hours ago
LoganDark | 3 hours ago