r260742 - [CMake] Improve the clang order-file generation workflow
ChrisBieneman via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 16 22:36:27 PST 2016
Ugh... That is most scary. Do you happen to know if this occurred with Gold, GNU ld or both? I had tested this patch on Darwin, FreeBSD and Linux with GNU ld. For that error to happen it means that the linker isn't handling -order_file as an invalid argument instead it is treating it as a "-o" argument.
My gut reaction to fix this is probably to do a check for what linker you're using, and only enable this on linkers that are known to support the -order_file flag. It is really unfortunate that the capabilities check is passing even though the flag is being mis-interpreted.
-Chris
> On Feb 16, 2016, at 6:24 PM, Chandler Carruth <chandlerc at google.com> wrote:
>
> FYI, I had to revert this in r261054 because it caused Linux links to write the output to 'rder_file' in all cases. See that commit for some details, and I think several build bots hit this as well. Happy to chat to help figure out what to do long term.
>
> -Chandler
>
>> On Fri, Feb 12, 2016 at 1:41 PM Chris Bieneman via cfe-commits <cfe-commits at lists.llvm.org> wrote:
>> Author: cbieneman
>> Date: Fri Feb 12 15:36:55 2016
>> New Revision: 260742
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=260742&view=rev
>> Log:
>> [CMake] Improve the clang order-file generation workflow
>>
>> Summary:
>> This commit re-lands r259862. The underlying cause of the build breakage was an incorrectly written capabilities test. In tools/Driver/CMakeLists.txt I was attempting to check if a linker flag worked, the test was passing it to the compiler, not the linker. CMake doesn't have a linker test, so we have a hand-rolled one.
>>
>> Original Patch Review: http://reviews.llvm.org/D16896
>>
>> Original Summary:
>> With this change generating clang order files using dtrace uses the following workflow:
>>
>> cmake <whatever options you want>
>>
>> ninja generate-order-file
>>
>> ninja clang
>>
>> This patch works by setting a default path to the order file (which can be overridden by the user). If the order file doesn't exist during configuration CMake will create an empty one.
>>
>> CMake then ties up the dependencies between the clang link job and the order file, and generate-order-file overwrites CLANG_ORDER_FILE with the new order file.
>>
>> Reviewers: bogner
>>
>> Subscribers: cfe-commits
>>
>> Differential Revision: http://reviews.llvm.org/D16999
>>
>> Modified:
>> cfe/trunk/CMakeLists.txt
>> cfe/trunk/tools/driver/CMakeLists.txt
>> cfe/trunk/utils/perf-training/CMakeLists.txt
>>
>> Modified: cfe/trunk/CMakeLists.txt
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CMakeLists.txt?rev=260742&r1=260741&r2=260742&view=diff
>> ==============================================================================
>> --- cfe/trunk/CMakeLists.txt (original)
>> +++ cfe/trunk/CMakeLists.txt Fri Feb 12 15:36:55 2016
>> @@ -595,18 +595,24 @@ if( CLANG_INCLUDE_DOCS )
>> add_subdirectory(docs)
>> endif()
>>
>> -if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/clang.order")
>> - file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/clang.order")
>> -endif()
>> -
>> -if(CLANG_ORDER_FILE STREQUAL "${CMAKE_CURRENT_BINARY_DIR}/clang.order")
>> +# this line is needed as a cleanup to ensure that any CMakeCaches with the old
>> +# default value get updated to the new default.
>> +if(CLANG_ORDER_FILE STREQUAL "")
>> unset(CLANG_ORDER_FILE CACHE)
>> - unset(CLANG_ORDER_FILE)
>> endif()
>>
>> -set(CLANG_ORDER_FILE "" CACHE FILEPATH
>> +set(CLANG_ORDER_FILE ${CMAKE_CURRENT_BINARY_DIR}/clang.order CACHE FILEPATH
>> "Order file to use when compiling clang in order to improve startup time.")
>>
>> +if(CLANG_ORDER_FILE AND NOT EXISTS ${CLANG_ORDER_FILE})
>> + string(FIND CLANG_ORDER_FILE "${CMAKE_CURRENT_BINARY_DIR}" PATH_START)
>> + if(PATH_START EQUAL 0)
>> + file(WRITE ${CLANG_ORDER_FILE} "\n")
>> + else()
>> + message(FATAL_ERROR "Specified order file '${CLANG_ORDER_FILE}' does not exist.")
>> + endif()
>> +endif()
>> +
>> if (CLANG_BUILT_STANDALONE OR CMAKE_VERSION VERSION_EQUAL 3 OR
>> CMAKE_VERSION VERSION_GREATER 3)
>> # Generate a list of CMake library targets so that other CMake projects can
>>
>> Modified: cfe/trunk/tools/driver/CMakeLists.txt
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/CMakeLists.txt?rev=260742&r1=260741&r2=260742&view=diff
>> ==============================================================================
>> --- cfe/trunk/tools/driver/CMakeLists.txt (original)
>> +++ cfe/trunk/tools/driver/CMakeLists.txt Fri Feb 12 15:36:55 2016
>> @@ -87,8 +87,24 @@ if (APPLE)
>> set(TOOL_INFO_BUILD_VERSION)
>> endif()
>>
>> -if(CLANG_ORDER_FILE AND EXISTS CLANG_ORDER_FILE)
>> - target_link_libraries(clang "-Wl,-order_file,${CLANG_ORDER_FILE}")
>> +if(CLANG_ORDER_FILE)
>> + include(CMakePushCheckState)
>> +
>> + function(check_linker_flag flag out_var)
>> + cmake_push_check_state()
>> + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag}")
>> + check_cxx_compiler_flag("" ${out_var})
>> + cmake_pop_check_state()
>> + endfunction()
>> +
>> + # This is a test to ensure the actual order file works with the linker.
>> + check_linker_flag("-Wl,-order_file,${CLANG_ORDER_FILE}"
>> + LINKER_ORDER_FILE_WORKS)
>> +
>> + if(LINKER_ORDER_FILE_WORKS)
>> + target_link_libraries(clang "-Wl,-order_file,${CLANG_ORDER_FILE}")
>> + set_target_properties(clang PROPERTIES LINK_DEPENDS ${CLANG_ORDER_FILE})
>> + endif()
>> endif()
>>
>> if(WITH_POLLY AND LINK_POLLY_INTO_TOOLS)
>>
>> Modified: cfe/trunk/utils/perf-training/CMakeLists.txt
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/perf-training/CMakeLists.txt?rev=260742&r1=260741&r2=260742&view=diff
>> ==============================================================================
>> --- cfe/trunk/utils/perf-training/CMakeLists.txt (original)
>> +++ cfe/trunk/utils/perf-training/CMakeLists.txt Fri Feb 12 15:36:55 2016
>> @@ -55,9 +55,8 @@ if(DTRACE)
>> COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py clean ${CMAKE_CURRENT_BINARY_DIR} dtrace
>> COMMENT "Clearing old dtrace data")
>>
>> -
>> add_custom_target(generate-order-file
>> - COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py gen-order-file --binary $<TARGET_FILE:clang> --output ${CMAKE_CURRENT_BINARY_DIR}/clang.order ${CMAKE_CURRENT_BINARY_DIR}
>> + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py gen-order-file --binary $<TARGET_FILE:clang> --output ${CLANG_ORDER_FILE} ${CMAKE_CURRENT_BINARY_DIR}
>> COMMENT "Generating order file"
>> DEPENDS generate-dtrace-logs)
>> endif()
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160216/7cb5ceb0/attachment-0001.html>
More information about the cfe-commits
mailing list