This document is a guide for compiler and linker options that contribute to delivering reliable and secure code using native (or cross) toolchains for C and C++. The objective of compiler options hardening is to produce application binaries (executables) with security mechanisms against potential attacks and/or misbehavior.
Hardened compiler options should also produce applications that integrate well with existing platform security features in modern operating systems (OSs). Effectively configuring the compiler options also has several benefits during development such as enhanced compiler warnings, static analysis, and debug instrumentation.
This document focuses on recommended options for the GNU Compiler Collection (GCC) and Clang/LLVM, and we expect the recommendations to be applicable to other compilers based on GCC and Clang technology. In the future, we aim to expand to guide to also cover other compilers, such as Microsoft MSVC.
CC65 is a mature cross-compiler of the C programming language for the 6502 processor. Some people have tried to use it (e.g. here, here, or here) and got discouraged by the quality of the generated code, often not understanding why the code generated was slow and big. This article is aiming to show that with a few changes in the coding style you can achieve both speed and size comparable to assembly language, while still having a majority of the benefits of working in a higher-level language. This article is based on CC65 version 2.18 (April 2020) and we may expect that in the future the compiler will handle more optimizations mentioned here automatically.
This wiki is about bootstrapping systems, i.e., building up compilers and interpreters and tools from nothing. If you wanted to learn about how one might build a functional computer from the OS up, there are some resources here that talk about doing just this.
Study the complete source code for a self-hosting compiler that runs on and generates code for CP/M on the Z80 processor. No prior knowledge in the field of compiler construction is required. The T3X/0 language that is discussed and implemented in the book has its roots in Pascal and BCPL and is very simple. A full 20-page manual is contained in the book.
The reader should know at least one procedural programming language, such as C or Pascal, and at least one assembly language, ideally the one for the Z80 CPU. They should also know the basics of the CP/M operating system. For the determined autodicact a short introduction to Z80 assembly language is also included in the book.