GCC-LOCAL(1)
π NAME π
gcc-local β local modifications to gcc
β¨ DESCRIPTION β¨
Hey bestie π welcome to gcc-local(1), straight outta the General Commands Manual. This page is literally about the local modifications to gcc, and itβs giving βOpenBSD said weβre doing things our way.β No cap.
OpenBSD uses derivatives of gcc(1) version 4.2.1. The software comes with specific modifications for OpenBSD, and hereβs the whole list, in order:
- For the C programming language,
gccdefaults to thegnu99standard, notgnu89β slay. The-stdoption can be used to select a different language standard. gccdoes not search under/usr/localfor include files nor for libraries: as a system compiler, it only searches the system paths by default. Periodt.- On all architectures where the stack is non-executable, trampoline code marks the smallest possible area around the trampoline stub executable using
mprotect(2). - Trampoline code generation is disabled by default. Code requiring trampolines will not compile without
-ftrampolines. The warning flag-Wtrampolinescan be used to locate trampoline instances if trampoline generation is re-enabled. - The
-O2option does not include-fstrict-aliasing, as this option causes issues on some legacy code. And-fstrict-aliasingis very unsafe with code that plays tricks with casts, bypassing the already weak type system of C. Big yikes π. - The
-O2option does not include-fstrict-overflow, as this option causes issues on some legacy code.-fstrict-overflowcan cause surprising optimizations to occur, possibly deleting security critical overflow checks. That is a red flag, bestie. - The
-O2option does not include the-ftree-vrpoptimization as it is known to be broken. π gccrecognizes the extra format attributesyslog, to better match the definition ofsyslog(3), and silence erroneous warnings when used with-pedantic.gccrecognizes the attribute__nonnull__, which can be used to mark arguments that canβt beNULL. Theprintfformat attribute does not imply__nonnull__for the format. This allows for correct format checking on theerr(3)function family.gccrecognizes the extra attribute__sentinel__, which can be used to mark varargs function that need aNULLpointer to mark argument termination, likeexecl(3). This exposes latent bugs for 64-bit architectures, where a terminating0will expand to a 32-bitint, and not a full-fledged 64-bits pointer. Iykyk.- On
alpha,-mieeeis enabled by default to enable full compliance with the IEEE floating point standard, although the βinexactβ flag is not maintained. Additionally, rounding mode is dynamic. Cute. gcccomes with the βProPoliceβ stack protection extension, which is enabled by default. This extension reorders local variable declarations and adds stack consistency checks at runtime, in order to detect stack overflows, and will attempt to report the problem in the system logs by callingsyslog(3)with aLOG_CRITpriority message:"stack overflow in function XXX", and abort the faulting process. It can be turned off using the-fno-stack-protectorcommand line option. Note that the stack protector relies on some support code inlibc. Stand-alone programs not linked againstlibcmust either provide their own support bits or use the-fno-stack-protectoroption.- There is a
-fstack-protector-alloption that turns stack protection code on for all functions and disables any heuristic that flags some functions as safe. This extended checking has a moderate runtime cost though. - There is a
-fstack-protector-strongoption, similar to-fstack-protector, which includes additional functions to be protected β those that have local array definitions or have references to local frame addresses.
- There is a
- On
amd64,-msave-argscan be passed to the compiler to have functions save their register arguments on the stack, while maintaining compatibility with the System 5 AMD64 ABI. This enables tools and debuggers that understand this semantic to trivially generate stack traces that include function arguments. Obsessed. - On all architectures,
gccgenerates position-independent executables (PIEs) by default, allowing the system to load the resulting binary at a random location. This behavior can be turned off by passing-fno-pieto the compiler and-nopieto the linker. gccrecognizes a new flag which is enabled by default,-Wbounded, to perform basic checks on functions which accept buffers and sizes. An extra attribute,__bounded__, has been added to mark functions that can be checked this way.gccrecognizes a new format attribute,kprintf, to deal with the extra format arguments%b,%r, and%zused in the OpenBSD kernel. Kernel girlies rise β¨.gccdoes not store its version string in objects. This behavior can be restored with-fident.- The option
-fstack-shufflewill randomize the order of stack variables at compile time, which can be helpful to find bugs. Chaos as a debugging tool, love that for us. gccwill not move variables initialized with the value zero from the data section to the bss section. The default behaviour ofgccon other systems is to perform this action, which can be restored for OpenBSD with-fzero-initialized-in-bss.gccdoes not warn for cast expressions used as lvalues outside of-pedantic.gccdoes not warn for passing pointer arguments or assignment with different signedness outside of-pedantic. This can be re-enabled with the-Wpointer-signflag.gccrecognizes the preprocessor flag-CCthat lets comments in macros pass through to the output (except in-traditionalmode).- The warning option
-Wsystem-headers, which makesgccreport warnings in systems headers, is enabled by default. gccsupports two extra warning options:-Wframe-larger-than=N(and its non-portable alias-Wstack-larger-than-N) will report functions using more thanNbytes of stack space for their local variables. Stack space used for other purposes (such as register window saving, callee-saved registers, or outbound arguments storage) is not taken into account for this check.-Wvariable-declwill report automatic variable declarations whose size cannot be determined at compile-time.
gcchas backported support for the GCC binary integer constants extension, which was first introduced ingcc4.3.- The behavior of
-Wshadowingcchas been altered to behave similarly togcc4.8and not warn about variables or parameters that shadow a global function unless the variable or parameter is of type pointer-to-function.
π§ ATTRIBUTES π§
The __bounded__ attribute is used to type-check functions whose parameters pass fixed-length buffers and their sizes. The syntax for normal buffers is:
__attribute__((__bounded__(__buffer__, buffer, length)))
where buffer contains the parameter number (starting from 1) of the pointer to the buffer, and length contains the parameter number of the buffer length argument.
gcc will emit a warning if the length argument is a constant larger than the actual size of the buffer. If the buffer is not a statically declared array of fixed length, no warnings will be generated. Refer to memcpy(3) for an example of a function with this check.
For checking strings, just use __string__ instead of __buffer__:
__attribute__((__bounded__(__string__, buffer, length)))
In addition to the checks described above, this also tests if the length argument was wrongly derived from a sizeof(void *) operation. strlcpy(3) is a good example of a string function with this check.
If a function needs string checking like __string__ but operates on element counts rather than buffer sizes, use __wcstring__:
__attribute__((__bounded__(__wcstring__, buffer, count)))
An example of a string function with this check is wcslcpy(3).
Some functions specify the length as two arguments: the number of elements and the size of each element. In this case, use the __size__ attribute:
__attribute__((__bounded__(__size__, buffer, nmemb, size)))
where buffer contains the parameter number of the pointer to the buffer, nmemb contains the parameter number of the number of members, and size has the parameter number of the size of each element. The type checks performed by __size__ are the same as the __buffer__ attribute. See fread(3) for an example of this type of function.
If a function accepts a buffer parameter and specifies that it has to be of a minimum length, the __minbytes__ attribute can be used:
__attribute__((__bounded__(__minbytes__, buffer, minsize)))
where buffer contains the parameter number of the pointer to the buffer, and minsize specifies the minimum number of bytes that the buffer should be. ctime_r(3) is an example of this type of function.
If -Wbounded is specified with -Wformat, additional checks are performed on sscanf(3) format strings. The %s fields are checked for incorrect bound lengths by checking the size of the buffer associated with the format argument.
π SEE ALSO π
gcc(1)β go read that one too, bestie π
β οΈ CAVEATS β οΈ
The -Wbounded flag only works with statically allocated fixed-size buffers. Since it is applied at compile-time, dynamically allocated memory buffers and non-constant arguments are ignored.
π Thatβs the whole GCC-LOCAL(1) page! Itβs from the Debian source, dated November 18, 2025 β GCC-LOCAL(1) and out. Go compile something iconic, bestie! π«Άβ¨
π¦ where this page comes from
- nixpkgs unstable: cvs-export
- Copyright (c) 2002 Marc Espie
- Copyright (c) 2003 Anil Madhavapeddy
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms