Skip to content

Commit 499260c

Browse files
committed
Revert "[CFGuard] Add address-taken IAT tables and delay-load support"
This reverts commit ef4e971.
1 parent 5f3e565 commit 499260c

File tree

12 files changed

+18
-259
lines changed

12 files changed

+18
-259
lines changed

lld/COFF/DLL.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
#include "DLL.h"
2121
#include "Chunks.h"
22-
#include "SymbolTable.h"
2322
#include "llvm/Object/COFF.h"
2423
#include "llvm/Support/Endian.h"
2524
#include "llvm/Support/Path.h"
@@ -654,18 +653,9 @@ void DelayLoadContents::create(Defined *h) {
654653
auto *c = make<HintNameChunk>(extName, 0);
655654
names.push_back(make<LookupChunk>(c));
656655
hintNames.push_back(c);
657-
// Add a syntentic symbol for this load thunk, using the "__imp_load"
658-
// prefix, in case this thunk needs to be added to the list of valid
659-
// call targets for Control Flow Guard.
660-
StringRef symName = saver.save("__imp_load_" + extName);
661-
s->loadThunkSym =
662-
cast<DefinedSynthetic>(symtab->addSynthetic(symName, t));
663656
}
664657
}
665658
thunks.push_back(tm);
666-
StringRef tmName =
667-
saver.save("__tailMerge_" + syms[0]->getDLLName().lower());
668-
symtab->addSynthetic(tmName, tm);
669659
// Terminate with null values.
670660
addresses.push_back(make<NullChunk>(8));
671661
names.push_back(make<NullChunk>(8));

lld/COFF/ICF.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ bool ICF::assocEquals(const SectionChunk *a, const SectionChunk *b) {
131131
auto considerForICF = [](const SectionChunk &assoc) {
132132
StringRef Name = assoc.getSectionName();
133133
return !(Name.startswith(".debug") || Name == ".gfids$y" ||
134-
Name == ".giats$y" || Name == ".gljmp$y");
134+
Name == ".gljmp$y");
135135
};
136136
auto ra = make_filter_range(a->children(), considerForICF);
137137
auto rb = make_filter_range(b->children(), considerForICF);

lld/COFF/InputFiles.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,6 @@ SectionChunk *ObjFile::readSection(uint32_t sectionNumber,
280280
debugChunks.push_back(c);
281281
else if (name == ".gfids$y")
282282
guardFidChunks.push_back(c);
283-
else if (name == ".giats$y")
284-
guardIATChunks.push_back(c);
285283
else if (name == ".gljmp$y")
286284
guardLJmpChunks.push_back(c);
287285
else if (name == ".sxdata")

lld/COFF/InputFiles.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ class ObjFile : public InputFile {
144144
ArrayRef<SectionChunk *> getDebugChunks() { return debugChunks; }
145145
ArrayRef<SectionChunk *> getSXDataChunks() { return sxDataChunks; }
146146
ArrayRef<SectionChunk *> getGuardFidChunks() { return guardFidChunks; }
147-
ArrayRef<SectionChunk *> getGuardIATChunks() { return guardIATChunks; }
148147
ArrayRef<SectionChunk *> getGuardLJmpChunks() { return guardLJmpChunks; }
149148
ArrayRef<Symbol *> getSymbols() { return symbols; }
150149

@@ -284,11 +283,9 @@ class ObjFile : public InputFile {
284283
// 32-bit x86.
285284
std::vector<SectionChunk *> sxDataChunks;
286285

287-
// Chunks containing symbol table indices of address taken symbols, address
288-
// taken IAT entries, and longjmp targets. These are not linked into the
289-
// final binary when /guard:cf is set.
286+
// Chunks containing symbol table indices of address taken symbols and longjmp
287+
// targets. These are not linked into the final binary when /guard:cf is set.
290288
std::vector<SectionChunk *> guardFidChunks;
291-
std::vector<SectionChunk *> guardIATChunks;
292289
std::vector<SectionChunk *> guardLJmpChunks;
293290

294291
// This vector contains a list of all symbols defined or referenced by this

lld/COFF/Symbols.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -343,13 +343,6 @@ class DefinedImportData : public Defined {
343343
uint16_t getOrdinal() { return file->hdr->OrdinalHint; }
344344

345345
ImportFile *file;
346-
347-
// This is a pointer to the synthetic symbol associated with the load thunk
348-
// for this symbol that will be called if the DLL is delay-loaded. This is
349-
// needed for Control Flow Guard because if this DefinedImportData symbol is a
350-
// valid call target, the corresponding load thunk must also be marked as a
351-
// valid call target.
352-
DefinedSynthetic *loadThunkSym;
353346
};
354347

355348
// This class represents a symbol for a jump table entry which jumps

lld/COFF/Writer.cpp

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,6 @@ class Writer {
227227
void markSymbolsForRVATable(ObjFile *file,
228228
ArrayRef<SectionChunk *> symIdxChunks,
229229
SymbolRVASet &tableSymbols);
230-
void getSymbolsFromSections(ObjFile *file,
231-
ArrayRef<SectionChunk *> symIdxChunks,
232-
std::vector<Symbol *> &symbols);
233230
void maybeAddRVATable(SymbolRVASet tableSymbols, StringRef tableSym,
234231
StringRef countSym);
235232
void setSectionPermissions();
@@ -608,9 +605,8 @@ void Writer::run() {
608605

609606
createImportTables();
610607
createSections();
611-
appendImportThunks();
612-
// Import thunks must be added before the Control Flow Guard tables are added.
613608
createMiscChunks();
609+
appendImportThunks();
614610
createExportTable();
615611
mergeSections();
616612
removeUnusedSections();
@@ -1622,8 +1618,6 @@ static void markSymbolsWithRelocations(ObjFile *file,
16221618
// table.
16231619
void Writer::createGuardCFTables() {
16241620
SymbolRVASet addressTakenSyms;
1625-
SymbolRVASet giatsRVASet;
1626-
std::vector<Symbol *> giatsSymbols;
16271621
SymbolRVASet longJmpTargets;
16281622
for (ObjFile *file : ObjFile::instances) {
16291623
// If the object was compiled with /guard:cf, the address taken symbols
@@ -1633,8 +1627,6 @@ void Writer::createGuardCFTables() {
16331627
// possibly address-taken.
16341628
if (file->hasGuardCF()) {
16351629
markSymbolsForRVATable(file, file->getGuardFidChunks(), addressTakenSyms);
1636-
markSymbolsForRVATable(file, file->getGuardIATChunks(), giatsRVASet);
1637-
getSymbolsFromSections(file, file->getGuardIATChunks(), giatsSymbols);
16381630
markSymbolsForRVATable(file, file->getGuardLJmpChunks(), longJmpTargets);
16391631
} else {
16401632
markSymbolsWithRelocations(file, addressTakenSyms);
@@ -1649,16 +1641,6 @@ void Writer::createGuardCFTables() {
16491641
for (Export &e : config->exports)
16501642
maybeAddAddressTakenFunction(addressTakenSyms, e.sym);
16511643

1652-
// For each entry in the .giats table, check if it has a corresponding load
1653-
// thunk (e.g. because the DLL that defines it will be delay-loaded) and, if
1654-
// so, add the load thunk to the address taken (.gfids) table.
1655-
for (Symbol *s : giatsSymbols) {
1656-
if (auto *di = dyn_cast<DefinedImportData>(s)) {
1657-
if (di->loadThunkSym)
1658-
addSymbolToRVASet(addressTakenSyms, di->loadThunkSym);
1659-
}
1660-
}
1661-
16621644
// Ensure sections referenced in the gfid table are 16-byte aligned.
16631645
for (const ChunkAndOffset &c : addressTakenSyms)
16641646
if (c.inputChunk->getAlignment() < 16)
@@ -1667,10 +1649,6 @@ void Writer::createGuardCFTables() {
16671649
maybeAddRVATable(std::move(addressTakenSyms), "__guard_fids_table",
16681650
"__guard_fids_count");
16691651

1670-
// Add the Guard Address Taken IAT Entry Table (.giats).
1671-
maybeAddRVATable(std::move(giatsRVASet), "__guard_iat_table",
1672-
"__guard_iat_count");
1673-
16741652
// Add the longjmp target table unless the user told us not to.
16751653
if (config->guardCF == GuardCFLevel::Full)
16761654
maybeAddRVATable(std::move(longJmpTargets), "__guard_longjmp_table",
@@ -1687,11 +1665,11 @@ void Writer::createGuardCFTables() {
16871665
}
16881666

16891667
// Take a list of input sections containing symbol table indices and add those
1690-
// symbols to a vector. The challenge is that symbol RVAs are not known and
1668+
// symbols to an RVA table. The challenge is that symbol RVAs are not known and
16911669
// depend on the table size, so we can't directly build a set of integers.
1692-
void Writer::getSymbolsFromSections(ObjFile *file,
1670+
void Writer::markSymbolsForRVATable(ObjFile *file,
16931671
ArrayRef<SectionChunk *> symIdxChunks,
1694-
std::vector<Symbol *> &symbols) {
1672+
SymbolRVASet &tableSymbols) {
16951673
for (SectionChunk *c : symIdxChunks) {
16961674
// Skip sections discarded by linker GC. This comes up when a .gfids section
16971675
// is associated with something like a vtable and the vtable is discarded.
@@ -1709,7 +1687,7 @@ void Writer::getSymbolsFromSections(ObjFile *file,
17091687
}
17101688

17111689
// Read each symbol table index and check if that symbol was included in the
1712-
// final link. If so, add it to the vector of symbols.
1690+
// final link. If so, add it to the table symbol set.
17131691
ArrayRef<ulittle32_t> symIndices(
17141692
reinterpret_cast<const ulittle32_t *>(data.data()), data.size() / 4);
17151693
ArrayRef<Symbol *> objSymbols = file->getSymbols();
@@ -1721,24 +1699,12 @@ void Writer::getSymbolsFromSections(ObjFile *file,
17211699
}
17221700
if (Symbol *s = objSymbols[symIndex]) {
17231701
if (s->isLive())
1724-
symbols.push_back(cast<Symbol>(s));
1702+
addSymbolToRVASet(tableSymbols, cast<Defined>(s));
17251703
}
17261704
}
17271705
}
17281706
}
17291707

1730-
// Take a list of input sections containing symbol table indices and add those
1731-
// symbols to an RVA table.
1732-
void Writer::markSymbolsForRVATable(ObjFile *file,
1733-
ArrayRef<SectionChunk *> symIdxChunks,
1734-
SymbolRVASet &tableSymbols) {
1735-
std::vector<Symbol *> syms;
1736-
getSymbolsFromSections(file, symIdxChunks, syms);
1737-
1738-
for (Symbol *s : syms)
1739-
addSymbolToRVASet(tableSymbols, cast<Defined>(s));
1740-
}
1741-
17421708
// Replace the absolute table symbol with a synthetic symbol pointing to
17431709
// tableChunk so that we can emit base relocations for it and resolve section
17441710
// relative relocations.

lld/test/COFF/giats.s

Lines changed: 0 additions & 117 deletions
This file was deleted.

llvm/include/llvm/MC/MCObjectFileInfo.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ class MCObjectFileInfo {
215215
MCSection *XDataSection = nullptr;
216216
MCSection *SXDataSection = nullptr;
217217
MCSection *GFIDsSection = nullptr;
218-
MCSection *GIATsSection = nullptr;
219218
MCSection *GLJMPSection = nullptr;
220219

221220
// XCOFF specific sections
@@ -399,7 +398,6 @@ class MCObjectFileInfo {
399398
MCSection *getXDataSection() const { return XDataSection; }
400399
MCSection *getSXDataSection() const { return SXDataSection; }
401400
MCSection *getGFIDsSection() const { return GFIDsSection; }
402-
MCSection *getGIATsSection() const { return GIATsSection; }
403401
MCSection *getGLJMPSection() const { return GLJMPSection; }
404402

405403
// XCOFF specific sections

0 commit comments

Comments
 (0)