-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cmake] Prevent test failures by disabling LTO for swift runtime #59425
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
Conversation
@swift-ci please smoke test |
@swift-ci please smoke test Linux platform |
@al45tair: Just in case you see some drawback to this approach. We build Swift as an external project of LLVM to speed up the build in our setup. When trying to enable LTO in the LLVM side, and testing Swift, the runtime is a LTO object which Gold cannot use (we use LLD for linking, but the test suite is not prepared for that). Explicitly disabling LTO for those two object libraries seems like the best idea (it also leaves them as object files in the SDK, which any linker can use). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think both of these changes should be conditional on the linker actually being gold
, since that's where the problem lies — and we don't use gold
every platform (not even every Linux platform, since Android doesn't use it).
Something like
# LTO doesn't work on gold
set(gold_no_lto)
if ("${SWIFT_USE_LINKER}" STREQUAL "gold")
set(gold_no_lto "-fno-lto")
endif()
then replace the -fno-lto
with ${gold_no_lto}
.
@al45tair Thanks for the review! I don't think it's possible to gate it with |
Hmmmm. I see. What I'm concerned about here is that we're effectively turning off LTO for Darwin because it doesn't work when you build on Linux in the manner that you're doing, even though Darwin doesn't have this problem because we don't use Unfortunately, set(swiftlib_c_compile_flags_all ${SWIFTLIB_C_COMPILE_FLAGS}) on line 2027 of if(${sdk} STREQUAL OSX)
list(APPEND swiftlib_c_compile_flags_all
${SWIFTLIB_C_COMPILE_FLAGS_OSX})
elseif(${sdk} STREQUAL IOS OR ${sdk} STREQUAL IOS_SIMULATOR)
list(APPEND swiftlib_c_compile_flags_all
${SWIFTLIB_C_COMPILE_FLAGS_IOS})
elseif(${sdk} STREQUAL TVOS OR ${sdk} STREQUAL TVOS_SIMULATOR)
list(APPEND swiftlib_c_compile_flags_all
${SWIFTLIB_C_COMPILE_FLAGS_TVOS})
elseif(${sdk} STREQUAL WATCHOS OR ${sdk} STREQUAL WATCHOS_SIMULATOR)
list(APPEND swiftlib_c_compile_flags_all
${SWIFTLIB_C_COMPILE_FLAGS_WATCHOS})
elseif(${sdk} STREQUAL LINUX)
list(APPEND swiftlib_c_compile_flags_all
${SWIFTLIB_C_COMPILE_FLAGS_LINUX})
elseif(${sdk} STREQUAL WINDOWS)
list(APPEND swiftlib_c_compile_flags_all
${SWIFTLIB_C_COMPILE_FLAGS_WINDOWS})
endif() and we need to declare the new options on line 1640, i.e. set(SWIFTLIB_multiple_parameter_options
C_COMPILE_FLAGS
C_COMPILE_FLAGS_IOS
C_COMPILE_FLAGS_OSX
C_COMPILE_FLAGS_TVOS
C_COMPILE_FLAGS_WATCHOS
C_COMPILE_FLAGS_LINUX
... Then your change will just need to add C_COMPILE_FLAGS_LINUX -fno-lto in both places. |
@al45tair I implemented the changes as you suggested. It works when I tried it building for Darwin and for Linux so I think this change should be safe. @drodriguez Could you help me smoke test this again just to make sure it also passes in upstream CI? |
@swift-ci please smoke test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Linux build failure looks unrelated to these changes. |
@swift-ci Please smoke test Linux platform |
@al45tair Would it be possible to merge this change into |
Created a different PR that cherry-picks this change to release/5.7. |
It might be possible; the issue there is that you'll have to persuade one of the branch managers that it's important enough to merge it there. |
I've pinged the branch managers (they'll get a notification anyway because you raised the PR, but it's a good idea to ask them as well). The main thing is to emphasise that this has no impact except on Linux, where it fixes a link problem. That makes it less risky to merge. |
We build a unified LLVM build with Swift and when enabling LTO, swift validation test suite fails for several ELF tests. The swift compiler defaults to the gold linker in these tests and fails to recognize bitcode files as inputs. This is also known issue for gold LTO as documented here (https://github.com/apple/swift/blob/main/lib/Driver/UnixToolChains.cpp#L166-L168). To prevent such test failures, prevent certain libraries,
swiftrt
andswiftDemangling
from compiling with LTO.