From b3107476a416bdfc284a17d4a20706bc0d435eb8 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Sat, 17 Feb 2018 20:41:38 +0000 Subject: [PATCH] Remove an unused accessor and simplify the logic a bit. NFC. llvm-svn: 325445 --- lld/COFF/Chunks.cpp | 11 +++++++---- lld/COFF/Symbols.cpp | 2 +- lld/COFF/Symbols.h | 9 ++++----- lld/COFF/Writer.cpp | 6 +++--- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/lld/COFF/Chunks.cpp b/lld/COFF/Chunks.cpp index 1d2c5d9..aceb4fb 100644 --- a/lld/COFF/Chunks.cpp +++ b/lld/COFF/Chunks.cpp @@ -75,10 +75,13 @@ static void applySecRel(const SectionChunk *Sec, uint8_t *Off, } static void applySecIdx(uint8_t *Off, OutputSection *OS) { - // If we have no output section, this must be an absolute symbol. Use the - // sentinel absolute symbol section index. - uint16_t SecIdx = OS ? OS->SectionIndex : DefinedAbsolute::OutputSectionIndex; - add16(Off, SecIdx); + // Absolute symbol doesn't have section index, but section index relocation + // against absolute symbol should be resolved to one plus the last output + // section index. This is required for compatibility with MSVC. + if (OS) + add16(Off, OS->SectionIndex); + else + add16(Off, DefinedAbsolute::NumOutputSections + 1); } void SectionChunk::applyRelX64(uint8_t *Off, uint16_t Type, OutputSection *OS, diff --git a/lld/COFF/Symbols.cpp b/lld/COFF/Symbols.cpp index 4c5ab48..798c744 100644 --- a/lld/COFF/Symbols.cpp +++ b/lld/COFF/Symbols.cpp @@ -71,7 +71,7 @@ COFFSymbolRef DefinedCOFF::getCOFFSymbol() { return COFFSymbolRef(reinterpret_cast(Sym)); } -uint16_t DefinedAbsolute::OutputSectionIndex = 0; +uint16_t DefinedAbsolute::NumOutputSections; static Chunk *makeImportThunk(DefinedImportData *S, uint16_t Machine) { if (Machine == AMD64) diff --git a/lld/COFF/Symbols.h b/lld/COFF/Symbols.h index 930ed3c..783965a 100644 --- a/lld/COFF/Symbols.h +++ b/lld/COFF/Symbols.h @@ -213,11 +213,10 @@ public: uint64_t getRVA() { return VA - Config->ImageBase; } void setVA(uint64_t V) { VA = V; } - // The sentinel absolute symbol section index. Section index relocations - // against absolute symbols resolve to this 16 bit number, and it is the - // largest valid section index plus one. This is written by the Writer. - static uint16_t OutputSectionIndex; - uint16_t getSecIdx() { return OutputSectionIndex; } + // Section index relocations against absolute symbols resolve to + // this 16 bit number, and it is the largest valid section index + // plus one. This variable keeps it. + static uint16_t NumOutputSections; private: uint64_t VA; diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp index 2766735..bb621eb 100644 --- a/lld/COFF/Writer.cpp +++ b/lld/COFF/Writer.cpp @@ -1008,9 +1008,9 @@ void Writer::setSectionPermissions() { // Write section contents to a mmap'ed file. void Writer::writeSections() { - // Record the section index that should be used when resolving a section - // relocation against an absolute symbol. - DefinedAbsolute::OutputSectionIndex = OutputSections.size() + 1; + // Record the number of sections to apply section index relocations + // against absolute symbols. See applySecIdx in Chunks.cpp.. + DefinedAbsolute::NumOutputSections = OutputSections.size(); uint8_t *Buf = Buffer->getBufferStart(); for (OutputSection *Sec : OutputSections) { -- 2.7.4