From 9a9984d0b52477f0bcd9e95bf3af08b7d4a7bcc7 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 21 May 2015 19:46:39 +0000 Subject: [PATCH] Pass a const MCAssembler to writeSectionHeader. It never creates sections, so it can use Asm.getSectionData instead of Asm.getOrCreateSectionData. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237943 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/ELFObjectWriter.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp index f1ba758dad5..ad3debf090b 100644 --- a/lib/MC/ELFObjectWriter.cpp +++ b/lib/MC/ELFObjectWriter.cpp @@ -230,7 +230,7 @@ class ELFObjectWriter : public MCObjectWriter { void ExecutePostLayoutBinding(MCAssembler &Asm, const MCAsmLayout &Layout) override; - void writeSectionHeader(MCAssembler &Asm, const MCAsmLayout &Layout, + void writeSectionHeader(const MCAssembler &Asm, const MCAsmLayout &Layout, const SectionIndexMapTy &SectionIndexMap, const SectionOffsetsTy &SectionOffsets); @@ -1299,7 +1299,7 @@ void ELFObjectWriter::writeSection(const SectionIndexMapTy &SectionIndexMap, } void ELFObjectWriter::writeSectionHeader( - MCAssembler &Asm, const MCAsmLayout &Layout, + const MCAssembler &Asm, const MCAsmLayout &Layout, const SectionIndexMapTy &SectionIndexMap, const SectionOffsetsTy &SectionOffsets) { const unsigned NumSections = SectionTable.size(); @@ -1310,7 +1310,6 @@ void ELFObjectWriter::writeSectionHeader( WriteSecHdrEntry(0, 0, 0, 0, 0, FirstSectionSize, 0, 0, 0, 0); for (MCSectionELF *Section : SectionTable) { - const MCSectionData &SD = Asm.getOrCreateSectionData(*Section); uint32_t GroupSymbolIndex; unsigned Type = Section->getType(); if (Type != ELF::SHT_GROUP) @@ -1320,8 +1319,13 @@ void ELFObjectWriter::writeSectionHeader( const std::pair &Offsets = SectionOffsets.find(Section)->second; - uint64_t Size = Type == ELF::SHT_NOBITS ? Layout.getSectionAddressSize(&SD) - : Offsets.second - Offsets.first; + uint64_t Size; + if (Type == ELF::SHT_NOBITS) { + const MCSectionData &SD = Asm.getSectionData(*Section); + Size = Layout.getSectionAddressSize(&SD); + } else { + Size = Offsets.second - Offsets.first; + } writeSection(SectionIndexMap, GroupSymbolIndex, Offsets.first, Size, *Section);