Stuff C in 4 functions

Beej’s Guide to C See compcert and frama-c

static keyword

gcc flags -E stop after preprcoessor. #include literally includes header file -s output assembly (don’t assemble) -c output object file

suggestions for secure flags

-fsanitize=bounds fsanitize-undefined-trap-on-error

Getting the maximum of your C compiler, for security GCC’s new fortification level: The gains and costs

gcc -shared foo.o -o - makes a dynamically linkable file. You actually have to make a object file first before you do this

g++ is gcc with some appropriate flags set for C++

-lgsl is the same as -l gsl and looks in system paths for a file called libgsl.o. It automatically appends .o and lib. Very odd to my sensibilities.

-I is useful to help

Header files and prototypes actually become “code” in the sense they are entries in the object file.


The C preprocessor.

It can be run on its own

  • #include literally brings that file in. <> vs "" is a difference in what search path it uses an prioritizes.
  • #define mcpp is an alternative

It can be programmed. This is typically ill adviuced An amusing essay saying that cpp is a pureply function programminbg language

__COUNTER__ is an autoincrementing thing There are things for string concatenation


An amusing essay that make is logic programming language. It is true. The file system is the database of sorts.

There is a default makefile that is included with every make invocation if you don’t turn it off.




Dynamic Bug detection technique SoK sanitizing for security. Really interesting. Address sanitizer ASAN memory snatizier -fsanitize=memory ThreadSanitizier - detect race conditions UBSan undefine behavior sanitizer

valgrind SAFECode, and SoftBound

See also notes on CTF stuff and compilers

Shadow memory. mapping of memory to shadow memory where you can hold metadata. Guard pages - try to access an overflow and hit unmapped page, you’ll crash

fat pointers - make pointer a struct tagged pointer - use unused bits in pointer. 64 bits is too many. ALignment makes low bits unused

The state of static analysis in the GCC 12 compiler

  • -fanalyzer
  • -Wanalyzer-tainted-array-index
  • -Wanalyzer-null-dereference

Build Systems

Shake build systems a la carte

Stressing C compilers

Csmith undefined behavior canaries

a guide to undefined behavior


echo '
// hello.c
#include <stdio.h>

int main() {
  printf("hello world\n");
' > /tmp/hello.c
~/Downloads/cosmocc/bin/cosmocc -o /tmp/hello /tmp/hello.c
file /tmp/hello # /tmp/hello: DOS/MBR boot sector; partition 1 : ID=0x7f, active, start-CHS (0x0,0,1), end-CHS (0x3ff,255,63), startsector 0, 4294967295 sectors 
# what
/tmp/hello --strace
/tmp/hello --ftrace

the strace and ftrace options are cool. WHat else might go in there?

ape command for “faster”?


DieHard error resitant allocator Ptmalloc mimalloc “The other allocators are Google’s tcmalloc (tc, tag:gperftools-2.8.1) used in Chrome, Facebook’s jemalloc (je, tag:5.2.1) by Jason Evans used in Firefox and FreeBSD, the Intel thread building blocks allocator (tbb, tag:v2020.3), rpmalloc (rp,tag:1.4.1) by Mattias Jansson, the original scalable Hoard (git:d880f72) allocator by Emery Berger [1], the memory compacting Mesh (git:67ff31a) allocator by Bobby Powers et al [8], and finally the default system allocator (glibc, 2.31) (based on PtMalloc2).” tcmalloc jemalloc tbb allocator rpmalloc hoard mesh


  • First fit - scan linked list
  • next fit - avoid having to scan head where you know you won’t find a good block
  • best fit - scan entire list

A memory allocator - doug lea

Metadata is stored next to chunk

  • free,in use flags
  • size
  • pointers in free lists are often stored in same place user data would be

Bins Coalescing

Top chunk, “the wilderness”


See debuggers note

Misc Cake C23 transpiler stb single-file public domain libraries for C/C++. stb_ds is a hash table and vector The quick and practical “MSI” hash table audit of list functions instrusive linked list

Some Were Meant for C The Endurance of an Unmanageable Language

cerberus simulator of C semantics K semantics

foundations of cs kind of cool they do it in C

All kernighan and ritchie programs ACSL by example programs svcomp C programs beginner C programs book list and guide