1 .\" $OpenBSD: gcc-local.1,v 1.36 2013/02/08 07:37:43 jmc Exp $
3 .\" Copyright (c) 2002 Marc Espie
4 .\" Copyright (c) 2003 Anil Madhavapeddy
6 .\" All rights reserved.
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\" notice, this list of conditions and the following disclaimer.
13 .\" 2. Redistributions in binary form must reproduce the above copyright
14 .\" notice, this list of conditions and the following disclaimer in the
15 .\" documentation and/or other materials provided with the distribution.
17 .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
18 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 .Dd $Mdocdate: February 8 2013 $
33 .Nd local modifications to gcc
38 versions 2.95.3, 3.3.6 or 4.2.1,
39 depending on machine architecture.
41 the software comes with specific modifications for
48 for include files nor for libraries:
49 as a system compiler, it only searches the system paths by default.
51 On all architectures where the stack is non-executable,
52 trampoline code marks the smallest possible area around the trampoline stub
56 Trampoline code generation is disabled by default.
57 Code requiring trampolines will not compile without
61 can be used to locate trampoline instances if trampoline generation
66 option does not include
67 .Fl fstrict-aliasing ,
68 as this option causes issues on some legacy code.
70 is very unsafe with code that plays tricks with casts, bypassing the
71 already weak type system of C.
75 option does not include
76 .Fl fstrict-overflow ,
77 as this option causes issues on some legacy code.
79 can cause surprising optimizations to occur, possibly deleting security
80 critical overflow checks.
84 option does not include the
86 optimization as it is known to be broken in
90 .Fl fno-builtin-<function>
93 and can be used without having to differentiate between
97 recognizes the extra format attribute syslog, to better match
100 and silence erroneous warnings when used with
105 recognizes the attribute
107 which can be used to mark arguments that can't be
109 The printf format attribute does not imply
112 This allows for correct format checking on the
117 recognizes the extra attribute
119 which can be used to mark varargs function that need a
121 pointer to mark argument termination, like
123 This exposes latent bugs for 64-bit architectures,
124 where a terminating 0 will expand to a 32-bit int, and not a full-fledged
132 style exceptions, and so needs extra fixes beyond the pure 2.95.3 release.
135 exceptions are also used on aviion, luna88k and mvme88k
138 On a.out platforms (i.e. vax),
140 uses a linker wrapper to write stubs that call global constructors and
144 and those calls can be traced using
145 .Fl Wl,-trace-ctors-dtors ,
151 is enabled by default to enable full compliance with
152 the IEEE floating point standard,
155 flag is not maintained.
156 Additionally, rounding mode is dynamic.
161 stack protection extension, which is enabled by default.
162 This extension reorders local variable declarations and adds stack consistency
163 checks at run time, in order to detect stack overflows, and will attempt to
164 report the problem in the system logs by calling
169 .Dq stack overflow in function XXX ,
170 and abort the faulting process.
171 It can be turned off using the
172 .Fl fno-stack-protector
174 Note that the stack protector relies on some support code in libc.
175 Stand-alone programs not linked against libc must either provide their own
176 support bits, or use the
177 .Fl fno-stack-protector
180 .Fl fstack-protector-all
181 option, that turns stack protection code on for all functions,
182 and disables any heuristic that flags some functions as safe.
183 This extended checking has a moderate runtime cost, though.
185 On the alpha, amd64, hppa, mips64, sh and sparc64 architectures,
187 generates position-independent executables
189 by default, allowing the system to load the resulting binary
190 at a random location.
191 This behavior can be turned off by passing
196 It is not supported for static executables.
199 recognizes a new flag,
201 to perform basic checks on functions which accept buffers and sizes.
204 has been added to mark functions that can be
208 recognizes a new format attribute, kprintf, to deal with the extra format
219 does not store its version string in objects.
220 This behavior can be restored with
224 will not move variables initialized with the value zero
225 from the data section to the bss section.
226 The default behaviour of
230 on other systems is to perform this action, which can be restored for
233 .Fl fzero-initialized-in-bss .
236 does not warn for cast expressions used as lvalues outside of
240 does not warn for pointer arguments passing or assignment with
241 different signedness outside of
250 recognizes the preprocessor flag
252 that lets comments in macros pass through to the output (except in
255 This is used to allow annotations in macros for
259 .Fl Wsystem-headers ,
262 report warnings in systems headers,
263 is enabled by default.
266 supports two extra warning options:
269 .Fl Wstack-larger-than- Ns Va N
270 will report functions using more than
272 bytes of stack space for their local variables.
273 Stack space used for other purposes (such as register window saving,
274 callee-saved registers, or outbound arguments storage)
275 is not taken into account for this check.
278 will report automatic variable declarations whose size cannot be
279 determined at compile-time.
285 attribute is used to type-check functions whose parameters pass fixed-length
286 buffers and their sizes.
287 The syntax for normal buffers is:
289 .Li __attribute__ ((__bounded__ (
297 contains the parameter number (starting from 1) of the pointer to the buffer,
300 contains the parameter number of the buffer length argument.
303 will emit a warning if the length argument is a constant larger than the
304 actual size of the buffer.
305 If the buffer is not a statically declared array of fixed length, no warnings
309 for an example of a function with this check.
311 For checking strings, just use
316 .Li __attribute__ ((__bounded__ (
322 In addition to the checks described above, this also tests if the
324 argument was wrongly derived from a
328 is a good example of a string function with this check.
330 Some functions specify the length as two arguments:
331 the number of elements and the size of each element.
332 In this case, use the
336 .Li __attribute__ ((__bounded__ (
345 contains the parameter number of the pointer to the buffer,
347 contains the parameter number of the number of members, and
349 has the parameter number of the size of each element.
350 The type checks performed by
357 for an example of this type of function.
359 If a function accepts a buffer parameter and specifies that it has to be of a
360 minimum length, the __minbytes__ attribute can be used:
362 .Li __attribute__ ((__bounded__ (
370 contains the parameter number of the pointer to the buffer, and
372 specifies the minimum number of bytes that the buffer should be.
374 is an example of this type of function.
380 additional checks are performed on
385 fields are checked for incorrect bound lengths by checking the size of the
386 buffer associated with the format argument.
390 .Lk http://www.research.ibm.com/trl/projects/security/ssp/
394 flag only works with statically allocated fixed-size buffers.
395 Since it is applied at compile-time, dynamically allocated memory buffers
396 and non-constant arguments are ignored.