Skip to content

fix: Fix sw64 gcc not support pie by default#701

Merged
lzwind merged 2 commits intolinuxdeepin:masterfrom
wangrong1069:pr0105
Jan 7, 2026
Merged

fix: Fix sw64 gcc not support pie by default#701
lzwind merged 2 commits intolinuxdeepin:masterfrom
wangrong1069:pr0105

Conversation

@wangrong1069
Copy link
Copy Markdown
Contributor

@wangrong1069 wangrong1069 commented Jan 5, 2026

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:

  • Enable global position-independent code generation via CMAKE_POSITION_INDEPENDENT_CODE.
  • Apply conditional -pie linker flags for GNU and Clang targets in application and third-party barrier executables.

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
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Jan 5, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Enable 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 configuration

flowchart 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
Loading

File-Level Changes

Change Details Files
Enable position-independent code (PIC/PIE) project-wide via CMake.
  • Set CMAKE_POSITION_INDEPENDENT_CODE to ON so all targets build with -fPIC/-fPIE as appropriate
  • Rely on CMake’s compiler-specific handling instead of manually specifying -fPIE per target
CMakeLists.txt
Add conditional -pie linker flags for executables when using GNU or Clang toolchains.
  • Use target_link_options with generator expressions to append -pie only for GNU/Clang C++ compilers
  • Apply the conditional -pie flag to the main dde-cooperation executables and related helper/daemon binaries
  • Extend the same behavior to bundled 3rd-party Barrier command binaries
src/apps/data-transfer/CMakeLists.txt
src/apps/dde-cooperation-transfer/CMakeLists.txt
src/apps/dde-cooperation/CMakeLists.txt
src/compat/apps/daemon/CMakeLists.txt
3rdparty/barrier/src/cmd/barrierc/CMakeLists.txt
3rdparty/barrier/src/cmd/barriers/CMakeLists.txt

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • 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.
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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot
Copy link
Copy Markdown

[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.

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

@wangrong1069
Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot
Copy link
Copy Markdown

deepin-bot Bot commented Jan 7, 2026

This pr force merged! (status: unstable)

@lzwind lzwind merged commit 81ae1e3 into linuxdeepin:master Jan 7, 2026
14 of 15 checks passed
@wangrong1069 wangrong1069 deleted the pr0105 branch January 7, 2026 01:29
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.

3 participants