chore: Update compiler flags for security enhancements#383
chore: Update compiler flags for security enhancements#383deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
Conversation
As title Log: Update compiler flags for security enhancements Bug: https://pms.uniontech.com/bug-view-342665.html
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds hardened compiler and linker flags for Release builds and removes some plugin-related install and RPATH settings from the src CMake configuration. Flow diagram for CMake build type handling and plugin install removalflowchart TD
Start[CMake configuration start]
CheckType{Build type}
Start --> CheckType
CheckType -->|Release| EnableHardening["Set HARDENING_FLAGS and append to C and CXX flags"]
EnableHardening --> SetLinkerFlags["Append -Wl,-z,relro and -Wl,-z,now to executable linker flags"]
SetLinkerFlags --> Continue[Continue CMake configuration]
CheckType -->|Not Release| Continue
Continue --> SrcCMake[src/CMakeLists.txt]
subgraph PreviousBehavior
RPathSetting["Set target property INSTALL_RPATH for BIN_NAME"]
PluginInstall1["Install LIB_NAME to DTK_QML_APP_PLUGIN_PATH"]
PluginInstall2["Install LIB_NAME to PREFIX/plugins/imageformats"]
end
SrcCMake -->|Before PR| RPathSetting
RPathSetting --> PluginInstall1
PluginInstall1 --> PluginInstall2
SrcCMake -->|After PR| End[Configuration without RPATH and plugin target installs]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider using generator expressions or CMAKE__FLAGS_RELEASE / CMAKE_EXE_LINKER_FLAGS_RELEASE instead of checking CMAKE_BUILD_TYPE == "Release", so the hardening also works correctly with multi-config generators (e.g. Ninja Multi-Config, Visual Studio).
- Appending a hard-coded set of flags (including -g and -O2) to CMAKE_CXX_FLAGS/CMAKE_C_FLAGS may override or conflict with existing toolchain or distro flags; it may be safer to limit this to the hardening-specific options only and/or use add_compile_options/add_link_options so the defaults remain intact.
- Enabling CMAKE_VERBOSE_MAKEFILE for Release builds may significantly increase log noise in normal build environments; you might want to keep this off by default and only enable it conditionally (e.g., via a cache option or for Debug builds).
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider using generator expressions or CMAKE_<LANG>_FLAGS_RELEASE / CMAKE_EXE_LINKER_FLAGS_RELEASE instead of checking CMAKE_BUILD_TYPE == "Release", so the hardening also works correctly with multi-config generators (e.g. Ninja Multi-Config, Visual Studio).
- Appending a hard-coded set of flags (including -g and -O2) to CMAKE_CXX_FLAGS/CMAKE_C_FLAGS may override or conflict with existing toolchain or distro flags; it may be safer to limit this to the hardening-specific options only and/or use add_compile_options/add_link_options so the defaults remain intact.
- Enabling CMAKE_VERBOSE_MAKEFILE for Release builds may significantly increase log noise in normal build environments; you might want to keep this off by default and only enable it conditionally (e.g., via a cache option or for Debug builds).Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
deepin pr auto review这段代码 diff 主要是对构建配置文件 以下是对这段 diff 的详细审查意见,分为语法逻辑、代码质量、代码性能和代码安全四个维度: 1. 语法逻辑
2. 代码质量
3. 代码性能
4. 代码安全这是本次修改的重点,添加的加固选项非常全面且专业。
综合改进建议
修正后的代码片段示例(针对建议1和5): if(CMAKE_BUILD_TYPE STREQUAL "Release")
message(STATUS "Enable build hardening for Release configuration.")
# set(CMAKE_VERBOSE_MAKEFILE ON) # 建议移除或按需开启
# 将长字符串拆分以提高可读性
set(HARDENING_FLAGS
"-Wdate-time"
"-D_FORTIFY_SOURCE=2"
"-g"
"-O2"
"-ffile-prefix-map=${CMAKE_SOURCE_DIR}=."
"-fstack-protector-strong"
"-fstack-clash-protection"
"-Wformat"
"-Werror=format-security"
)
# 使用 list join 或者直接拼接
string(REPLACE ";" " " HARDENING_FLAGS "${HARDENING_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${HARDENING_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${HARDENING_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,relro -Wl,-z,now")
endif() |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lzwind, wangrong1069 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
As title
Log: Update compiler flags for security enhancements
Bug: https://pms.uniontech.com/bug-view-342665.html
Summary by Sourcery
Harden the release build configuration and adjust installation settings for plugins and runtime paths.
Build: