[NFC] Remove duplicate include
[llvm-project.git] / lld / Common / CommonLinkerContext.cpp
blob50ccbb37c79669183b36aea488b5e490255ae7fe
1 //===- CommonLinkerContext.cpp --------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "lld/Common/CommonLinkerContext.h"
10 #include "lld/Common/ErrorHandler.h"
11 #include "lld/Common/Memory.h"
13 using namespace llvm;
14 using namespace lld;
16 // Reference to the current LLD instance. This is a temporary situation, until
17 // we pass this context everywhere by reference, or we make it a thread_local,
18 // as in https://reviews.llvm.org/D108850?id=370678 where each thread can be
19 // associated with a LLD instance. Only then will LLD be free of global
20 // state.
21 static CommonLinkerContext *lctx;
23 CommonLinkerContext::CommonLinkerContext() { lctx = this; }
25 CommonLinkerContext::~CommonLinkerContext() {
26 assert(lctx);
27 // Explicitly call the destructors since we created the objects with placement
28 // new in SpecificAlloc::create().
29 for (auto &it : instances)
30 it.second->~SpecificAllocBase();
31 lctx = nullptr;
34 CommonLinkerContext &lld::commonContext() {
35 assert(lctx);
36 return *lctx;
39 bool lld::hasContext() { return lctx != nullptr; }
41 void CommonLinkerContext::destroy() {
42 if (lctx == nullptr)
43 return;
44 delete lctx;