diff options
| author | Reid Kleckner <rnk@google.com> | 2018-08-16 21:34:41 +0000 |
|---|---|---|
| committer | Reid Kleckner <rnk@google.com> | 2018-08-16 21:34:41 +0000 |
| commit | 602c0dafdd022f23a26506fb26c6ce8ec7ae8a4d (patch) | |
| tree | 7b67665c3e8d54f7687a168215526a0002d7bcd8 /llvm/lib/MC | |
| parent | 19763d93fdbe678485ff97fc43ac7472a7cdf807 (diff) | |
| download | bcm5719-llvm-602c0dafdd022f23a26506fb26c6ce8ec7ae8a4d.tar.gz bcm5719-llvm-602c0dafdd022f23a26506fb26c6ce8ec7ae8a4d.zip | |
[MC] Improve COFF associative section lookup
Handle the case when the symbol is private. Private symbols are not in
the COFF object file symbol table, so they aren't inserted into
SymbolMap. We can't look up the section of the symbol that way. Instead,
get the MCSection from the MCSymbol and map that to the object file
section.
Print a better error message when the symbol has no section, like when
the symbol is undefined.
Fixes PR38607
llvm-svn: 339942
Diffstat (limited to 'llvm/lib/MC')
| -rw-r--r-- | llvm/lib/MC/WinCOFFObjectWriter.cpp | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/llvm/lib/MC/WinCOFFObjectWriter.cpp b/llvm/lib/MC/WinCOFFObjectWriter.cpp index 9ffecd99df6..f63d491c825 100644 --- a/llvm/lib/MC/WinCOFFObjectWriter.cpp +++ b/llvm/lib/MC/WinCOFFObjectWriter.cpp @@ -1020,22 +1020,28 @@ uint64_t WinCOFFObjectWriter::writeObject(MCAssembler &Asm, continue; const MCSectionCOFF &MCSec = *Section->MCSection; + const MCSymbol *AssocMCSym = MCSec.getCOMDATSymbol(); + assert(AssocMCSym); - const MCSymbol *COMDAT = MCSec.getCOMDATSymbol(); - assert(COMDAT); - COFFSymbol *COMDATSymbol = GetOrCreateCOFFSymbol(COMDAT); - assert(COMDATSymbol); - COFFSection *Assoc = COMDATSymbol->Section; - if (!Assoc) - report_fatal_error( - Twine("Missing associated COMDAT section for section ") + - MCSec.getSectionName()); + // It's an error to try to associate with an undefined symbol or a symbol + // without a section. + if (!AssocMCSym->isInSection()) { + Asm.getContext().reportError( + SMLoc(), Twine("cannot make section ") + MCSec.getSectionName() + + Twine(" associative with sectionless symbol ") + + AssocMCSym->getName()); + continue; + } + + const auto *AssocMCSec = cast<MCSectionCOFF>(&AssocMCSym->getSection()); + assert(SectionMap.count(AssocMCSec)); + COFFSection *AssocSec = SectionMap[AssocMCSec]; // Skip this section if the associated section is unused. - if (Assoc->Number == -1) + if (AssocSec->Number == -1) continue; - Section->Symbol->Aux[0].Aux.SectionDefinition.Number = Assoc->Number; + Section->Symbol->Aux[0].Aux.SectionDefinition.Number = AssocSec->Number; } assignFileOffsets(Asm, Layout); |

