mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-29 12:15:00 +01:00
This removes the separately built and installed LLD binary. The symlinks used by Clang when directly invoking LLD now point back to the main `carbon-busybox` binary and dispatch through the newly added subcommand. With this change we're down to shipping a single busybox binary in the toolchain, removing duplicate installed copies of LLD and all its LLVM dependencies. =] The LLD subcommand works a bit differently from the `clang` subcommand because the CLI for LLD is specific to which platform flavor of linker is being invoked. As part of this, I've extracted some of the common functionality in the Clang runner into a base class that can be re-used. I expect to use this again in a follow-up change to add subcommands to run other LLVM tools. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
60 lines
2.0 KiB
C++
60 lines
2.0 KiB
C++
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#include "toolchain/driver/lld_runner.h"
|
|
|
|
#include <algorithm>
|
|
#include <memory>
|
|
#include <numeric>
|
|
#include <optional>
|
|
|
|
#include "common/vlog.h"
|
|
#include "llvm/ADT/ArrayRef.h"
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
// Declare the supported driver flavor entry points.
|
|
//
|
|
// TODO: Currently, just ELF and MachO, but eventually we should support all of
|
|
// the LLD platforms.
|
|
//
|
|
// NOLINTBEGIN(readability-identifier-naming): External library name.
|
|
LLD_HAS_DRIVER(elf)
|
|
LLD_HAS_DRIVER(macho)
|
|
// NOLINTEND(readability-identifier-naming)
|
|
|
|
namespace Carbon {
|
|
|
|
auto LldRunner::LinkHelper(llvm::StringLiteral label,
|
|
llvm::ArrayRef<llvm::StringRef> args,
|
|
const std::string& path, lld::DriverDef driver_def)
|
|
-> bool {
|
|
// Allocate one chunk of storage for the actual C-strings and a vector of
|
|
// pointers into the storage.
|
|
llvm::OwningArrayRef<char> cstr_arg_storage;
|
|
llvm::SmallVector<const char*, 64> cstr_args =
|
|
BuildCStrArgs("LLD", path, "-v", args, cstr_arg_storage);
|
|
|
|
CARBON_VLOG("Running LLD {0}-platform link...\n", label);
|
|
lld::Result result =
|
|
lld::lldMain(cstr_args, llvm::outs(), llvm::errs(), {driver_def});
|
|
|
|
// Check for an unrecoverable error.
|
|
CARBON_CHECK(result.canRunAgain, "LLD encountered an unrecoverable error!");
|
|
|
|
// TODO: Should this be forwarding the full exit code?
|
|
return result.retCode == 0;
|
|
}
|
|
|
|
auto LldRunner::ElfLink(llvm::ArrayRef<llvm::StringRef> args) -> bool {
|
|
return LinkHelper("GNU", args, installation_->ld_lld_path(),
|
|
{.f = lld::Gnu, .d = &lld::elf::link});
|
|
}
|
|
|
|
auto LldRunner::MachOLink(llvm::ArrayRef<llvm::StringRef> args) -> bool {
|
|
return LinkHelper("Darwin", args, installation_->ld64_lld_path(),
|
|
{.f = lld::Darwin, .d = &lld::macho::link});
|
|
}
|
|
|
|
} // namespace Carbon
|