[llvm] r235994 - Avoid an extra loop for computing the section size. NFC.
Rafael Espindola
rafael.espindola at gmail.com
Tue Apr 28 08:04:09 PDT 2015
Author: rafael
Date: Tue Apr 28 10:04:09 2015
New Revision: 235994
URL: http://llvm.org/viewvc/llvm-project?rev=235994&view=rev
Log:
Avoid an extra loop for computing the section size. NFC.
Modified:
llvm/trunk/lib/MC/ELFObjectWriter.cpp
Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=235994&r1=235993&r2=235994&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Tue Apr 28 10:04:09 2015
@@ -91,9 +91,6 @@ class ELFObjectWriter : public MCObjectW
bool Used, bool Renamed);
static bool isLocal(const MCSymbolData &Data, bool isUsedInReloc);
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,
const MCSectionData &SD);
@@ -224,8 +221,9 @@ class ELFObjectWriter : public MCObjectW
typedef DenseMap<const MCSectionELF*, const MCSymbol*> GroupMapTy;
// Map from a signature symbol to the group section
typedef DenseMap<const MCSymbol*, const MCSectionELF*> RevGroupMapTy;
- // Map from a section to its offset
- typedef DenseMap<const MCSectionELF*, uint64_t> SectionOffsetMapTy;
+ // Map from a section to its start and end offset
+ typedef DenseMap<const MCSectionELF *, std::pair<uint64_t, uint64_t>>
+ SectionOffsetMapTy;
/// Compute the symbol table data
///
@@ -1533,24 +1531,6 @@ bool ELFObjectWriter::IsELFMetaDataSecti
!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,
const MCAsmLayout &Layout,
const MCSectionData &SD) {
@@ -1590,11 +1570,14 @@ void ELFObjectWriter::writeSectionHeader
GroupSymbolIndex = getSymbolIndexInSymbolTable(Asm,
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,
- SectionOffsetMap.lookup(&Section), Size, SD.getAlignment(),
- Section);
+ writeSection(Asm, SectionIndexMap, GroupSymbolIndex, Offsets.first, Size,
+ SD.getAlignment(), Section);
}
}
@@ -1637,9 +1620,10 @@ void ELFObjectWriter::WriteObject(MCAsse
WriteZeros(Padding);
// Remember the offset into the file for this section.
- SectionOffsetMap[&Section] = OS.tell();
-
+ uint64_t SecStart = OS.tell();
writeDataSectionData(Asm, Layout, SD);
+ uint64_t SecEnd = OS.tell();
+ SectionOffsetMap[&Section] = std::make_pair(SecStart, SecEnd);
}
uint64_t NaturalAlignment = is64Bit() ? 8 : 4;
More information about the llvm-commits
mailing list