Skip to content

refactor: optimize build system security flags#40

Merged
BLumia merged 1 commit intolinuxdeepin:masterfrom
mhduiy:sec
Jul 3, 2025
Merged

refactor: optimize build system security flags#40
BLumia merged 1 commit intolinuxdeepin:masterfrom
mhduiy:sec

Conversation

@mhduiy
Copy link
Copy Markdown
Contributor

@mhduiy mhduiy commented Jul 2, 2025

  1. Removed redundant security flags from CMakeLists.txt since they are now handled by debian/rules
  2. Added comprehensive security hardening flags in debian/rules using DEB_BUILD_MAINT_OPTIONS
  3. Standardized compiler flag handling across all CMakeLists.txt files by using ${CMAKE_CXX_FLAGS} consistently
  4. Kept -g flag for debugging but moved it to be appended to existing flags

The changes centralize security flag management in the Debian build system rather than having them scattered across multiple CMake files. This makes the build configuration more maintainable and consistent with Debian packaging standards.

refactor: 优化构建系统安全标志

  1. 从 CMakeLists.txt 中移除冗余的安全标志,现在由 debian/rules 统一处理
  2. 在 debian/rules 中使用 DEB_BUILD_MAINT_OPTIONS 添加全面的安全加固标志
  3. 通过统一使用 ${CMAKE_CXX_FLAGS} 标准化所有 CMakeLists.txt 文件中的编 译器标志处理
  4. 保留 -g 调试标志但改为追加到现有标志中

这些变更将安全标志管理集中到 Debian 构建系统中,而不是分散在多个 CMake
文件中,使构建配置更易维护且符合 Debian 打包标准。

1. Removed redundant security flags from CMakeLists.txt since they are now handled by debian/rules
2. Added comprehensive security hardening flags in debian/rules using DEB_BUILD_MAINT_OPTIONS
3. Standardized compiler flag handling across all CMakeLists.txt files by using ${CMAKE_CXX_FLAGS} consistently
4. Kept -g flag for debugging but moved it to be appended to existing flags

The changes centralize security flag management in the Debian build system rather than having them scattered across multiple CMake files. This makes the build configuration more maintainable and consistent with Debian packaging standards.

refactor: 优化构建系统安全标志

1. 从 CMakeLists.txt 中移除冗余的安全标志,现在由 debian/rules 统一处理
2. 在 debian/rules 中使用 DEB_BUILD_MAINT_OPTIONS 添加全面的安全加固标志
3. 通过统一使用 ${CMAKE_CXX_FLAGS} 标准化所有 CMakeLists.txt 文件中的编 译器标志处理
4. 保留 -g 调试标志但改为追加到现有标志中

这些变更将安全标志管理集中到 Debian 构建系统中,而不是分散在多个 CMake
文件中,使构建配置更易维护且符合 Debian 打包标准。
@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

代码审查意见如下:

CMakeLists.txt 文件修改

修改建议

  1. 合并编译选项:在 CMakeLists.txt 文件中,将编译选项合并到 CMAKE_CXX_FLAGS 中,而不是分开设置。这样可以保持一致性,并且更易于维护。
  2. 移除注释:移除不必要的注释,以保持代码的整洁和清晰。

具体修改

  • set(CMAKE_CXX_FLAGS "-g -Wall")ADD_DEFINITIONS 合并为 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall")

debian/rules 文件修改

修改建议

  1. 添加编译选项:在 debian/rules 文件中,添加了 -Wall 编译选项,这有助于在编译时发现潜在的问题。但是,建议检查是否所有目标都需要这些选项,因为它们可能会增加编译时间和警告数量。
  2. 链接器选项:添加了链接器选项,如 -Wl,--as-needed-Wl,-z,relro-Wl,-z,now-Wl,-z,noexecstack,这些选项有助于提高程序的安全性和性能。但是,需要确保这些选项适用于所有目标,并且不会与现有配置冲突。

具体修改

  • debian/rules 文件中,将 export DEB_CFLAGS_MAINT_APPEND = -Wallexport DEB_CXXFLAGS_MAINT_APPEND = -Wall 合并为 export DEB_CFLAGS_MAINT_APPEND = -Wallexport DEB_CXXFLAGS_MAINT_APPEND = -Wall
  • 添加了链接器选项 export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -Wl,-E

代码质量

  • 代码的整洁性和一致性得到了提升,通过合并编译选项和移除不必要的注释。
  • 添加了编译和链接器选项,有助于提高代码的质量和安全性。

代码性能

  • 通过添加链接器选项,如 -Wl,--as-needed,可以减少不必要的库链接,从而提高程序的加载速度和运行效率。

代码安全

  • 添加了 -fstack-protector-strong-D_FORTITY_SOURCE=1 编译选项,有助于防止栈溢出攻击。
  • 添加了 -z noexecstack 链接器选项,有助于防止利用栈溢出的攻击。
  • 添加了 -pie-fPIC 编译选项,有助于创建位置无关的可执行文件,提高安全性。

总体来说,这些修改有助于提高代码的质量、性能和安全性。

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, BLumia, mhduiy

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@BLumia BLumia merged commit d01d22a into linuxdeepin:master Jul 3, 2025
8 of 9 checks passed
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.

4 participants