[PATCH] D84127: Make LLVM_ENABLE_LTO function with multi-arch values for CMAKE_OSX_ARCHITECTURES
Daniel Sanders via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 19 10:18:49 PDT 2020
dsanders created this revision.
dsanders added a reviewer: bogner.
Herald added subscribers: dexonsmith, inglorion, aprantl, mgorny.
Herald added a reviewer: JDevlieghere.
Herald added a project: LLVM.
Each ld invocation within the clang command needs a unique filename on the
-object_path_lto option so that dsymutil can extract debug info for all compiled
slices. In the current code, every slice uses the same temporary filename and
as a result only one slice of debug info ends up in the dSYM.
clang already knows how to use -object_path_file and dsymutil for multiarch
builds correctly so use that method instead. There is however a strange quirk.
clang will only do this if there is at least one non-object in the command that
performs a link (this doesn't make sense in my opinion). To work around this
we include a nearly-empty file (empty causes warnings) in the linking clang
invocation.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D84127
Files:
llvm/cmake/modules/AddLLVM.cmake
Index: llvm/cmake/modules/AddLLVM.cmake
===================================================================
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -1970,27 +1970,33 @@
set(file_ext dSYM)
endif()
- set(output_name "$<TARGET_FILE_NAME:${name}>.${file_ext}")
-
- if(LLVM_EXTERNALIZE_DEBUGINFO_OUTPUT_DIR)
- set(output_path "-o=${LLVM_EXTERNALIZE_DEBUGINFO_OUTPUT_DIR}/${output_name}")
- else()
- set(output_path "-o=${output_name}")
- endif()
if(CMAKE_CXX_FLAGS MATCHES "-flto"
OR CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE} MATCHES "-flto")
- set(lto_object ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${name}-lto.o)
+ # As long as we compile at least one file from source code, clang will
+ # invoke dsymutil on the temporary objects after lipo'ing all the slices
+ # together.
+ set(lto_src ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${name}-lto.cpp)
+ file(WRITE "${lto_src}" "extern int dummy;\n")
set_property(TARGET ${name} APPEND_STRING PROPERTY
- LINK_FLAGS " -Wl,-object_path_lto,${lto_object}")
+ LINK_FLAGS " ${lto_src}")
endif()
- if(NOT CMAKE_DSYMUTIL)
- set(CMAKE_DSYMUTIL xcrun dsymutil)
+ if(LLVM_EXTERNALIZE_DEBUGINFO_OUTPUT_DIR)
+ set(output_name "$<TARGET_FILE_NAME:${name}>.${file_ext}")
+ set(output_path "${LLVM_EXTERNALIZE_DEBUGINFO_OUTPUT_DIR}/${output_name}")
+ add_custom_command(TARGET ${name} POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E make_directory "${LLVM_EXTERNALIZE_DEBUGINFO_OUTPUT_DIR}"
+ # Remove any old versions if present
+ COMMAND ${CMAKE_COMMAND} -E rm "-rf" "${output_path}"
+ # Move the dSYM clang emitted next to the output binary where we want it
+ # to be.
+ COMMAND ${CMAKE_COMMAND} -E rename "$<TARGET_FILE:${name}>.${file_ext}"
+ "${output_path}"
+ )
endif()
add_custom_command(TARGET ${name} POST_BUILD
- COMMAND ${CMAKE_DSYMUTIL} ${output_path} $<TARGET_FILE:${name}>
- ${strip_command}
+ COMMAND ${strip_command}
)
else()
add_custom_command(TARGET ${name} POST_BUILD
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84127.279100.patch
Type: text/x-patch
Size: 2227 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200719/f15763d9/attachment.bin>
More information about the llvm-commits
mailing list