News for hackers. Stuff that matters.
Re:The Cerberus C semantics [pdf] by JonChesterfield on Friday May 12, 2023 @06:33PM (#35923362)
I've read the abstract, noted the enthusiasm for pointer provenance and the doctoral advisor, and jumped to my usual conclusion on this stuff.

Software that needs to be written in C, as opposed to in friendlier or more aggressively constrained languages, is that which needs to deal in hardware. Things like there's a value at absolute address k which you load from to indicate to some other part of the system that a thing has happened.

The domain is exclusively stuff that can be written in asm but it's cheaper and saner not to.

The pointer provenance strategy miscompiles enough of that domain to be unsafe to use. It interacts particularly poorly with the aliasing model that thwarts treating memory as an array of integers, or an array of atomic integers, or an array of simd types.

The end game of this "sound semantics" strategy, as favoured by WG14, is a language with zero use cases. You can't put it near hardware without fno-strict-aliasing and whatever flag turns off provenance based reasoning. You don't want to put it near anything else because C++ freestanding, D and rust are all faster and safer.

It's interesting work that can help provide sane semantics for fairly low level code. It's a real shame that it comes at the price of killing C.

Re:The Cerberus C semantics [pdf] by carbotaniuman on Friday May 12, 2023 @09:22PM (#35924510)
With provenance, it's important to remember that this is less about adopting a new model that allows miscompilations, and more about addressing current, already existing miscompilations.

Pointer provenance does nothing to stop you from accessing stuff at a fixed address, it simply justifies things that current compilers already do and will not change. For example, even if you were to guess the address of a local, pointer provenance prevents you from changing it. This enables (really basic!) optimizations like moving variables into registers.

Re:The Cerberus C semantics [pdf] by JonChesterfield on Saturday May 13, 2023 @05:16AM (#35926825)
Mem2reg works fine on variables whose addresses have not escaped. Compilers do extensive alias analysis anyway, because even given an oracle that says double* does not alias long*, you still want to work out which double*s can alias.

Type based alias analysis is a hack from separate compilation using compilers on limited hardware resources. It should be dropped as an unnecessary compromise to language expressivity, not leaned into as a law of nature.

Re:The Cerberus C semantics [pdf] by sanxiyn on Saturday May 13, 2023 @10:37AM (#35928830)
Without pointer provenance, all addresses escape. Just cast integer to pointer.

I agree strict aliasing is a relic of the past that should be abolished ASAP, but that's quite different from pointer provenance.

Re:The Cerberus C semantics [pdf] by jcranmer on Saturday May 13, 2023 @10:53AM (#35928970)
> Mem2reg works fine on variables whose addresses have not escaped.

The question of pointer provenance is really about trying to formalize a workable definition of "escape." This turns out to be far harder than it looks, because it turns out that converting a pointer to integer necessarily needs to be an escape, and all of a sudden, there are all sorts of hidden places that causes pointers to become integers that you never expected (such as storing a pointer in a stack variable, if memory is untyped).

Re:The Cerberus C semantics [pdf] by samth on Friday May 12, 2023 @11:18PM (#35925142)
I think you are confused about who is advocating what here. Pointer provenance is a real thing that has already happened and that compiler developers want. Sewell's group has been working (eg in this thesis) to put that idea on a consistent foundation, and figure out how to make it compatible with the programs you care about.
Re:The Cerberus C semantics [pdf] by JonChesterfield on Saturday May 13, 2023 @05:11AM (#35926804)
Some compiler developers want the provenance model as it allows cheaper alias analysis. Others don't as it breaks things like mmap of prebuilt hashtables.

Application level C++ developers want it too, as it makes things slightly faster without breaking anything that would get past code review.

My point of contention is with applying this to C. The main remaining uses are things like linux which can't be compiled as ISO C any more, instead requiring a bunch of compiler flags to opt out of things very like the provenance model.

I claim there are zero use cases for C with "strict aliasing" rules and the like, and adopting the application facing copy-ideas-from-C++ approach will/has killed the language. GNU C will persist for a while, ISO C serves noone well.

Re:The Cerberus C semantics [pdf] by nine_k on Saturday May 13, 2023 @08:51AM (#35927894)
Could you please give a simple practical example where pointer provenance or another similar anti-aliasing mechanism prevent a useful hardware-facing piece of code from being compiled?
Re:The Cerberus C semantics [pdf] by amluto on Saturday May 13, 2023 @09:41AM (#35928276)
> Others don't as it breaks things like mmap of prebuilt hashtables.

Can you elaborate? An mmap of prebuilt hash tables doesn’t work well in practice of the mmapped area contains pointers regardless of provenance, and an mmap of a hashtable that uses integer offsets doesn’t involve pointers.

The only real issue I see is if the mmap contains objects but isn’t itself laid out like an object in the language in question, and you need to generate a pointer to one of those objects. (So mmapping an array of structs that don’t contain pointers is fine, but mmapping a mess that contains integer offsets referencing various things in the mmap that don’t nicely line up like an array is harder.)

But I imagine that a pointer provenance system could have an operation that takes as input an mmap, an offset and a type and returns a pointer to the object with the type in question at the offset in question. It would check that the type makes sense (no pointers!) and could, if needed for the degree of safety require, also check for invalid aliasing.

Re:The Cerberus C semantics [pdf] by fanf2 on Saturday May 13, 2023 @09:17AM (#35928076)
These pointer provanance semantics are implemented by LLVM too. They also apply to C++, Rust, Zig, etc.
Re:The Cerberus C semantics [pdf] by tialaramex on Saturday May 13, 2023 @12:45PM (#35930119)
What are "these" semantics? The PDF linked describes all of both PVI and PNVI, so saying LLVM implements "these" semantics in that context would be like if you said "I dated her in college" when somebody is describing the entire US population. Maybe you did date an American in college, but I think you need to be more specific.
Re:The Cerberus C semantics [pdf] by carbotaniuman on Saturday May 13, 2023 @04:17PM (#35932288)
I think the parent was trying to say LLVM implements pointer provenance semantics in some form, as "these" semantics doesn't really make sense. As to what form LLVM implements... a weird mishmash of many semantics, with some optimizations that are contradictory with each other and some that don't make sense.

PNVI-ae-udi looks to be the one that compiler developers and the committee agree on, but we'll see if these efforts gain any more traction.

Re:The Cerberus C semantics [pdf] by UncleMeat on Saturday May 13, 2023 @04:16PM (#35932286)
Then we need to fork these languages. Maybe there are people out there who truly need a combination of zero safety and the ability to link binaries written 20 years ago. But there are also people who need the linux kernel to not be riddled with bugs.

A solution to both would be nice.