Skip to content

Commit a6891df

Browse files
committed
Merge commit '11daa8ef1d85fdf815bb4ba83b548ca22ab7038c' into mainline
2 parents 3fca1f4 + 11daa8e commit a6891df

159 files changed

Lines changed: 3014 additions & 1398 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/llvm/tools/lld/COFF/Chunks.cpp

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "InputFiles.h"
1212
#include "Symbols.h"
1313
#include "Writer.h"
14+
#include "SymbolTable.h"
1415
#include "lld/Common/ErrorHandler.h"
1516
#include "llvm/ADT/Twine.h"
1617
#include "llvm/BinaryFormat/COFF.h"
@@ -315,6 +316,32 @@ void SectionChunk::applyRelARM64(uint8_t *Off, uint16_t Type, OutputSection *OS,
315316
}
316317
}
317318

319+
static void maybeReportRelocationToDiscarded(const SectionChunk *FromChunk,
320+
Defined *Sym,
321+
const coff_relocation &Rel) {
322+
// Don't report these errors when the relocation comes from a debug info
323+
// section or in mingw mode. MinGW mode object files (built by GCC) can
324+
// have leftover sections with relocations against discarded comdat
325+
// sections. Such sections are left as is, with relocations untouched.
326+
if (FromChunk->isCodeView() || FromChunk->isDWARF() || Config->MinGW)
327+
return;
328+
329+
// Get the name of the symbol. If it's null, it was discarded early, so we
330+
// have to go back to the object file.
331+
ObjFile *File = FromChunk->File;
332+
StringRef Name;
333+
if (Sym) {
334+
Name = Sym->getName();
335+
} else {
336+
COFFSymbolRef COFFSym =
337+
check(File->getCOFFObj()->getSymbol(Rel.SymbolTableIndex));
338+
File->getCOFFObj()->getSymbolName(COFFSym, Name);
339+
}
340+
341+
error("relocation against symbol in discarded section: " + Name +
342+
getSymbolLocations(File, Rel.SymbolTableIndex));
343+
}
344+
318345
void SectionChunk::writeTo(uint8_t *Buf) const {
319346
if (!hasData())
320347
return;
@@ -342,41 +369,23 @@ void SectionChunk::writeTo(uint8_t *Buf) const {
342369
// Use the potentially remapped Symbol instead of the one that the
343370
// relocation points to.
344371
auto *Sym = dyn_cast_or_null<Defined>(RelocTargets[I]);
345-
if (!Sym) {
346-
if (isCodeView() || isDWARF())
347-
continue;
348-
// Symbols in early discarded sections are represented using null pointers,
349-
// so we need to retrieve the name from the object file.
350-
COFFSymbolRef Sym =
351-
check(File->getCOFFObj()->getSymbol(Rel.SymbolTableIndex));
352-
StringRef Name;
353-
File->getCOFFObj()->getSymbolName(Sym, Name);
354-
355-
// MinGW mode object files (built by GCC) can have leftover sections
356-
// with relocations against discarded comdat sections. Such sections
357-
// are left as is, with relocations untouched.
358-
if (!Config->MinGW)
359-
error("relocation against symbol in discarded section: " + Name);
360-
continue;
361-
}
372+
362373
// Get the output section of the symbol for this relocation. The output
363374
// section is needed to compute SECREL and SECTION relocations used in debug
364375
// info.
365-
Chunk *C = Sym->getChunk();
376+
Chunk *C = Sym ? Sym->getChunk() : nullptr;
366377
OutputSection *OS = C ? C->getOutputSection() : nullptr;
367378

368-
// Only absolute and __ImageBase symbols lack an output section. For any
369-
// other symbol, this indicates that the chunk was discarded. Normally
370-
// relocations against discarded sections are an error. However, debug info
371-
// sections are not GC roots and can end up with these kinds of relocations.
372-
// Skip these relocations.
373-
if (!OS && !isa<DefinedAbsolute>(Sym) && !isa<DefinedSynthetic>(Sym)) {
374-
if (isCodeView() || isDWARF())
375-
continue;
376-
error("relocation against symbol in discarded section: " +
377-
Sym->getName());
379+
// Skip the relocation if it refers to a discarded section, and diagnose it
380+
// as an error if appropriate. If a symbol was discarded early, it may be
381+
// null. If it was discarded late, the output section will be null, unless
382+
// it was an absolute or synthetic symbol.
383+
if (!Sym ||
384+
(!OS && !isa<DefinedAbsolute>(Sym) && !isa<DefinedSynthetic>(Sym))) {
385+
maybeReportRelocationToDiscarded(this, Sym, Rel);
378386
continue;
379387
}
388+
380389
uint64_t S = Sym->getRVA();
381390

382391
// Compute the RVA of the relocation for relative relocations.

src/llvm/tools/lld/COFF/ICF.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,18 @@ void ICF::run(ArrayRef<Chunk *> Vec) {
262262

263263
// Initially, we use hash values to partition sections.
264264
for_each(parallel::par, Chunks.begin(), Chunks.end(), [&](SectionChunk *SC) {
265+
SC->Class[1] = xxHash64(SC->getContents());
266+
});
267+
268+
// Combine the hashes of the sections referenced by each section into its
269+
// hash.
270+
for_each(parallel::par, Chunks.begin(), Chunks.end(), [&](SectionChunk *SC) {
271+
uint32_t Hash = SC->Class[1];
272+
for (Symbol *B : SC->symbols())
273+
if (auto *Sym = dyn_cast_or_null<DefinedRegular>(B))
274+
Hash ^= Sym->getChunk()->Class[1];
265275
// Set MSB to 1 to avoid collisions with non-hash classs.
266-
SC->Class[0] = xxHash64(SC->getContents()) | (1 << 31);
276+
SC->Class[0] = Hash | (1U << 31);
267277
});
268278

269279
// From now on, sections in Chunks are ordered so that sections in

src/llvm/tools/lld/COFF/InputFiles.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,10 @@ void ImportFile::parse() {
501501
ExternalName = ExtName;
502502

503503
ImpSym = Symtab->addImportData(ImpName, this);
504+
// If this was a duplicate, we logged an error but may continue;
505+
// in this case, ImpSym is nullptr.
506+
if (!ImpSym)
507+
return;
504508

505509
if (Hdr->getType() == llvm::COFF::IMPORT_CONST)
506510
static_cast<void>(Symtab->addImportData(Name, this));

src/llvm/tools/lld/COFF/InputFiles.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "llvm/ADT/ArrayRef.h"
1616
#include "llvm/ADT/DenseMap.h"
1717
#include "llvm/ADT/DenseSet.h"
18+
#include "llvm/DebugInfo/CodeView/TypeRecord.h"
1819
#include "llvm/LTO/LTO.h"
1920
#include "llvm/Object/Archive.h"
2021
#include "llvm/Object/COFF.h"
@@ -122,9 +123,12 @@ class ObjFile : public InputFile {
122123
return Symbols[SymbolIndex];
123124
}
124125

125-
// Returns the underying COFF file.
126+
// Returns the underlying COFF file.
126127
COFFObjectFile *getCOFFObj() { return COFFObj.get(); }
127128

129+
// Whether the object was already merged into the final PDB or not
130+
bool wasProcessedForPDB() const { return !!ModuleDBI; }
131+
128132
static std::vector<ObjFile *> Instances;
129133

130134
// Flags in the absolute @feat.00 symbol if it is present. These usually
@@ -147,6 +151,11 @@ class ObjFile : public InputFile {
147151

148152
const coff_section *AddrsigSec = nullptr;
149153

154+
// When using Microsoft precompiled headers, this is the PCH's key.
155+
// The same key is used by both the precompiled object, and objects using the
156+
// precompiled object. Any difference indicates out-of-date objects.
157+
llvm::Optional<llvm::codeview::EndPrecompRecord> EndPrecomp;
158+
150159
private:
151160
void initializeChunks();
152161
void initializeSymbols();

src/llvm/tools/lld/COFF/LTO.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ static std::unique_ptr<lto::LTO> createLTO() {
6060
C.DisableVerify = true;
6161
C.DiagHandler = diagnosticHandler;
6262
C.OptLevel = Config->LTOO;
63+
C.MAttrs = GetMAttrs();
64+
6365
if (Config->SaveTemps)
6466
checkError(C.addSaveTemps(std::string(Config->OutputFile) + ".",
6567
/*UseInputModulePath*/ true));

src/llvm/tools/lld/COFF/MinGW.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ AutoExporter::AutoExporter() {
8484
"libsupc++",
8585
"libobjc",
8686
"libgcj",
87+
"libclang_rt.builtins",
8788
"libclang_rt.builtins-aarch64",
8889
"libclang_rt.builtins-arm",
8990
"libclang_rt.builtins-i386",

0 commit comments

Comments
 (0)