diff options
author | David Majnemer <david.majnemer@gmail.com> | 2014-08-28 04:02:50 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2014-08-28 04:02:50 +0000 |
commit | 9ab5ff1c5b4b944f6467a96a019bac3d7c754dd2 (patch) | |
tree | 364e907eb88c5721777fbbf4250dfe5253fbb770 /llvm/lib/MC | |
parent | c01ce6bc01369688efb0b9c8341d215a342dd9fc (diff) | |
download | bcm5719-llvm-9ab5ff1c5b4b944f6467a96a019bac3d7c754dd2.tar.gz bcm5719-llvm-9ab5ff1c5b4b944f6467a96a019bac3d7c754dd2.zip |
MC: Don't crash when the COFF section limit is reached
I've decided not to commit a test, it takes 2.5 seconds to run on my an
incredibly strong machine.
llvm-svn: 216647
Diffstat (limited to 'llvm/lib/MC')
-rw-r--r-- | llvm/lib/MC/WinCOFFObjectWriter.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/llvm/lib/MC/WinCOFFObjectWriter.cpp b/llvm/lib/MC/WinCOFFObjectWriter.cpp index 824895be32d..2de65c798be 100644 --- a/llvm/lib/MC/WinCOFFObjectWriter.cpp +++ b/llvm/lib/MC/WinCOFFObjectWriter.cpp @@ -840,18 +840,23 @@ void WinCOFFObjectWriter::RecordRelocation(const MCAssembler &Asm, void WinCOFFObjectWriter::WriteObject(MCAssembler &Asm, const MCAsmLayout &Layout) { // Assign symbol and section indexes and offsets. - Header.NumberOfSections = 0; + size_t NumberOfSections = 0; DenseMap<COFFSection *, uint16_t> SectionIndices; - for (auto & Section : Sections) { - size_t Number = ++Header.NumberOfSections; - SectionIndices[Section.get()] = Number; + for (const auto &Section : Sections) { + size_t Number = ++NumberOfSections; + SectionIndices[Section.get()] = static_cast<uint16_t>(Number); MakeSectionReal(*Section, Number); } + if (NumberOfSections > COFF::MaxNumberOfSections) + report_fatal_error( + "PE COFF object files can't have more than 65,299 sections"); + + Header.NumberOfSections = static_cast<uint16_t>(NumberOfSections); Header.NumberOfSymbols = 0; - for (auto & Symbol : Symbols) { + for (auto &Symbol : Symbols) { // Update section number & offset for symbols that have them. if (Symbol->Section) Symbol->Data.SectionNumber = Symbol->Section->Number; @@ -929,7 +934,7 @@ void WinCOFFObjectWriter::WriteObject(MCAssembler &Asm, bool RelocationsOverflow = Sec->Relocations.size() >= 0xffff; if (RelocationsOverflow) { - // Signal overflow by setting NumberOfSections to max value. Actual + // Signal overflow by setting NumberOfRelocations to max value. Actual // size is found in reloc #0. Microsoft tools understand this. Sec->Header.NumberOfRelocations = 0xffff; } else { |