Index: COFF/Writer.cpp =================================================================== --- COFF/Writer.cpp +++ COFF/Writer.cpp @@ -606,16 +606,28 @@ if (isa(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; }