nhaehnle created this revision. Herald added subscribers: Moerafaat, zero9178, bzcheeseman, sdasgup3, wenzhicui, wrengr, cota, teijeong, rdzhabarov, tatianashp, msifontes, jurahul, Kayjukh, grosul1, Joonsoo, liufengdb, aartbik, mgester, arpith-jacob, antiagainst, shauheen, rriddle, mehdi_amini, s.egerton, simoncook. Herald added a reviewer: rriddle. Herald added a reviewer: antiagainst. Herald added a project: All. nhaehnle requested review of this revision. Herald added subscribers: cfe-commits, pcwang-thead, stephenneuendorffer, nicolasvasilache. Herald added projects: clang, MLIR, LLVM.
Most TableGen tools have link dependency chains of the form ${project}-tblgen -> ${project}Support -> LLVMSupport In LLVM_LINK_LLVM_DYLIB=ON builds, ${project}Support naturally links aginst LLVMSupport implicitly by linking against libLLVM-*.so, and so ${project}-tblgen ends up with a dependency on the shared library. Configuring the tool itself with DISABLE_LLVM_LINK_LLVM_DYLIB then typically leads to LLVMSupport to be also included statically, leading to duplicate definitions of symbols from LLVMSupport after the dynamic linker has done its thing. TableGen tools simply aren't that special: they can be linked dynamically just fine, and so we do that to simplify the build setup. The only exception to this rule is llvm-tblgen itself, which must be statically linked to avoid circular dependencies of the form llvm-tblgen -> llvm-shlib -> tablegen-generated files -> llvm-tblgen Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D138278 Files: clang/lib/Support/CMakeLists.txt clang/utils/TableGen/CMakeLists.txt llvm/cmake/modules/CrossCompile.cmake llvm/cmake/modules/TableGen.cmake llvm/utils/TableGen/CMakeLists.txt mlir/lib/Support/CMakeLists.txt mlir/lib/TableGen/CMakeLists.txt mlir/lib/Tools/PDLL/Parser/CMakeLists.txt mlir/lib/Tools/mlir-tblgen/CMakeLists.txt mlir/lib/Tools/tblgen-lsp-server/CMakeLists.txt
Index: mlir/lib/Tools/tblgen-lsp-server/CMakeLists.txt =================================================================== --- mlir/lib/Tools/tblgen-lsp-server/CMakeLists.txt +++ mlir/lib/Tools/tblgen-lsp-server/CMakeLists.txt @@ -12,8 +12,6 @@ ADDITIONAL_HEADER_DIRS ${MLIR_MAIN_INCLUDE_DIR}/mlir/Tools/tblgen-lsp-server - DISABLE_LLVM_LINK_LLVM_DYLIB - LINK_LIBS PUBLIC MLIRLspServerSupportLib MLIRSupport Index: mlir/lib/Tools/mlir-tblgen/CMakeLists.txt =================================================================== --- mlir/lib/Tools/mlir-tblgen/CMakeLists.txt +++ mlir/lib/Tools/mlir-tblgen/CMakeLists.txt @@ -4,8 +4,6 @@ ADDITIONAL_HEADER_DIRS ${MLIR_MAIN_INCLUDE_DIR}/mlir/Tools/mlir-tblgen - DISABLE_LLVM_LINK_LLVM_DYLIB - LINK_COMPONENTS TableGen Index: mlir/lib/Tools/PDLL/Parser/CMakeLists.txt =================================================================== --- mlir/lib/Tools/PDLL/Parser/CMakeLists.txt +++ mlir/lib/Tools/PDLL/Parser/CMakeLists.txt @@ -4,8 +4,6 @@ Lexer.cpp Parser.cpp - DISABLE_LLVM_LINK_LLVM_DYLIB - LINK_COMPONENTS Support TableGen Index: mlir/lib/TableGen/CMakeLists.txt =================================================================== --- mlir/lib/TableGen/CMakeLists.txt +++ mlir/lib/TableGen/CMakeLists.txt @@ -1,14 +1,5 @@ -# This library is unusual, since mlir-tblgen depends on it, which is -# built with DISABLE_LLVM_LINK_LLVM_DYLIB, this must also be built -# with that option. Otherwise builds with LLVM_BUILD_LLVM_DYLIB and -# LLVM_LINK_LLVM_DYLIB fail. (Note that even if this has no llvm -# component dependencies, LLVM_LINK_LLVM_DYLIB tends to introduce a -# dependence on libLLVM.so) However, it must also be linkable against -# libMLIR.so in some contexts (see unittests/Tablegen, for instance, which -# has a dependence on MLIRIR, which must depend on libLLVM.so). This works -# in this special case because this library is static. -llvm_add_library(MLIRTableGen STATIC +llvm_add_library(MLIRTableGen Argument.cpp Attribute.cpp AttrOrTypeDef.cpp @@ -30,8 +21,6 @@ Trait.cpp Type.cpp - DISABLE_LLVM_LINK_LLVM_DYLIB - ADDITIONAL_HEADER_DIRS ${MLIR_MAIN_INCLUDE_DIR}/mlir/TableGen ) Index: mlir/lib/Support/CMakeLists.txt =================================================================== --- mlir/lib/Support/CMakeLists.txt +++ mlir/lib/Support/CMakeLists.txt @@ -30,8 +30,6 @@ add_llvm_library(MLIRSupportIndentedOstream IndentedOstream.cpp - DISABLE_LLVM_LINK_LLVM_DYLIB - LINK_COMPONENTS Support ) Index: llvm/utils/TableGen/CMakeLists.txt =================================================================== --- llvm/utils/TableGen/CMakeLists.txt +++ llvm/utils/TableGen/CMakeLists.txt @@ -3,6 +3,7 @@ set(LLVM_LINK_COMPONENTS Support) add_tablegen(llvm-tblgen LLVM + DISABLE_LLVM_LINK_LLVM_DYLIB DESTINATION "${LLVM_TOOLS_INSTALL_DIR}" EXPORT LLVM AsmMatcherEmitter.cpp Index: llvm/cmake/modules/TableGen.cmake =================================================================== --- llvm/cmake/modules/TableGen.cmake +++ llvm/cmake/modules/TableGen.cmake @@ -141,7 +141,7 @@ endfunction() macro(add_tablegen target project) - cmake_parse_arguments(ADD_TABLEGEN "" "DESTINATION;EXPORT" "" ${ARGN}) + cmake_parse_arguments(ADD_TABLEGEN "DISABLE_LLVM_LINK_LLVM_DYLIB" "DESTINATION;EXPORT" "" ${ARGN}) set(${target}_OLD_LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS}) set(LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS} TableGen) @@ -152,10 +152,17 @@ set(LLVM_ENABLE_OBJLIB ON) endif() - add_llvm_executable(${target} DISABLE_LLVM_LINK_LLVM_DYLIB + set(add_executable_dylib_opt "") + if(ADD_TABLEGEN_DISABLE_LLVM_LINK_LLVM_DYLIB) + set(add_executable_dylib_opt "DISABLE_LLVM_LINK_LLVM_DYLIB") + endif() + + add_llvm_executable(${target} ${add_executable_dylib_opt} ${ADD_TABLEGEN_UNPARSED_ARGUMENTS}) set(LLVM_LINK_COMPONENTS ${${target}_OLD_LLVM_LINK_COMPONENTS}) + unset(add_executable_dylib_opt) + set(${project}_TABLEGEN "${target}" CACHE STRING "Native TableGen executable. Saves building one when cross-compiling.") Index: llvm/cmake/modules/CrossCompile.cmake =================================================================== --- llvm/cmake/modules/CrossCompile.cmake +++ llvm/cmake/modules/CrossCompile.cmake @@ -96,7 +96,7 @@ endfunction() # Sets up a native build for a tool, used e.g. for cross-compilation and -# LLVM_OPTIMIZED_TABLEGEN. Always builds in Release. +# LLVM_OPTIMIZED_TABLEGEN. Always builds in Release and with static linking. # - target: The target to build natively # - output_path_var: A variable name which receives the path to the built target # - DEPENDS: Any additional dependencies for the target Index: clang/utils/TableGen/CMakeLists.txt =================================================================== --- clang/utils/TableGen/CMakeLists.txt +++ clang/utils/TableGen/CMakeLists.txt @@ -25,6 +25,6 @@ TableGen.cpp ) -target_link_libraries(clang-tblgen PRIVATE clangSupport_tablegen) +target_link_libraries(clang-tblgen PRIVATE clangSupport) set_target_properties(clang-tblgen PROPERTIES FOLDER "Clang tablegenning") Index: clang/lib/Support/CMakeLists.txt =================================================================== --- clang/lib/Support/CMakeLists.txt +++ clang/lib/Support/CMakeLists.txt @@ -9,24 +9,7 @@ Support ) -set(clangSupport_sources - RISCVVIntrinsicUtils.cpp - ) - -add_clang_library(clangSupport ${clangSupport_sources}) - -if (NOT XCODE) - add_library(clangSupport_tablegen ALIAS obj.clangSupport) -elseif (NOT LLVM_LINK_LLVM_DYLIB) - add_library(clangSupport_tablegen ALIAS clangSupport) -else() - # Build a version of the support library that does not link against - # libLLVM-*.so, to be used by clang-tblgen. This is so clang-tblgen doesn't - # link against libLLVMSupport twice (once statically and once via - # libLLVM-*.so). - add_llvm_library(clangSupport_tablegen - BUILDTREE_ONLY STATIC DISABLE_LLVM_LINK_LLVM_DYLIB - ${clangSupport_sources}) -endif() +add_clang_library(clangSupport + RISCVVIntrinsicUtils.cpp) set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS_OLD})
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits