Avoid an extra loop for computing the section size. NFC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235994 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2015-04-28 15:04:09 +00:00
parent 83259d70bb
commit 39dfabd785

View File

@ -91,9 +91,6 @@ class ELFObjectWriter : public MCObjectWriter {
bool Used, bool Renamed); bool Used, bool Renamed);
static bool isLocal(const MCSymbolData &Data, bool isUsedInReloc); static bool isLocal(const MCSymbolData &Data, bool isUsedInReloc);
static bool IsELFMetaDataSection(const MCSectionData &SD); static bool IsELFMetaDataSection(const MCSectionData &SD);
static uint64_t DataSectionSize(const MCSectionData &SD);
static uint64_t GetSectionAddressSize(const MCAsmLayout &Layout,
const MCSectionData &SD);
void writeDataSectionData(MCAssembler &Asm, const MCAsmLayout &Layout, void writeDataSectionData(MCAssembler &Asm, const MCAsmLayout &Layout,
const MCSectionData &SD); const MCSectionData &SD);
@ -224,8 +221,9 @@ class ELFObjectWriter : public MCObjectWriter {
typedef DenseMap<const MCSectionELF*, const MCSymbol*> GroupMapTy; typedef DenseMap<const MCSectionELF*, const MCSymbol*> GroupMapTy;
// Map from a signature symbol to the group section // Map from a signature symbol to the group section
typedef DenseMap<const MCSymbol*, const MCSectionELF*> RevGroupMapTy; typedef DenseMap<const MCSymbol*, const MCSectionELF*> RevGroupMapTy;
// Map from a section to its offset // Map from a section to its start and end offset
typedef DenseMap<const MCSectionELF*, uint64_t> SectionOffsetMapTy; typedef DenseMap<const MCSectionELF *, std::pair<uint64_t, uint64_t>>
SectionOffsetMapTy;
/// Compute the symbol table data /// Compute the symbol table data
/// ///
@ -1533,24 +1531,6 @@ bool ELFObjectWriter::IsELFMetaDataSection(const MCSectionData &SD) {
!SD.getSection().isVirtualSection(); !SD.getSection().isVirtualSection();
} }
uint64_t ELFObjectWriter::DataSectionSize(const MCSectionData &SD) {
uint64_t Ret = 0;
for (MCSectionData::const_iterator i = SD.begin(), e = SD.end(); i != e;
++i) {
const MCFragment &F = *i;
assert(F.getKind() == MCFragment::FT_Data);
Ret += cast<MCDataFragment>(F).getContents().size();
}
return Ret;
}
uint64_t ELFObjectWriter::GetSectionAddressSize(const MCAsmLayout &Layout,
const MCSectionData &SD) {
if (IsELFMetaDataSection(SD))
return DataSectionSize(SD);
return Layout.getSectionAddressSize(&SD);
}
void ELFObjectWriter::writeDataSectionData(MCAssembler &Asm, void ELFObjectWriter::writeDataSectionData(MCAssembler &Asm,
const MCAsmLayout &Layout, const MCAsmLayout &Layout,
const MCSectionData &SD) { const MCSectionData &SD) {
@ -1590,11 +1570,14 @@ void ELFObjectWriter::writeSectionHeader(
GroupSymbolIndex = getSymbolIndexInSymbolTable(Asm, GroupSymbolIndex = getSymbolIndexInSymbolTable(Asm,
GroupMap.lookup(&Section)); GroupMap.lookup(&Section));
uint64_t Size = GetSectionAddressSize(Layout, SD); const std::pair<uint64_t, uint64_t> &Offsets =
SectionOffsetMap.lookup(&Section);
uint64_t Size = Section.getType() == ELF::SHT_NOBITS
? Layout.getSectionAddressSize(&SD)
: Offsets.second - Offsets.first;
writeSection(Asm, SectionIndexMap, GroupSymbolIndex, writeSection(Asm, SectionIndexMap, GroupSymbolIndex, Offsets.first, Size,
SectionOffsetMap.lookup(&Section), Size, SD.getAlignment(), SD.getAlignment(), Section);
Section);
} }
} }
@ -1637,9 +1620,10 @@ void ELFObjectWriter::WriteObject(MCAssembler &Asm,
WriteZeros(Padding); WriteZeros(Padding);
// Remember the offset into the file for this section. // Remember the offset into the file for this section.
SectionOffsetMap[&Section] = OS.tell(); uint64_t SecStart = OS.tell();
writeDataSectionData(Asm, Layout, SD); writeDataSectionData(Asm, Layout, SD);
uint64_t SecEnd = OS.tell();
SectionOffsetMap[&Section] = std::make_pair(SecStart, SecEnd);
} }
uint64_t NaturalAlignment = is64Bit() ? 8 : 4; uint64_t NaturalAlignment = is64Bit() ? 8 : 4;