fix: Fix sw64 gcc not support pie by default#701
Merged
lzwind merged 2 commits intolinuxdeepin:masterfrom Jan 7, 2026
Merged
Conversation
Add the -fPIE parameter via CMAKE_POSITION_INDEPENDENT_CODE. Add the -pie parameter via target_link_options. Log: Update compiler flags for security enhancements Bug: https://pms.uniontech.com/bug-view-339563.html
Reviewer's guide (collapsed on small PRs)Reviewer's GuideEnable position-independent code globally and add conditional PIE linker flags for GNU/Clang-built executables to fix SW64 GCC default PIE behavior and improve security. Flow diagram for updated PIE-related build configurationflowchart TD
A[Configure_CMake_project] --> B[Set_CMAKE_POSITION_INDEPENDENT_CODE_ON]
B --> C[Define_targets]
C --> D[data_transfer_target]
C --> E[dde_cooperation_transfer_target]
C --> F[dde_cooperation_target]
C --> G[daemon_compat_target]
C --> H[barrierc_target]
C --> I[barriers_target]
subgraph Compiler_detection
J[Check_CXX_COMPILER_ID]
J --> K{Is_GNU_or_Clang}
end
D --> J
E --> J
F --> J
G --> J
H --> J
I --> J
K -- yes --> L[Apply_target_link_options_-pie]
K -- no --> M[No_PIE_link_option]
L --> N[Link_executable_with_-pie]
M --> O[Link_executable_without_-pie]
B --> P[Compile_all_sources_as_PIC]
P --> N
P --> O
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:
- Enabling
CMAKE_POSITION_INDEPENDENT_CODEat the top level will make all libraries/targets (including third-party ones) build as PIC/PIE; consider scoping this only to the affected executables if that broader impact is not desired. - The repeated
target_link_options(... -pie ...)blocks could be refactored into a small helper function or global property (e.g., set once for all executables) to avoid duplication and keep the PIE configuration consistent. - The
-pietarget_link_optionsare not guarded byCMAKE_SYSTEM, so they may affect non-Linux GNU/Clang builds; consider wrapping them with a platform check (e.g., Linux/ELF-only) if that is the intended scope.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Enabling `CMAKE_POSITION_INDEPENDENT_CODE` at the top level will make all libraries/targets (including third-party ones) build as PIC/PIE; consider scoping this only to the affected executables if that broader impact is not desired.
- The repeated `target_link_options(... -pie ...)` blocks could be refactored into a small helper function or global property (e.g., set once for all executables) to avoid duplication and keep the PIE configuration consistent.
- The `-pie` `target_link_options` are not guarded by `CMAKE_SYSTEM`, so they may affect non-Linux GNU/Clang builds; consider wrapping them with a platform check (e.g., Linux/ELF-only) if that is the intended scope.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
lzwind
approved these changes
Jan 6, 2026
|
[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 |
Contributor
Author
|
/forcemerge |
|
This pr force merged! (status: unstable) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add the -fPIE parameter via CMAKE_POSITION_INDEPENDENT_CODE. Add the -pie parameter via target_link_options.
Log: Update compiler flags for security enhancements
Bug: https://pms.uniontech.com/bug-view-339563.html
Summary by Sourcery
Enable position-independent code and PIE linking across targets to address platform/toolchain compatibility and security requirements.
Enhancements: