Write a Blog >>

Garbage collection (GC) for C is challenging due to two reasons – it is \emph{imprecise} because of the difficulty in differentiating pointers from non-pointers in the absence of typing guarantees and runtime type information, and, it is \emph{unsound} because C allows for unsafe pointer manipulations that can hide pointer values from a collector and later recover them. While prior work has addressed type-accurate precise GC, C remains generally unsafe for GC. We present a novel provenance based GC that dynamically tracks the \emph{pointer provenance} metadata of pointer-derived values throughout an execution, and then prevents GC from collecting objects accessible via them. Our pointer provenance propagation rules are designed to reduce the metadata state and its tracking overheads for common operations on pointers. We further optimize the analysis using optimistic hybrid analysis (OHA), and integrate the optimized Pointer Provenance Tracking analysis with conservative GC for C. The modified GC is \emph{safe} in the sense that it does not collect an object whose pointer can later be recovered using C pointer manipulations. Our GC tool evaluated for a suite of large applications imparts practical overheads while ensuring GC safety.