[PDB] Simplify API for making section map, NFC

Prevents API misuse described in PR44495
This commit is contained in:
Reid Kleckner 2020-01-23 12:11:50 -08:00
parent cbcd07a481
commit e5caa156b4
3 changed files with 9 additions and 21 deletions

View File

@ -178,8 +178,6 @@ private:
llvm::SmallString<128> nativePath; llvm::SmallString<128> nativePath;
std::vector<pdb::SecMapEntry> sectionMap;
/// Type index mappings of type server PDBs that we've loaded so far. /// Type index mappings of type server PDBs that we've loaded so far.
std::map<codeview::GUID, CVIndexMap> typeServerIndexMappings; std::map<codeview::GUID, CVIndexMap> typeServerIndexMappings;
@ -1766,8 +1764,7 @@ void PDBLinker::addSections(ArrayRef<OutputSection *> outputSections,
ArrayRef<object::coff_section> sections = { ArrayRef<object::coff_section> sections = {
(const object::coff_section *)sectionTable.data(), (const object::coff_section *)sectionTable.data(),
sectionTable.size() / sizeof(object::coff_section)}; sectionTable.size() / sizeof(object::coff_section)};
sectionMap = pdb::DbiStreamBuilder::createSectionMap(sections); dbiBuilder.createSectionMap(sections);
dbiBuilder.setSectionMap(sectionMap);
// Add COFF section header stream. // Add COFF section header stream.
exitOnErr( exitOnErr(

View File

@ -57,7 +57,6 @@ public:
void setFlags(uint16_t F); void setFlags(uint16_t F);
void setMachineType(PDB_Machine M); void setMachineType(PDB_Machine M);
void setMachineType(COFF::MachineTypes M); void setMachineType(COFF::MachineTypes M);
void setSectionMap(ArrayRef<SecMapEntry> SecMap);
// Add given bytes as a new stream. // Add given bytes as a new stream.
Error addDbgStream(pdb::DbgHeaderType Type, ArrayRef<uint8_t> Data); Error addDbgStream(pdb::DbgHeaderType Type, ArrayRef<uint8_t> Data);
@ -84,9 +83,8 @@ public:
SectionContribs.emplace_back(SC); SectionContribs.emplace_back(SC);
} }
// A helper function to create a Section Map from a COFF section header. // Populate the Section Map from COFF section headers.
static std::vector<SecMapEntry> void createSectionMap(ArrayRef<llvm::object::coff_section> SecHdrs);
createSectionMap(ArrayRef<llvm::object::coff_section> SecHdrs);
private: private:
struct DebugStream { struct DebugStream {
@ -133,7 +131,7 @@ private:
WritableBinaryStreamRef NamesBuffer; WritableBinaryStreamRef NamesBuffer;
MutableBinaryByteStream FileInfoBuffer; MutableBinaryByteStream FileInfoBuffer;
std::vector<SectionContrib> SectionContribs; std::vector<SectionContrib> SectionContribs;
ArrayRef<SecMapEntry> SectionMap; std::vector<SecMapEntry> SectionMap;
std::array<Optional<DebugStream>, (int)DbgHeaderType::Max> DbgStreams; std::array<Optional<DebugStream>, (int)DbgHeaderType::Max> DbgStreams;
}; };
} }

View File

@ -58,10 +58,6 @@ void DbiStreamBuilder::setMachineType(COFF::MachineTypes M) {
MachineType = static_cast<pdb::PDB_Machine>(static_cast<unsigned>(M)); MachineType = static_cast<pdb::PDB_Machine>(static_cast<unsigned>(M));
} }
void DbiStreamBuilder::setSectionMap(ArrayRef<SecMapEntry> SecMap) {
SectionMap = SecMap;
}
void DbiStreamBuilder::setGlobalsStreamIndex(uint32_t Index) { void DbiStreamBuilder::setGlobalsStreamIndex(uint32_t Index) {
GlobalsStreamIndex = Index; GlobalsStreamIndex = Index;
} }
@ -348,19 +344,18 @@ static uint16_t toSecMapFlags(uint32_t Flags) {
return Ret; return Ret;
} }
// A utility function to create a Section Map for a given list of COFF sections. // Populate the Section Map from COFF section headers.
// //
// A Section Map seem to be a copy of a COFF section list in other format. // A Section Map seem to be a copy of a COFF section list in other format.
// I don't know why a PDB file contains both a COFF section header and // I don't know why a PDB file contains both a COFF section header and
// a Section Map, but it seems it must be present in a PDB. // a Section Map, but it seems it must be present in a PDB.
std::vector<SecMapEntry> DbiStreamBuilder::createSectionMap( void DbiStreamBuilder::createSectionMap(
ArrayRef<llvm::object::coff_section> SecHdrs) { ArrayRef<llvm::object::coff_section> SecHdrs) {
std::vector<SecMapEntry> Ret;
int Idx = 0; int Idx = 0;
auto Add = [&]() -> SecMapEntry & { auto Add = [&]() -> SecMapEntry & {
Ret.emplace_back(); SectionMap.emplace_back();
auto &Entry = Ret.back(); auto &Entry = SectionMap.back();
memset(&Entry, 0, sizeof(Entry)); memset(&Entry, 0, sizeof(Entry));
Entry.Frame = Idx + 1; Entry.Frame = Idx + 1;
@ -384,8 +379,6 @@ std::vector<SecMapEntry> DbiStreamBuilder::createSectionMap(
Entry.Flags = static_cast<uint16_t>(OMFSegDescFlags::AddressIs32Bit) | Entry.Flags = static_cast<uint16_t>(OMFSegDescFlags::AddressIs32Bit) |
static_cast<uint16_t>(OMFSegDescFlags::IsAbsoluteAddress); static_cast<uint16_t>(OMFSegDescFlags::IsAbsoluteAddress);
Entry.SecByteLength = UINT32_MAX; Entry.SecByteLength = UINT32_MAX;
return Ret;
} }
Error DbiStreamBuilder::commit(const msf::MSFLayout &Layout, Error DbiStreamBuilder::commit(const msf::MSFLayout &Layout,
@ -417,7 +410,7 @@ Error DbiStreamBuilder::commit(const msf::MSFLayout &Layout,
SecMapHeader SMHeader = {Size, Size}; SecMapHeader SMHeader = {Size, Size};
if (auto EC = Writer.writeObject(SMHeader)) if (auto EC = Writer.writeObject(SMHeader))
return EC; return EC;
if (auto EC = Writer.writeArray(SectionMap)) if (auto EC = Writer.writeArray(makeArrayRef(SectionMap)))
return EC; return EC;
} }