
Verify Hardening in an ELF With readelf
Write a shell script that uses readelf and nm to fail a build when an ELF binary lacks PIE, full RELRO, a non-executable stack, a stack canary or CET notes.
Everything you need to level up your coding skills.

Write a shell script that uses readelf and nm to fail a build when an ELF binary lacks PIE, full RELRO, a non-executable stack, a stack canary or CET notes.

Define a default function with __attribute__((weak)) so another object file can replace it at link time, and check optional symbols with weak references.

Add stack protector, fortify, PIE, full RELRO and CET flags to a CMake 3.28 project with feature checks, per-target options and a verification step.

Use __attribute__((section)) to put functions and variables in named ELF sections, then walk the section with the linker's start and stop symbols.

A curated set of GCC and Clang warnings, from -Wformat=2 and -Wstringop-overflow to -Wvla and -Wconversion, that flag memory-safety bugs before they ship.

Raise the alignment of variables, structs and heap buffers with __attribute__((aligned(n))), alignas and aligned_alloc for cache lines, SIMD and DMA.

Turn on _FORTIFY_SOURCE=3 with -O2 on glibc 2.33 or later and see which libc calls get bounds checks, how level 3 differs from 2 and what it cannot catch.

Remove struct padding with __attribute__((packed)) to match a wire format, then see the unaligned-access cost, the pointer warning and the memcpy alternative.

Copy .data from flash and zero .bss in a Cortex-M reset handler without bugs: alignment, the memset trap, empty sections and a debugger check to run.

Declare a logging function with __attribute__((format(printf, ...))) so GCC and Clang check each call's format and arguments, and pair it with vsnprintf.

Declare a function that calls exit or abort as noreturn so GCC drops dead code, silences false warnings and lays out the error path correctly.

Put code, constants, variables and zeroed buffers into the right ELF sections in NASM and GNU as, and see how segments and permissions follow from them.
We send one email when a new post is published. No spam.