@@ -250,13 +250,14 @@ function(_add_variant_swift_compile_flags
250
250
endfunction ()
251
251
252
252
function (_add_variant_link_flags )
253
- set (oneValueArgs SDK ARCH BUILD_TYPE ENABLE_ASSERTIONS ANALYZE_CODE_COVERAGE DEPLOYMENT_VERSION_IOS RESULT_VAR_NAME ENABLE_LTO )
253
+ set (oneValueArgs SDK ARCH BUILD_TYPE ENABLE_ASSERTIONS ANALYZE_CODE_COVERAGE
254
+ DEPLOYMENT_VERSION_IOS RESULT_VAR_NAME ENABLE_LTO LTO_OBJECT_NAME )
254
255
cmake_parse_arguments (LFLAGS
255
256
""
256
257
"${oneValueArgs} "
257
258
""
258
259
${ARGN} )
259
-
260
+
260
261
if ("${LFLAGS_SDK} " STREQUAL "" )
261
262
message (FATAL_ERROR "Should specify an SDK" )
262
263
endif ()
@@ -294,6 +295,19 @@ function(_add_variant_link_flags)
294
295
"${SWIFT_ANDROID_NDK_PATH} /sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_shared.so" )
295
296
else ()
296
297
list (APPEND result "-lobjc" )
298
+
299
+ # If lto is enabled, we need to add the object path flag so that the LTO code
300
+ # generator leaves the intermediate object file in a place where it will not
301
+ # be touched. The reason why this must be done is that on OS X, debug info is
302
+ # left in object files. So if the object file is removed when we go to
303
+ # generate a dsym, the debug info is gone.
304
+ if (LFLAGS_ENABLE_LTO )
305
+ precondition (LFLAGS_LTO_OBJECT_NAME
306
+ MESSAGE "Should specify a unique name for the lto object" )
307
+ set (lto_object_dir ${CMAKE_CURRENT_BINARY_DIR} /${CMAKE_CFG_INTDIR} )
308
+ set (lto_object ${lto_object_dir} /${LFLAGS_LTO_OBJECT_NAME}-lto.o )
309
+ list (APPEND result "-Wl,-object_path_lto,${lto_object} " )
310
+ endif ()
297
311
endif ()
298
312
299
313
if (NOT "${SWIFT_${LFLAGS_SDK} _ICU_UC}" STREQUAL "" )
@@ -932,6 +946,7 @@ function(_add_swift_library_single target name)
932
946
ENABLE_ASSERTIONS "${enable_assertions} "
933
947
ANALYZE_CODE_COVERAGE "${analyze_code_coverage} "
934
948
ENABLE_LTO "${lto_type} "
949
+ LTO_OBJECT_NAME "${target} -${SWIFTLIB_SINGLE_SDK} -${SWIFTLIB_SINGLE_ARCHITECTURE} "
935
950
DEPLOYMENT_VERSION_IOS "${SWIFTLIB_DEPLOYMENT_VERSION_IOS} "
936
951
RESULT_VAR_NAME link_flags
937
952
)
@@ -1643,6 +1658,7 @@ function(_add_swift_executable_single name)
1643
1658
BUILD_TYPE "${CMAKE_BUILD_TYPE} "
1644
1659
ENABLE_ASSERTIONS "${LLVM_ENABLE_ASSERTIONS} "
1645
1660
ENABLE_LTO "${SWIFT_TOOLS_ENABLE_LTO} "
1661
+ LTO_OBJECT_NAME "${name} -${SWIFTEXE_SINGLE_SDK} -${SWIFTEXE_SINGLE_ARCHITECTURE} "
1646
1662
ANALYZE_CODE_COVERAGE "${SWIFT_ANALYZE_CODE_COVERAGE} "
1647
1663
RESULT_VAR_NAME link_flags )
1648
1664
0 commit comments