Skip to content

Commit

Permalink
Revert "[LLD] Remove global state in lld/COFF"
Browse files Browse the repository at this point in the history
This reverts commit 7370ff6.
(and 47fb8ae).

This commit broke the symbol type in import libraries generated
for mingw autoexported symbols, when the source files were built
with LTO. I'll commit a testcase that showcases this issue after
the revert.
  • Loading branch information
mstorsjo committed Jan 9, 2023
1 parent 35b8bb0 commit 398c2ad
Show file tree
Hide file tree
Showing 31 changed files with 828 additions and 1,040 deletions.
14 changes: 4 additions & 10 deletions lld/COFF/COFFLinkerContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@
//===----------------------------------------------------------------------===//

#include "COFFLinkerContext.h"
#include "Symbols.h"
#include "lld/Common/Memory.h"
#include "llvm/BinaryFormat/COFF.h"
#include "llvm/DebugInfo/CodeView/TypeHashing.h"
#include "llvm/Demangle/Demangle.h"

namespace lld::coff {

COFFLinkerContext::COFFLinkerContext()
: driver(*this), symtab(*this), rootTimer("Total Linking Time"),
: symtab(*this), rootTimer("Total Linking Time"),
inputFileTimer("Input File Reading", rootTimer),
ltoTimer("LTO", rootTimer), gcTimer("GC", rootTimer),
icfTimer("ICF", rootTimer), codeLayoutTimer("Code Layout", rootTimer),
Expand All @@ -35,10 +33,6 @@ COFFLinkerContext::COFFLinkerContext()
symbolMergingTimer("Symbol Merging", addObjectsTimer),
publicsLayoutTimer("Publics Stream Layout", totalPdbLinkTimer),
tpiStreamLayoutTimer("TPI Stream Layout", totalPdbLinkTimer),
diskCommitTimer("Commit to Disk", totalPdbLinkTimer) {
FakeSection ltoTextSection(llvm::COFF::IMAGE_SCN_MEM_EXECUTE);
FakeSection ltoDataSection(llvm::COFF::IMAGE_SCN_CNT_INITIALIZED_DATA);
ltoTextSectionChunk = make<FakeSectionChunk>(&ltoTextSection.section);
ltoDataSectionChunk = make<FakeSectionChunk>(&ltoDataSection.section);
}
diskCommitTimer("Commit to Disk", totalPdbLinkTimer) {}

} // namespace lld::coff
17 changes: 4 additions & 13 deletions lld/COFF/COFFLinkerContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
//
//===----------------------------------------------------------------------===//

#ifndef LLD_COFF_COFFLINKERCONTEXT_H
#define LLD_COFF_COFFLINKERCONTEXT_H
#ifndef LLD_COFF_COFFLinkerContext_H
#define LLD_COFF_COFFLinkerContext_H

#include "Chunks.h"
#include "Config.h"
#include "DebugTypes.h"
#include "Driver.h"
#include "InputFiles.h"
#include "SymbolTable.h"
#include "Writer.h"
Expand All @@ -28,9 +27,9 @@ class COFFLinkerContext : public CommonLinkerContext {
COFFLinkerContext &operator=(const COFFLinkerContext &) = delete;
~COFFLinkerContext() = default;

LinkerDriver driver;
void addTpiSource(TpiSource *tpi) { tpiSourceList.push_back(tpi); }

SymbolTable symtab;
COFFOptTable optTable;

std::vector<ObjFile *> objFileInstances;
std::map<std::string, PDBInputFile *> pdbInputFileInstances;
Expand All @@ -42,8 +41,6 @@ class COFFLinkerContext : public CommonLinkerContext {
/// All sources of type information in the program.
std::vector<TpiSource *> tpiSourceList;

void addTpiSource(TpiSource *tpi) { tpiSourceList.push_back(tpi); }

std::map<llvm::codeview::GUID, TpiSource *> typeServerSourceMappings;
std::map<uint32_t, TpiSource *> precompSourceMappings;

Expand All @@ -55,10 +52,6 @@ class COFFLinkerContext : public CommonLinkerContext {
return c->osidx == 0 ? nullptr : outputSections[c->osidx - 1];
}

// Fake sections for parsing bitcode files.
FakeSectionChunk *ltoTextSectionChunk;
FakeSectionChunk *ltoDataSectionChunk;

// All timers used in the COFF linker.
Timer rootTimer;
Timer inputFileTimer;
Expand All @@ -84,8 +77,6 @@ class COFFLinkerContext : public CommonLinkerContext {
Timer publicsLayoutTimer;
Timer tpiStreamLayoutTimer;
Timer diskCommitTimer;

Configuration config;
};

} // namespace lld::coff
Expand Down
14 changes: 6 additions & 8 deletions lld/COFF/CallGraphSort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ class CallGraphSort {
private:
std::vector<Cluster> clusters;
std::vector<const SectionChunk *> sections;

const COFFLinkerContext &ctx;
};

// Maximum amount the combined cluster density can be worse than the original
Expand All @@ -73,8 +71,8 @@ using SectionPair = std::pair<const SectionChunk *, const SectionChunk *>;
// Take the edge list in Config->CallGraphProfile, resolve symbol names to
// Symbols, and generate a graph between InputSections with the provided
// weights.
CallGraphSort::CallGraphSort(const COFFLinkerContext &ctx) : ctx(ctx) {
const MapVector<SectionPair, uint64_t> &profile = ctx.config.callGraphProfile;
CallGraphSort::CallGraphSort(const COFFLinkerContext &ctx) {
MapVector<SectionPair, uint64_t> &profile = config->callGraphProfile;
DenseMap<const SectionChunk *, int> secToCluster;

auto getOrCreateNode = [&](const SectionChunk *isec) -> int {
Expand All @@ -87,7 +85,7 @@ CallGraphSort::CallGraphSort(const COFFLinkerContext &ctx) : ctx(ctx) {
};

// Create the graph.
for (const std::pair<SectionPair, uint64_t> &c : profile) {
for (std::pair<SectionPair, uint64_t> &c : profile) {
const auto *fromSec = cast<SectionChunk>(c.first.first->repl);
const auto *toSec = cast<SectionChunk>(c.first.second->repl);
uint64_t weight = c.second;
Expand Down Expand Up @@ -207,11 +205,11 @@ DenseMap<const SectionChunk *, int> CallGraphSort::run() {
break;
}
}
if (!ctx.config.printSymbolOrder.empty()) {
if (!config->printSymbolOrder.empty()) {
std::error_code ec;
raw_fd_ostream os(ctx.config.printSymbolOrder, ec, sys::fs::OF_None);
raw_fd_ostream os(config->printSymbolOrder, ec, sys::fs::OF_None);
if (ec) {
error("cannot open " + ctx.config.printSymbolOrder + ": " + ec.message());
error("cannot open " + config->printSymbolOrder + ": " + ec.message());
return orderMap;
}
// Print the symbols ordered by C3, in the order of increasing curOrder
Expand Down
Loading

0 comments on commit 398c2ad

Please sign in to comment.