[lld] r333472 - [COFF] Unify output section code. NFC
Shoaib Meenai via llvm-commits
llvm-commits at lists.llvm.org
Tue May 29 15:49:56 PDT 2018
Author: smeenai
Date: Tue May 29 15:49:56 2018
New Revision: 333472
URL: http://llvm.org/viewvc/llvm-project?rev=333472&view=rev
Log:
[COFF] Unify output section code. NFC
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.
Differential Revision: https://reviews.llvm.org/D47497
Modified:
lld/trunk/COFF/Writer.cpp
Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=333472&r1=333471&r2=333472&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Tue May 29 15:49:56 2018
@@ -602,20 +602,28 @@ size_t Writer::addEntryToStringTable(Str
}
Optional<coff_symbol16> Writer::createSymbol(Defined *Def) {
- // Relative symbols are unrepresentable in a COFF symbol table.
- if (isa<DefinedSynthetic>(Def))
+ coff_symbol16 Sym;
+ switch (Def->kind()) {
+ case Symbol::DefinedAbsoluteKind:
+ Sym.Value = Def->getRVA();
+ Sym.SectionNumber = IMAGE_SYM_ABSOLUTE;
+ break;
+ case Symbol::DefinedSyntheticKind:
+ // Relative symbols are unrepresentable in a COFF symbol table.
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();
+ default: {
+ // Don't write symbols that won't be written to the output to the symbol
+ // table.
+ OutputSection *OS = Def->getChunk()->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 +642,6 @@ Optional<coff_symbol16> Writer::createSy
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;
}
More information about the llvm-commits
mailing list