mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-27 22:02:33 +01:00
Per their documentation, the `llvm::Initialize*` functions are only supposed to be called by the main program, not by a library like toolchain/codegen. Fixes a hang due to a data race in multithreaded autoupdate. Add a utility class `Carbon::InitLLVM` to do the common LLVM initialization shared by all Carbon tools, optionally including initializing the LLVM targets. Because the LLVM targets add a lot of binary size, only initialize them for binaries that opt in by depending on a new target `//common:all_llvm_targets`. Also fix `//explorer:file_test` and `//explorer:file_test.trace` to share a binary rather than linking an identical binary twice. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
23 lines
745 B
C++
23 lines
745 B
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 "common/init_llvm.h"
|
|
#include "llvm/Support/TargetSelect.h"
|
|
|
|
namespace Carbon {
|
|
|
|
static auto InitLLVMTargets() -> void {
|
|
llvm::InitializeAllTargetInfos();
|
|
llvm::InitializeAllTargets();
|
|
llvm::InitializeAllTargetMCs();
|
|
llvm::InitializeAllAsmParsers();
|
|
llvm::InitializeAllAsmPrinters();
|
|
}
|
|
|
|
// On program startup, set `InitLLVM::InitializeTargets` to be our
|
|
// initialization function so that `InitLLVM` can call it at the right moment.
|
|
char InitLLVM::RegisterTargets = (InitializeTargets = &InitLLVMTargets, 0);
|
|
|
|
} // namespace Carbon
|