Skip to content

clike: Unset _FORTIFY_SOURCE together with -O0 #14418

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Saur2000
Copy link

If -O2, -D_FORTIFY_SOURCE=2 and -Werror are present in, e.g., the environment's CFLAGS, then configuration tests that run the compiler will fail unexpectedly due to the use of -O0 (from get_no_optimization_args()), which is not compatible with -D_FORTIFY_SOURCE=2. To overcome this potential problem, provide -U_FORTIFY_SOURCE along with -O0.

Fixes: #14417

If -O2, -D_FORTIFY_SOURCE=2 and -Werror are present in, e.g., the
environment's CFLAGS, then configuration tests that run the compiler
will fail unexpectedly due to the use of -O0 (from
get_no_optimization_args()), which is not compatible with
-D_FORTIFY_SOURCE=2. To overcome this potential problem, provide
-U_FORTIFY_SOURCE along with -O0.

Fixes: mesonbuild#14417
@@ -171,7 +171,7 @@ def get_compile_only_args(self) -> T.List[str]:
return ['-c']

def get_no_optimization_args(self) -> T.List[str]:
return ['-O0']
return ['-O0', '-U_FORTIFY_SOURCE']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this totally break projects that are performing checks using -D_FORTIFY_SOURCE=XX?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They would already be broken due to Meson adding -O0. You cannot have -D_FORTIFY_SOURCE=X (where X > 0) together with -O0. The code in features.h that produces the warning looks like:

#if defined _FORTIFY_SOURCE && _FORTIFY_SOURCE > 0
# if !defined __OPTIMIZE__ || __OPTIMIZE__ <= 0
#  warning _FORTIFY_SOURCE requires compiling with optimization (-O)
# elif !__GNUC_PREREQ (4, 1)
...
# endif
#endif
#ifndef __USE_FORTIFY_LEVEL
# define __USE_FORTIFY_LEVEL 0
#endif

i.e., if _FORTIFY_SOURCE is defined and has a value greater than zero and you add -O0 to the compiler switches, you will get the warning and the effective fortification level used (__USE_FORTIFY_LEVEL) will be 0.

@thesamesam thesamesam self-requested a review March 27, 2025 01:57
@Saur2000 Saur2000 requested a review from eli-schwartz April 12, 2025 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Configuration may fail if -O2, -D_FORTIFY_SOURCE and -Werror are in CFLAGS or CXXFLAGS
2 participants