In this article I discuss how memory arenas interact with strict type aliasing in C, and how to use the clang type sanitizer to check compliance.Table of contentsRequirementsStrict aliasingMemory arenasArenas and aliasingType sanitizerRequirementsWe will need GNU libc based Linux system with the clang C compiler. If you are running a non-GNU system, e.g. one using musl libc, then you can simply install clang within a GNU chroot.Strict aliasing in CAccording to the C standard, it is never valid to read memory through a pointer of type T *ptr if the type of the object is not compatible with T (unless T is a character type, e.g. char). Here an object refers to either a variable (e.g. for int x;, the object at &x in memory has type int), or a location in untyped memory (e.g. memory returned by malloc) where a value has been written (e.g. int *x = malloc(sizeof(int)); *x=1; gives the object at x type int).Common practices forbidden by the strict aliasing rule include type punning through…
No comments yet. Log in to reply on the Fediverse. Comments will appear here.