The llvm-driver, enabled with LLVM_TOOL_LLVM_DRIVER_BUILD combines many llvm executables
into one to save overall toolchain size. This patch adds the capability for lld to be part of the
llvm-driver.
Differential Revision: https://reviews.llvm.org/D127472
lld.cpp
SUPPORT_PLUGINS
+ GENERATE_DRIVER
)
export_executable_symbols_for_plugins(lld)
-target_link_libraries(lld
+function(lld_target_link_libraries target type)
+ target_link_libraries(${target} ${type} ${ARGN})
+ if (TARGET obj.${target})
+ target_link_libraries(obj.${target} ${ARGN})
+ endif()
+endfunction()
+
+lld_target_link_libraries(lld
PRIVATE
lldCommon
lldCOFF
return v;
}
-int main(int argc, const char **argv) {
+int lld_main(int argc, char **argv) {
InitLLVM x(argc, argv);
sys::Process::UseANSIEscapeCodes(true);
// Not running in lit tests, just take the shortest codepath with global
// exception handling and no memory cleanup on exit.
if (!inTestVerbosity())
- return lldMain(argc, argv, llvm::outs(), llvm::errs());
+ return lldMain(argc, const_cast<const char **>(argv), llvm::outs(),
+ llvm::errs());
Optional<int> mainRet;
CrashRecoveryContext::Enable();
inTestOutputDisabled = (i != 1);
// Execute one iteration.
- auto r = safeLldMain(argc, argv, llvm::outs(), llvm::errs());
+ auto r = safeLldMain(argc, const_cast<const char **>(argv), llvm::outs(),
+ llvm::errs());
if (!r.canRunAgain)
exitLld(r.ret); // Exit now, can't re-execute again.
--- /dev/null
+from lit.llvm import llvm_config
+
+if llvm_config.use_lld(required=False):
+ config.available_features.add('lld')
--- /dev/null
+# REQUIRES: lld
+
+# RUN: %llvm ld.lld --help | FileCheck %s
+# RUN: %llvm lld -flavor ld.lld --help | FileCheck %s
+
+# CHECK: supported targets: elf
StringRef Stem = sys::path::stem(ToolName);
auto Is = [=](StringRef Tool) {
- auto I = Stem.rfind_insensitive(Tool);
- return I != StringRef::npos && (I + Tool.size() == Stem.size() ||
- !llvm::isAlnum(Stem[I + Tool.size()]));
+ auto IsImpl = [=](StringRef Stem) {
+ auto I = Stem.rfind_insensitive(Tool);
+ return I != StringRef::npos && (I + Tool.size() == Stem.size() ||
+ !llvm::isAlnum(Stem[I + Tool.size()]));
+ };
+ for (StringRef S : {Stem, ToolName})
+ if (IsImpl(S))
+ return true;
+ return false;
};
#define LLVM_DRIVER_TOOL(tool, entry) \
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
load("//llvm:tblgen.bzl", "gentbl")
package(
],
)
+expand_template(
+ name = "lld_main",
+ out = "lld-driver.cpp",
+ substitutions = {
+ "@TOOL_NAME@": "lld",
+ },
+ template = "//llvm:cmake/modules/llvm-driver-template.cpp.in",
+)
+
cc_binary(
name = "lld",
srcs = glob([
"tools/lld/*.cpp",
"tools/lld/*.h",
- ]),
+ ]) + ["lld-driver.cpp"],
deps = [
":COFF",
":Common",