[PATCH] D47497: [COFF] Unify output section code. NFC

Shoaib Meenai via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 29 14:55:56 PDT 2018


smeenai created this revision.
smeenai added reviewers: pcc, rnk, ruiu.

Peter Collingbourne suggested moving the switch to the top of the
function, so that all the code that cares about the output section for a
symbol is in the same place.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D47497

Files:
  COFF/Writer.cpp


Index: COFF/Writer.cpp
===================================================================
--- COFF/Writer.cpp
+++ COFF/Writer.cpp
@@ -606,16 +606,28 @@
   if (isa<DefinedSynthetic>(Def))
     return None;
 
-  // Don't write symbols that won't be written to the output to the symbol
-  // table.
-  OutputSection *OS = nullptr;
-  if (Chunk *C = Def->getChunk()) {
-    OS = C->getOutputSection();
+  coff_symbol16 Sym;
+
+  switch (Def->kind()) {
+  case Symbol::DefinedAbsoluteKind:
+    Sym.Value = Def->getRVA();
+    Sym.SectionNumber = IMAGE_SYM_ABSOLUTE;
+    break;
+  default: {
+    // Don't write symbols that won't be written to the output to the symbol
+    // table.
+    Chunk *C = Def->getChunk();
+    assert(C && "non-absolute and non-synthetic symbol without a chunk");
+    OutputSection *OS = C->getOutputSection();
     if (!OS)
       return None;
+
+    Sym.Value = Def->getRVA() - OS->getRVA();
+    Sym.SectionNumber = OS->SectionIndex;
+    break;
+  }
   }
 
-  coff_symbol16 Sym;
   StringRef Name = Def->getName();
   if (Name.size() > COFF::NameSize) {
     Sym.Name.Offset.Zeroes = 0;
@@ -634,19 +646,6 @@
     Sym.StorageClass = IMAGE_SYM_CLASS_EXTERNAL;
   }
   Sym.NumberOfAuxSymbols = 0;
-
-  switch (Def->kind()) {
-  case Symbol::DefinedAbsoluteKind:
-    Sym.Value = Def->getRVA();
-    Sym.SectionNumber = IMAGE_SYM_ABSOLUTE;
-    break;
-  default: {
-    assert(OS && "Writing dead symbol to symbol table");
-    Sym.Value = Def->getRVA() - OS->getRVA();
-    Sym.SectionNumber = OS->SectionIndex;
-    break;
-  }
-  }
   return Sym;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47497.148990.patch
Type: text/x-patch
Size: 1583 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180529/145d8299/attachment.bin>


More information about the llvm-commits mailing list