-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compiler guide: Add note about redefining default of FORTIFY_SOURCE #273
Conversation
See also the findings in #270. |
@@ -124,7 +124,7 @@ Table 2: Recommended compiler options that enable run-time protection mechanisms | |||
|
|||
| Compiler Flag | Supported since | Description | | |||
|:----------------------------------------------------------------------------------------- |:----------------------------------:|:-------------------------------------------------------------------------------------------- | | |||
| [`-D_FORTIFY_SOURCE=3`](#-D_FORTIFY_SOURCE=3) <br/>(requires `-O1` or higher) | GCC 12.0<br/>Clang 9.0.0[^Guelton20] | Fortify sources with compile- and run-time checks for unsafe libc usage and buffer overflows. Some fortification levels can impact performance. | | |||
| [`-D_FORTIFY_SOURCE=3`](#-D_FORTIFY_SOURCE=3) <br/>(requires `-O1` or higher, <br/> may require -U_FORTIFY_SOURCE) | GCC 12.0<br/>Clang 9.0.0[^Guelton20] | Fortify sources with compile- and run-time checks for unsafe libc usage and buffer overflows. Some fortification levels can impact performance. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer "may require prepending -U_FORTIFY_SOURCE
" to avoid the interpretation that one should specify -D_FORTIFY_SOURCE=3 -U_FORTIFY_SOURCE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -267,6 +266,8 @@ To benefit from `_FORTIFY_SOURCE` checks following requirements must be met: | |||
|
|||
If checks added by `_FORTIFY_SOURCE` detect unsafe behavior at run-time they will print an error message and terminate the application. | |||
|
|||
A default mode for FORTIFY_SOURCE may be predefined for a given compiler, for instance gcc shipped with Ubuntu 22.04 uses FORTIFY_SOURCE=2 by default. If a mode of FORTIFY_SOURCE is set on the command line which differs from the default, the compiler warns about redefining the FORTIFY_SOURCE macro. To avoid this, the predefined mode can be unset with -U_FORTIFY_SOURCE before setting the desired value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: We are capitalizing GCC elsewhere in the guide.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
In case a compiler uses a predefined default for FORTIFY_SOURCE and a different mode is set on the command line, a warning about redefining the macro is triggered. To avoid this, the default value of FORTIFY_SOURCE can be unset first before setting the desired value. Signed-off-by: Georg Kunz <[email protected]>
Signed-off-by: Georg Kunz <[email protected]>
f097d3b
to
d6d8d23
Compare
lgtm |
In case a compiler uses a predefined default for FORTIFY_SOURCE and a different mode is set on the command line, a warning about redefining the macro is triggered. To avoid this, the default value of FORTIFY_SOURCE can be unset first before setting the desired value.
Fixes #272