kwk created this revision. kwk added reviewers: tbaeder, tstellar. kwk added projects: clang, lld. Herald added a subscriber: mgorny. kwk requested review of this revision. Herald added a subscriber: cfe-commits.
**This is work in progress. I'm evaluating the patch now.** This change introduces the possibility to specify a style of build-id generation that must be one of "md5", "sha1", "fast", "uuid", or "0x<hexstring>". To set this style, one can set `ENABLE_LINKER_BUILD_ID_STYLE`. Setting the style will automatically turn `ON` `ENABLE_LINKER_BUILD_ID`. The effect is that invocations of the compiler will link with `--build-id=<style>` by default, where `<style>` must be one of the above. Background: =========== Currently you can have clang invoke the linker (e.g. ld or lld) automatically with `--build-id` when the CMake boolean option `ENABLE_LINKER_BUILD_ID` is set to `ON`. There's currently no way to specify what type of build-id generation algorithm (e.g. md5, sha1, uuuid, fast) to choose by default. In [1] we can see that the default build-id generation algorithm being choosen is not large enough to because of overlaps with other build ids. An upstream bug for not choosing a different build-id generation algorithm by default is shown in [2]. [1]: https://bugzilla.redhat.com/show_bug.cgi?id=2023666 [2]: https://bugs.llvm.org/show_bug.cgi?id=44138 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D113993 Files: clang/CMakeLists.txt clang/include/clang/Config/config.h.cmake clang/lib/Driver/ToolChains/Hurd.cpp Index: clang/lib/Driver/ToolChains/Hurd.cpp =================================================================== --- clang/lib/Driver/ToolChains/Hurd.cpp +++ clang/lib/Driver/ToolChains/Hurd.cpp @@ -82,7 +82,11 @@ const std::string MultiarchTriple = getMultiarchTriple(D, Triple, SysRoot); #ifdef ENABLE_LINKER_BUILD_ID - ExtraOpts.push_back("--build-id"); + #ifdef ENABLE_LINKER_BUILD_ID_STYLE + ExtraOpts.push_back("--build-id=" ENABLE_LINKER_BUILD_ID_STYLE); + #else + ExtraOpts.push_back("--build-id"); + #endif #endif Generic_GCC::AddMultilibPaths(D, SysRoot, OSLibDir, MultiarchTriple, Paths); Index: clang/include/clang/Config/config.h.cmake =================================================================== --- clang/include/clang/Config/config.h.cmake +++ clang/include/clang/Config/config.h.cmake @@ -69,9 +69,12 @@ /* Linker version detected at compile time. */ #cmakedefine HOST_LINK_VERSION "${HOST_LINK_VERSION}" -/* pass --build-id to ld */ +/* Pass --build-id or --build-id=<style> to linker (e.g. ld or ldd) by default */ #cmakedefine ENABLE_LINKER_BUILD_ID +/* Set --build-id=<style> */ +#cmakedefine ENABLE_LINKER_BUILD_ID_STYLE "${ENABLE_LINKER_BUILD_ID_STYLE}" + /* enable x86 relax relocations by default */ #cmakedefine01 ENABLE_X86_RELAX_RELOCATIONS Index: clang/CMakeLists.txt =================================================================== --- clang/CMakeLists.txt +++ clang/CMakeLists.txt @@ -219,7 +219,23 @@ set(DEFAULT_SYSROOT "" CACHE STRING "Default <path> to all compiler invocations for --sysroot=<path>." ) -set(ENABLE_LINKER_BUILD_ID OFF CACHE BOOL "pass --build-id to ld") +set(ENABLE_LINKER_BUILD_ID OFF CACHE BOOLEAN + "Pass --build-id or --build-id=<style> to linker (e.g. ld or lld). See also ENABLE_LINKER_BUILD_ID_STYLE.") + +set(ENABLE_LINKER_BUILD_ID_STYLE "" CACHE STRING + "enables ENABLE_LINKER_BUILD_ID (if not already done) and passes the style to --build-id=<style>" + +if (NOT(ENABLE_LINKER_BUILD_ID_STYLE STREQUAL "")) + if (NOT(ENABLE_LINKER_BUILD_ID)) + message(WARNING "Turning on ENABLE_LINKER_BUILD_ID because ENABLE_LINKER_BUILD_ID_STYLE style was specified") + set(ENABLE_LINKER_BUILD_ID ON) + endif() + if (NOT("${ENABLE_LINKER_BUILD_ID_STYLE}" MATCHES "^(fast|md5|sha1|uuid|0x[0-9A-Fa-f]+)$")) + message(WARNING "Allowed values for ENABLE_LINKER_BUILD_ID_STYLE are " +"\"sha1\", \"md5\" or \"uuid\", \"fast\","\"0x<hexstring>\" " +but the current value is: ${ENABLE_LINKER_BUILD_ID_STYLE}") + endif() +endif() set(ENABLE_X86_RELAX_RELOCATIONS ON CACHE BOOL "enable x86 relax relocations by default")
Index: clang/lib/Driver/ToolChains/Hurd.cpp =================================================================== --- clang/lib/Driver/ToolChains/Hurd.cpp +++ clang/lib/Driver/ToolChains/Hurd.cpp @@ -82,7 +82,11 @@ const std::string MultiarchTriple = getMultiarchTriple(D, Triple, SysRoot); #ifdef ENABLE_LINKER_BUILD_ID - ExtraOpts.push_back("--build-id"); + #ifdef ENABLE_LINKER_BUILD_ID_STYLE + ExtraOpts.push_back("--build-id=" ENABLE_LINKER_BUILD_ID_STYLE); + #else + ExtraOpts.push_back("--build-id"); + #endif #endif Generic_GCC::AddMultilibPaths(D, SysRoot, OSLibDir, MultiarchTriple, Paths); Index: clang/include/clang/Config/config.h.cmake =================================================================== --- clang/include/clang/Config/config.h.cmake +++ clang/include/clang/Config/config.h.cmake @@ -69,9 +69,12 @@ /* Linker version detected at compile time. */ #cmakedefine HOST_LINK_VERSION "${HOST_LINK_VERSION}" -/* pass --build-id to ld */ +/* Pass --build-id or --build-id=<style> to linker (e.g. ld or ldd) by default */ #cmakedefine ENABLE_LINKER_BUILD_ID +/* Set --build-id=<style> */ +#cmakedefine ENABLE_LINKER_BUILD_ID_STYLE "${ENABLE_LINKER_BUILD_ID_STYLE}" + /* enable x86 relax relocations by default */ #cmakedefine01 ENABLE_X86_RELAX_RELOCATIONS Index: clang/CMakeLists.txt =================================================================== --- clang/CMakeLists.txt +++ clang/CMakeLists.txt @@ -219,7 +219,23 @@ set(DEFAULT_SYSROOT "" CACHE STRING "Default <path> to all compiler invocations for --sysroot=<path>." ) -set(ENABLE_LINKER_BUILD_ID OFF CACHE BOOL "pass --build-id to ld") +set(ENABLE_LINKER_BUILD_ID OFF CACHE BOOLEAN + "Pass --build-id or --build-id=<style> to linker (e.g. ld or lld). See also ENABLE_LINKER_BUILD_ID_STYLE.") + +set(ENABLE_LINKER_BUILD_ID_STYLE "" CACHE STRING + "enables ENABLE_LINKER_BUILD_ID (if not already done) and passes the style to --build-id=<style>" + +if (NOT(ENABLE_LINKER_BUILD_ID_STYLE STREQUAL "")) + if (NOT(ENABLE_LINKER_BUILD_ID)) + message(WARNING "Turning on ENABLE_LINKER_BUILD_ID because ENABLE_LINKER_BUILD_ID_STYLE style was specified") + set(ENABLE_LINKER_BUILD_ID ON) + endif() + if (NOT("${ENABLE_LINKER_BUILD_ID_STYLE}" MATCHES "^(fast|md5|sha1|uuid|0x[0-9A-Fa-f]+)$")) + message(WARNING "Allowed values for ENABLE_LINKER_BUILD_ID_STYLE are " +"\"sha1\", \"md5\" or \"uuid\", \"fast\","\"0x<hexstring>\" " +but the current value is: ${ENABLE_LINKER_BUILD_ID_STYLE}") + endif() +endif() set(ENABLE_X86_RELAX_RELOCATIONS ON CACHE BOOL "enable x86 relax relocations by default")
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits