[llvm-driver] Add lld
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
This commit is contained in:
parent
4e6b071509
commit
1fda6f6859
@ -6,10 +6,18 @@ add_lld_tool(lld
|
||||
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
|
||||
|
@ -210,7 +210,7 @@ static unsigned inTestVerbosity() {
|
||||
return v;
|
||||
}
|
||||
|
||||
int main(int argc, const char **argv) {
|
||||
int lld_main(int argc, char **argv) {
|
||||
InitLLVM x(argc, argv);
|
||||
sys::Process::UseANSIEscapeCodes(true);
|
||||
|
||||
@ -223,7 +223,8 @@ int main(int argc, const char **argv) {
|
||||
// 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();
|
||||
@ -233,7 +234,8 @@ int main(int argc, const char **argv) {
|
||||
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.
|
||||
|
||||
|
4
llvm/test/tools/llvm-driver/lit.local.cfg
Normal file
4
llvm/test/tools/llvm-driver/lit.local.cfg
Normal file
@ -0,0 +1,4 @@
|
||||
from lit.llvm import llvm_config
|
||||
|
||||
if llvm_config.use_lld(required=False):
|
||||
config.available_features.add('lld')
|
6
llvm/test/tools/llvm-driver/passthrough-lld.test
Normal file
6
llvm/test/tools/llvm-driver/passthrough-lld.test
Normal file
@ -0,0 +1,6 @@
|
||||
# REQUIRES: lld
|
||||
|
||||
# RUN: %llvm ld.lld --help | FileCheck %s
|
||||
# RUN: %llvm lld -flavor ld.lld --help | FileCheck %s
|
||||
|
||||
# CHECK: supported targets: elf
|
@ -49,9 +49,15 @@ static int findTool(int Argc, char **Argv) {
|
||||
|
||||
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) \
|
||||
|
@ -2,6 +2,7 @@
|
||||
# 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(
|
||||
@ -240,12 +241,21 @@ cc_library(
|
||||
],
|
||||
)
|
||||
|
||||
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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user