Path: blob/main/contrib/llvm-project/lld/Common/CommonLinkerContext.cpp
34879 views
//===- CommonLinkerContext.cpp --------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lld/Common/CommonLinkerContext.h"9#include "lld/Common/ErrorHandler.h"10#include "lld/Common/Memory.h"1112#include "llvm/CodeGen/CommandFlags.h"1314using namespace llvm;15using namespace lld;1617// Reference to the current LLD instance. This is a temporary situation, until18// we pass this context everywhere by reference, or we make it a thread_local,19// as in https://reviews.llvm.org/D108850?id=370678 where each thread can be20// associated with a LLD instance. Only then will LLD be free of global21// state.22static CommonLinkerContext *lctx;2324CommonLinkerContext::CommonLinkerContext() {25lctx = this;26// Fire off the static initializations in CGF's constructor.27codegen::RegisterCodeGenFlags CGF;28}2930CommonLinkerContext::~CommonLinkerContext() {31assert(lctx);32// Explicitly call the destructors since we created the objects with placement33// new in SpecificAlloc::create().34for (auto &it : instances)35it.second->~SpecificAllocBase();36lctx = nullptr;37}3839CommonLinkerContext &lld::commonContext() {40assert(lctx);41return *lctx;42}4344bool lld::hasContext() { return lctx != nullptr; }4546void CommonLinkerContext::destroy() {47if (lctx == nullptr)48return;49delete lctx;50}515253