Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-13631] Add CMake options + build-script flag to turn off linker optimizations #56066

Closed
typesanitizer opened this issue Sep 30, 2020 · 4 comments
Labels

Comments

@typesanitizer
Copy link

Previous ID SR-13631
Radar rdar://problem/69768708
Original Reporter @typesanitizer
Type Improvement
Status Closed
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Project Infrastructure
Labels Improvement, StarterBug
Assignee mininny (JIRA)
Priority Medium

md5: 2fe271a48791ae85b5f8c0537041d016

Issue Description:

1. Add a build-script flag to turn off dead stripping (no-op on non-Darwin platform).
2. Pass it down to CMake and use it to turn off dead-stripping in the code below.
3. Suggest this flag in the getting started guide; debugging with a RelWithDebInfoAssert build should improve after turning this on because debugging-only functions like the various dump() methods should not be getting optimized out.

  if(NOT CMAKE_BUILD_TYPE STREQUAL Debug)
    if(CMAKE_SYSTEM_NAME MATCHES Darwin)
      # See rdar://48283130: This gives 6MB+ size reductions for swift and
      # SourceKitService, and much larger size reductions for sil-opt etc.
      target_link_options(${target} PRIVATE
        "SHELL:-Xlinker -dead_strip")
    endif()
  endif()

Strictly speaking, part 1 is optional as build-script already has a --extra-cmake-options flag.

@typesanitizer
Copy link
Author

@swift-ci create

@swift-ci
Copy link
Collaborator

Comment by Minhyuk Kim (JIRA)

I've been trying to implement this, but I'm struggling because I'm not seeing much of a difference on the console output after making the changes to the build process. Can you give me any guidance on how to debug the changes I make on CMake through Logs or something? 🙂

@typesanitizer
Copy link
Author

For CMake itself, you can use print debugging using MESSAGE (https://cmake.org/cmake/help/latest/command/message.html).

Once CMake has finished running, if you look at the generated build.ninja (under $BUILD_DIR/swift-macosx-x86_64), you will see some stuff like:

build bin/swift-frontend: # other stuff
  FLAGS = ...
  LINK_FLAGS = ...  

In the LINK_FLAGS, you should see -Xlinker -dead_strip for non-debug builds; this should go away when your new flag is passed.

@swift-ci
Copy link
Collaborator

Comment by Minhyuk Kim (JIRA)

Thanks for the guide theindigamer (JIRA User)! 🙂

I created a PR here!

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants