You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cmake: incorrect assumption that Debug build type will not use optimisations #30800
# When the build configuration is Debug, all optimizations are disabled.
# However, _FORTIFY_SOURCE requires that there is some level of optimization,
# otherwise it does nothing and just creates a compiler warning.
# Since _FORTIFY_SOURCE is a no-op without optimizations, do not enable it
# when the build configuration is Debug.
However that isn't always true. If, for example, depends is built with DEBUG=1, and CMake is configured with -DCMAKE_BUILD_TYPE=Debug, -O1 will actually be used. This is confusing, not just because the documentation is incorrect, but when making a change to switch the build type to Debug in oss-fuzz, it's caused unexpected results: google/oss-fuzz#12443 (comment).
Rather than assuming that builds with the Debug build type don't use optimisations, the check should be fixed to actually check what optimisation level is being used.
Not sure if this makes sense, but if the problem is that specifying _FORTIFY_SOURCE without optimizations triggers a compiler warning, maybe there should just be a check that drops _FORTIFY_SOURCE when it triggers the warning. That might avoid problems if there is a discrepancy between the way our cmake code detects optimizations and the way _FORTIFY_SOURCE implementation does.
However that isn't always true. If, for example, depends is built with DEBUG=1, and CMake is configured with -DCMAKE_BUILD_TYPE=Debug, -O1 will actually be used.
I think we should first prioritize coordinating the optimization and debugging flags between the depends subsystem and the main build system:
Should the optimization and debugging flags coincide, or are they allowed to differ?
If the optimization and debugging can differ between the depends subsystem and in the main build system, which should take precedence?
I think we should first prioritize coordinating the optimization and debugging flags between the depends subsystem and the main build system:
I'm not sure? This hardening feature should be turned on if optimisations are being used, and hardening isn't disabled. Whether or not depends flags override CMake defaults, or if depends defaults match CMake defaults seems tangential.
Not sure if this makes sense, but if the problem is that specifying _FORTIFY_SOURCE without optimizations triggers a compiler warning, maybe there should just be a check that drops _FORTIFY_SOURCE when it triggers the warning. That might avoid problems if there is a discrepancy between the way our cmake code detects optimizations and the way _FORTIFY_SOURCE implementation does.
That could be a good approach, but there's also the possiblity that FORTIFY will warn if the selected level will be treated as a lower level (i.e 3 selected, but will be treated as 2), depending on the libc, platform etc, which would cause it's usage to be inadvertantly disabled. I've opted to implement what is (hopefully) a straightforward enough check for optimisations in #30824, which is the same test used by glibc.
Activity
ryanofsky commentedon Sep 3, 2024
Not sure if this makes sense, but if the problem is that specifying _FORTIFY_SOURCE without optimizations triggers a compiler warning, maybe there should just be a check that drops _FORTIFY_SOURCE when it triggers the warning. That might avoid problems if there is a discrepancy between the way our cmake code detects optimizations and the way _FORTIFY_SOURCE implementation does.
hebasto commentedon Sep 3, 2024
I think we should first prioritize coordinating the optimization and debugging flags between the depends subsystem and the main build system:
UPD. #29796 is related.
fanquake commentedon Sep 4, 2024
I'm not sure? This hardening feature should be turned on if optimisations are being used, and hardening isn't disabled. Whether or not depends flags override CMake defaults, or if depends defaults match CMake defaults seems tangential.
fanquake commentedon Sep 5, 2024
That could be a good approach, but there's also the possiblity that FORTIFY will warn if the selected level will be treated as a lower level (i.e 3 selected, but will be treated as 2), depending on the libc, platform etc, which would cause it's usage to be inadvertantly disabled. I've opted to implement what is (hopefully) a straightforward enough check for optimisations in #30824, which is the same test used by glibc.
Merge #30824: cmake: decouple `FORTIFY_SOURCE` check from `Debug` bui…
partial Merge bitcoin#30824: cmake: decouple `FORTIFY_SOURCE` check f…
Merge #7696: backport: bitcoin#30824: cmake: decouple `FORTIFY_SOURCE…
Merge bitcoin#30824: cmake: decouple `FORTIFY_SOURCE` check from `Deb…