Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions llvm/lib/MC/MachObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/SMLoc.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
Expand Down Expand Up @@ -584,7 +585,12 @@ void MachObjectWriter::computeSymbolTable(
unsigned Index = 1;
for (MCSection &Sec : Asm)
SectionIndexMap[&Sec] = Index++;
assert(Index <= 256 && "Too many sections!");

// Section indices begin from 1 in MachO. Only sections 1-255 can be indexed
// into section symbols. Referencing a section with index larger than 255 will
// not set n_sect for these symbols.
if (Index > 255)
getContext().reportError(SMLoc(), "Too many sections!");

// Build the string table.
for (const MCSymbol &Symbol : Asm.symbols()) {
Expand Down Expand Up @@ -621,7 +627,8 @@ void MachObjectWriter::computeSymbolTable(
ExternalSymbolData.push_back(MSD);
} else {
MSD.SectionIndex = SectionIndexMap.lookup(&Symbol.getSection());
assert(MSD.SectionIndex && "Invalid section index!");
if (!MSD.SectionIndex)
getContext().reportError(SMLoc(), "Invalid section index!");
ExternalSymbolData.push_back(MSD);
}
}
Expand All @@ -645,7 +652,8 @@ void MachObjectWriter::computeSymbolTable(
LocalSymbolData.push_back(MSD);
} else {
MSD.SectionIndex = SectionIndexMap.lookup(&Symbol.getSection());
assert(MSD.SectionIndex && "Invalid section index!");
if (!MSD.SectionIndex)
getContext().reportError(SMLoc(), "Invalid section index!");
LocalSymbolData.push_back(MSD);
}
}
Expand Down
Loading
Loading