Skip to content

Commit

Permalink
Temporarily revert "[LLD] Remove global state in lld/COFF" and "[lld]…
Browse files Browse the repository at this point in the history
… Add test to

check for timer output"

Seems to be causing a number of asan test failures.

This reverts commit b4fa71e
and e03c7e3.
  • Loading branch information
amykhuang committed Sep 16, 2021
1 parent 5de8c7f commit a2fd05a
Show file tree
Hide file tree
Showing 38 changed files with 607 additions and 754 deletions.
1 change: 0 additions & 1 deletion lld/COFF/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ add_public_tablegen_target(COFFOptionsTableGen)
add_lld_library(lldCOFF
CallGraphSort.cpp
Chunks.cpp
COFFLinkerContext.cpp
DebugTypes.cpp
DLL.cpp
Driver.cpp
Expand Down
53 changes: 0 additions & 53 deletions lld/COFF/COFFLinkerContext.cpp

This file was deleted.

88 changes: 0 additions & 88 deletions lld/COFF/COFFLinkerContext.h

This file was deleted.

12 changes: 5 additions & 7 deletions lld/COFF/CallGraphSort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
//===----------------------------------------------------------------------===//

#include "CallGraphSort.h"
#include "COFFLinkerContext.h"
#include "InputFiles.h"
#include "SymbolTable.h"
#include "Symbols.h"
Expand Down Expand Up @@ -49,7 +48,7 @@ struct Cluster {

class CallGraphSort {
public:
CallGraphSort(const COFFLinkerContext &ctx);
CallGraphSort();

DenseMap<const SectionChunk *, int> run();

Expand All @@ -71,7 +70,7 @@ 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) {
CallGraphSort::CallGraphSort() {
MapVector<SectionPair, uint64_t> &profile = config->callGraphProfile;
DenseMap<const SectionChunk *, int> secToCluster;

Expand All @@ -96,7 +95,7 @@ CallGraphSort::CallGraphSort(const COFFLinkerContext &ctx) {
// output. This messes with the cluster size and density calculations. We
// would also end up moving input sections in other output sections without
// moving them closer to what calls them.
if (ctx.getOutputSection(fromSec) != ctx.getOutputSection(toSec))
if (fromSec->getOutputSection() != toSec->getOutputSection())
continue;

int from = getOrCreateNode(fromSec);
Expand Down Expand Up @@ -241,7 +240,6 @@ DenseMap<const SectionChunk *, int> CallGraphSort::run() {
// This first builds a call graph based on the profile data then merges sections
// according to the C³ heuristic. All clusters are then sorted by a density
// metric to further improve locality.
DenseMap<const SectionChunk *, int>
coff::computeCallGraphProfileOrder(const COFFLinkerContext &ctx) {
return CallGraphSort(ctx).run();
DenseMap<const SectionChunk *, int> coff::computeCallGraphProfileOrder() {
return CallGraphSort().run();
}
4 changes: 1 addition & 3 deletions lld/COFF/CallGraphSort.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
namespace lld {
namespace coff {
class SectionChunk;
class COFFLinkerContext;

llvm::DenseMap<const SectionChunk *, int>
computeCallGraphProfileOrder(const COFFLinkerContext &ctx);
llvm::DenseMap<const SectionChunk *, int> computeCallGraphProfileOrder();
} // namespace coff
} // namespace lld

Expand Down
13 changes: 7 additions & 6 deletions lld/COFF/Chunks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
//===----------------------------------------------------------------------===//

#include "Chunks.h"
#include "COFFLinkerContext.h"
#include "InputFiles.h"
#include "SymbolTable.h"
#include "Symbols.h"
#include "Writer.h"
#include "SymbolTable.h"
#include "lld/Common/ErrorHandler.h"
#include "llvm/ADT/Twine.h"
#include "llvm/BinaryFormat/COFF.h"
Expand Down Expand Up @@ -386,7 +385,7 @@ void SectionChunk::applyRelocation(uint8_t *off,
// section is needed to compute SECREL and SECTION relocations used in debug
// info.
Chunk *c = sym ? sym->getChunk() : nullptr;
OutputSection *os = c ? file->ctx.getOutputSection(c) : nullptr;
OutputSection *os = c ? c->getOutputSection() : nullptr;

// Skip the relocation if it refers to a discarded section, and diagnose it
// as an error if appropriate. If a symbol was discarded early, it may be
Expand Down Expand Up @@ -939,16 +938,18 @@ uint8_t Baserel::getDefaultType() {
}
}

MergeChunk *MergeChunk::instances[Log2MaxSectionAlignment + 1] = {};

MergeChunk::MergeChunk(uint32_t alignment)
: builder(StringTableBuilder::RAW, alignment) {
setAlignment(alignment);
}

void MergeChunk::addSection(COFFLinkerContext &ctx, SectionChunk *c) {
void MergeChunk::addSection(SectionChunk *c) {
assert(isPowerOf2_32(c->getAlignment()));
uint8_t p2Align = llvm::Log2_32(c->getAlignment());
assert(p2Align < array_lengthof(ctx.mergeChunkInstances));
auto *&mc = ctx.mergeChunkInstances[p2Align];
assert(p2Align < array_lengthof(instances));
auto *&mc = instances[p2Align];
if (!mc)
mc = make<MergeChunk>(c->getAlignment());
mc->sections.push_back(c);
Expand Down
4 changes: 3 additions & 1 deletion lld/COFF/Chunks.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class Chunk {
// chunk has a back pointer to an output section.
void setOutputSectionIdx(uint16_t o) { osidx = o; }
uint16_t getOutputSectionIdx() const { return osidx; }
OutputSection *getOutputSection() const;

// Windows-specific.
// Collect all locations that contain absolute addresses for base relocations.
Expand Down Expand Up @@ -414,7 +415,7 @@ inline StringRef Chunk::getDebugName() const {
class MergeChunk : public NonSectionChunk {
public:
MergeChunk(uint32_t alignment);
static void addSection(COFFLinkerContext &ctx, SectionChunk *c);
static void addSection(SectionChunk *c);
void finalizeContents();
void assignSubsectionRVAs();

Expand All @@ -423,6 +424,7 @@ class MergeChunk : public NonSectionChunk {
size_t getSize() const override;
void writeTo(uint8_t *buf) const override;

static MergeChunk *instances[Log2MaxSectionAlignment + 1];
std::vector<SectionChunk *> sections;

private:
Expand Down
7 changes: 3 additions & 4 deletions lld/COFF/DLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
//===----------------------------------------------------------------------===//

#include "DLL.h"
#include "COFFLinkerContext.h"
#include "Chunks.h"
#include "SymbolTable.h"
#include "llvm/Object/COFF.h"
Expand Down Expand Up @@ -632,7 +631,7 @@ uint64_t DelayLoadContents::getDirSize() {
return dirs.size() * sizeof(delay_import_directory_table_entry);
}

void DelayLoadContents::create(COFFLinkerContext &ctx, Defined *h) {
void DelayLoadContents::create(Defined *h) {
helper = h;
std::vector<std::vector<DefinedImportData *>> v = binImports(imports);

Expand Down Expand Up @@ -661,13 +660,13 @@ void DelayLoadContents::create(COFFLinkerContext &ctx, Defined *h) {
// call targets for Control Flow Guard.
StringRef symName = saver.save("__imp_load_" + extName);
s->loadThunkSym =
cast<DefinedSynthetic>(ctx.symtab.addSynthetic(symName, t));
cast<DefinedSynthetic>(symtab->addSynthetic(symName, t));
}
}
thunks.push_back(tm);
StringRef tmName =
saver.save("__tailMerge_" + syms[0]->getDLLName().lower());
ctx.symtab.addSynthetic(tmName, tm);
symtab->addSynthetic(tmName, tm);
// Terminate with null values.
addresses.push_back(make<NullChunk>(8));
names.push_back(make<NullChunk>(8));
Expand Down
2 changes: 1 addition & 1 deletion lld/COFF/DLL.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DelayLoadContents {
public:
void add(DefinedImportData *sym) { imports.push_back(sym); }
bool empty() { return imports.empty(); }
void create(COFFLinkerContext &ctx, Defined *helper);
void create(Defined *helper);
std::vector<Chunk *> getChunks();
std::vector<Chunk *> getDataChunks();
ArrayRef<Chunk *> getCodeChunks() { return thunks; }
Expand Down
Loading

0 comments on commit a2fd05a

Please sign in to comment.