Remove an unused accessor and simplify the logic a bit. NFC.
authorRui Ueyama <ruiu@google.com>
Sat, 17 Feb 2018 20:41:38 +0000 (20:41 +0000)
committerRui Ueyama <ruiu@google.com>
Sat, 17 Feb 2018 20:41:38 +0000 (20:41 +0000)
llvm-svn: 325445

lld/COFF/Chunks.cpp
lld/COFF/Symbols.cpp
lld/COFF/Symbols.h
lld/COFF/Writer.cpp

index 1d2c5d9..aceb4fb 100644 (file)
@@ -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,
index 4c5ab48..798c744 100644 (file)
@@ -71,7 +71,7 @@ COFFSymbolRef DefinedCOFF::getCOFFSymbol() {
   return COFFSymbolRef(reinterpret_cast<const coff_symbol32 *>(Sym));
 }
 
-uint16_t DefinedAbsolute::OutputSectionIndex = 0;
+uint16_t DefinedAbsolute::NumOutputSections;
 
 static Chunk *makeImportThunk(DefinedImportData *S, uint16_t Machine) {
   if (Machine == AMD64)
index 930ed3c..783965a 100644 (file)
@@ -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;
index 2766735..bb621eb 100644 (file)
@@ -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) {