diff --git a/lld/Common/CommonLinkerContext.cpp b/lld/Common/CommonLinkerContext.cpp --- a/lld/Common/CommonLinkerContext.cpp +++ b/lld/Common/CommonLinkerContext.cpp @@ -7,7 +7,6 @@ //===----------------------------------------------------------------------===// #include "lld/Common/CommonLinkerContext.h" -#include "lld/Common/Driver.h" #include "lld/Common/ErrorHandler.h" #include "lld/Common/Memory.h" @@ -44,11 +43,3 @@ return; delete lctx; } - -// Temporary API that forces global state cleanup between explicit calls to -// drivers. See discussion in https://reviews.llvm.org/D119049. -void lld::cleanup() { - // Delete the global context and clear the global context pointer, so that it - // cannot be accessed anymore. - CommonLinkerContext::destroy(); -} diff --git a/lld/include/lld/Common/Driver.h b/lld/include/lld/Common/Driver.h --- a/lld/include/lld/Common/Driver.h +++ b/lld/include/lld/Common/Driver.h @@ -52,11 +52,6 @@ bool link(llvm::ArrayRef args, llvm::raw_ostream &stdoutOS, llvm::raw_ostream &stderrOS, bool exitEarly, bool disableOutput); } - -// Temporary API that forces global state cleanup between explicit calls to -// drivers above. DO NOT USE - this will be replaced by safeLldMain(). See -// discussion in https://reviews.llvm.org/D119049. -void cleanup(); } // namespace lld #endif diff --git a/mlir/lib/Dialect/GPU/CMakeLists.txt b/mlir/lib/Dialect/GPU/CMakeLists.txt --- a/mlir/lib/Dialect/GPU/CMakeLists.txt +++ b/mlir/lib/Dialect/GPU/CMakeLists.txt @@ -126,11 +126,6 @@ "Building mlir with ROCm support requires the AMDGPU backend") endif() - # Ensure lld is enabled. - if (NOT "lld" IN_LIST LLVM_ENABLE_PROJECTS) - message(SEND_ERROR "lld is not enabled. Please revise LLVM_ENABLE_PROJECTS") - endif() - set(DEFAULT_ROCM_PATH "/opt/rocm" CACHE PATH "Fallback path to search for ROCm installs") target_compile_definitions(obj.MLIRGPUTransforms PRIVATE @@ -138,21 +133,9 @@ MLIR_GPU_TO_HSACO_PASS_ENABLE=1 ) - target_include_directories(obj.MLIRGPUTransforms - PRIVATE - ${MLIR_SOURCE_DIR}/../lld/include - ) - target_link_libraries(MLIRGPUOps PRIVATE - lldELF MLIRExecutionEngine MLIRROCDLToLLVMIRTranslation ) - - # Link lldELF also to libmlir.so. Create an alias that starts with LLVM - # because LINK_COMPONENTS elements are implicitly prefixed with LLVM. - add_library(LLVMAliasTolldELF ALIAS lldELF) - set_property(GLOBAL APPEND PROPERTY MLIR_LLVM_LINK_COMPONENTS AliasTolldELF) - endif() diff --git a/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp b/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp --- a/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp +++ b/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp @@ -52,8 +52,6 @@ #include "llvm/Transforms/IPO/Internalize.h" -#include "lld/Common/Driver.h" - #include using namespace mlir; @@ -435,20 +433,15 @@ } llvm::FileRemover cleanupHsaco(tempHsacoFilename); - { - static std::mutex mutex; - const std::lock_guard lock(mutex); - // Invoke lld. Expect a true return value from lld. - bool r = lld::elf::link({"ld.lld", "-shared", tempIsaBinaryFilename.c_str(), - "-o", tempHsacoFilename.c_str()}, - llvm::outs(), llvm::errs(), /*exitEarly=*/false, - /*disableOutput=*/false); - // Allow for calling the driver again in the same process. - lld::cleanup(); - if (!r) { - emitError(loc, "lld invocation error"); - return {}; - } + std::string theRocmPath = getRocmPath(); + llvm::SmallString<32> lldPath(std::move(theRocmPath)); + llvm::sys::path::append(lldPath, "llvm", "bin", "ld.lld"); + int lldResult = llvm::sys::ExecuteAndWait( + lldPath, + {"ld.lld", "-shared", tempIsaBinaryFilename, "-o", tempHsacoFilename}); + if (lldResult != 0) { + emitError(loc, "lld invocation error"); + return {}; } // Load the HSA code object.