# _FORTIFY_SOURCE

> preprocessor flag to use fortified implentations

**Wikidata**: [Q115952956](https://www.wikidata.org/wiki/Q115952956)  
**Wikipedia**: [English](https://en.wikipedia.org/wiki/FORTIFY_SOURCE)  
**Source**: https://4ort.xyz/entity/fortify-source

## Summary
_FORTIFY_SOURCE is a C/C++ preprocessor flag that enables “fortified” implementations of certain functions to help detect problems at runtime. It is classified as a runtime error detection mechanism because it can report defects during program execution. It is used in multiple C library implementations, including the GNU C Library, Bionic, and Newlib.

## Key Facts
- _FORTIFY_SOURCE is a preprocessor flag used to enable fortified implementations of functions.
- _FORTIFY_SOURCE is an instance of runtime error detection (a method that analyzes software as it executes and reports detected defects during execution).
- The inception year of _FORTIFY_SOURCE is 2004.
- _FORTIFY_SOURCE is part of the GNU C Library (glibc).
- _FORTIFY_SOURCE is part of Bionic.
- _FORTIFY_SOURCE is part of Newlib.
- _FORTIFY_SOURCE is compatible with the GNU Compiler Collection (GCC).
- _FORTIFY_SOURCE has documented compatibility work toward parity with LLVM/Clang (referenced by Red Hat: https://developers.redhat.com/blog/2020/02/11/toward-_fortify_source-parity-between-clang-and-gcc).
- Known aliases include `-D_FORTIFY_SOURCE`, “fortify source”, and `___builtin_object_size`.
- An English-language description is available at https://maskray.me/blog/2022-11-06-fortify-source#more.

## FAQs
### Q: What is _FORTIFY_SOURCE used for?
A: _FORTIFY_SOURCE is used to enable fortified implementations of functions via a preprocessor flag. It is associated with runtime error detection, meaning it can help report certain defects while a program is running.

### Q: Which C libraries include _FORTIFY_SOURCE?
A: _FORTIFY_SOURCE is listed as part of the GNU C Library, Bionic, and Newlib. These are C library implementations where the flag is used to enable fortified behavior.

### Q: Is _FORTIFY_SOURCE compatible with GCC and Clang/LLVM?
A: _FORTIFY_SOURCE is compatible with the GNU Compiler Collection (GCC). There is also documented work toward _FORTIFY_SOURCE parity between Clang/LLVM and GCC (see the referenced Red Hat article).

### Q: When was _FORTIFY_SOURCE introduced?
A: The inception year for _FORTIFY_SOURCE is 2004.

## Why It Matters
_FORTIFY_SOURCE matters because it provides a standardized, flag-driven way to enable fortified implementations that support runtime error detection. In practice, this positions it as a tool for improving software robustness by helping detect certain defects during execution rather than only relying on compile-time checks or post hoc debugging. Its inclusion across multiple C library implementations—GNU C Library, Bionic, and Newlib—indicates it is relevant in more than one ecosystem and can be encountered in a range of environments that rely on those libraries. Compatibility with GCC and ongoing attention to parity with LLVM/Clang further underscores its practical importance for real-world toolchains. For developers and maintainers, _FORTIFY_SOURCE is a notable lever in the build configuration space: it is activated as a preprocessor flag (commonly expressed as `-D_FORTIFY_SOURCE`) and is tied to the broader goal of runtime defect detection.

## Notable For
- Being explicitly classified as a runtime error detection mechanism.
- Being implemented across multiple C libraries (GNU C Library, Bionic, and Newlib).
- Having an inception year of 2004.
- Being compatible with GCC and having documented efforts toward LLVM/Clang parity.
- Being commonly referenced via build-flag and related aliases such as `-D_FORTIFY_SOURCE` and `___builtin_object_size`.

## Body
### Definition and Classification
- _FORTIFY_SOURCE is described as a “preprocessor flag to use fortified implementations.”
- It is an instance of **runtime error detection**.
  - Runtime error detection is defined here as a software verification method that analyzes an application as it executes and reports defects detected during execution.

### Names and Aliases
- Aliases associated with _FORTIFY_SOURCE include:
  - `-D_FORTIFY_SOURCE`
  - “fortify source”
  - `___builtin_object_size`

### Ecosystem and Where It Appears
- _FORTIFY_SOURCE is listed as part of:
  - GNU C Library (glibc)
  - Bionic
  - Newlib

### Toolchain Compatibility
- _FORTIFY_SOURCE is compatible with:
  - GNU Compiler Collection (GCC)
  - LLVM (with a cited reference discussing parity efforts between Clang and GCC: https://developers.redhat.com/blog/2020/02/11/toward-_fortify_source-parity-between-clang-and-gcc)

### Historical Note
- Inception: **2004**

### Further Reading (Provided Sources)
- English-language article: https://maskray.me/blog/2022-11-06-fortify-source#more
- LLVM/GCC parity discussion (reference): https://developers.redhat.com/blog/2020/02/11/toward-_fortify_source-parity-between-clang-and-gcc

## References

1. [Source](https://developers.redhat.com/blog/2020/02/11/toward-_fortify_source-parity-between-clang-and-gcc)