summaryrefslogtreecommitdiffstats
path: root/llvm/lib/MC
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2016-05-25 00:14:12 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2016-05-25 00:14:12 +0000
commitb910e566049ffd9b1f285b29cd4dfe124aad3a12 (patch)
treeaa9dd201385584a680108431abb3fe8d75693313 /llvm/lib/MC
parent172d59c105ea99da09bbbef25698e94b8358bf20 (diff)
downloadbcm5719-llvm-b910e566049ffd9b1f285b29cd4dfe124aad3a12.tar.gz
bcm5719-llvm-b910e566049ffd9b1f285b29cd4dfe124aad3a12.zip
Revert r270569 (teach llvm-mc to generate compressed debug sections in zlib
style). It appears that current ELF linkers are not ready for this. llvm-svn: 270638
Diffstat (limited to 'llvm/lib/MC')
-rw-r--r--llvm/lib/MC/ELFObjectWriter.cpp44
-rw-r--r--llvm/lib/MC/MCContext.cpp16
2 files changed, 39 insertions, 21 deletions
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index 4ba5bf143ce..900dcf51a26 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -979,6 +979,26 @@ ELFObjectWriter::createRelocationSection(MCContext &Ctx,
return RelaSection;
}
+// Include the debug info compression header:
+// "ZLIB" followed by 8 bytes representing the uncompressed size of the section,
+// useful for consumers to preallocate a buffer to decompress into.
+static bool
+prependCompressionHeader(uint64_t Size,
+ SmallVectorImpl<char> &CompressedContents) {
+ const StringRef Magic = "ZLIB";
+ if (Size <= Magic.size() + sizeof(Size) + CompressedContents.size())
+ return false;
+ if (sys::IsLittleEndianHost)
+ sys::swapByteOrder(Size);
+ CompressedContents.insert(CompressedContents.begin(),
+ Magic.size() + sizeof(Size), 0);
+ std::copy(Magic.begin(), Magic.end(), CompressedContents.begin());
+ std::copy(reinterpret_cast<char *>(&Size),
+ reinterpret_cast<char *>(&Size + 1),
+ CompressedContents.begin() + Magic.size());
+ return true;
+}
+
void ELFObjectWriter::writeSectionData(const MCAssembler &Asm, MCSection &Sec,
const MCAsmLayout &Layout) {
MCSectionELF &Section = static_cast<MCSectionELF &>(Sec);
@@ -1009,30 +1029,12 @@ void ELFObjectWriter::writeSectionData(const MCAssembler &Asm, MCSection &Sec,
return;
}
- uint64_t HdrSize =
- is64Bit() ? sizeof(ELF::Elf32_Chdr) : sizeof(ELF::Elf64_Chdr);
- if (UncompressedData.size() <= HdrSize + CompressedContents.size()) {
+ if (!prependCompressionHeader(UncompressedData.size(), CompressedContents)) {
getStream() << UncompressedData;
return;
}
-
- // Set the compressed flag. That is zlib style.
- Section.setFlags(Section.getFlags() | ELF::SHF_COMPRESSED);
-
- // Platform specific header is followed by compressed data.
- if (is64Bit()) {
- // Write Elf64_Chdr header.
- write(static_cast<ELF::Elf64_Word>(ELF::ELFCOMPRESS_ZLIB));
- write(static_cast<ELF::Elf64_Word>(0)); // ch_reserved field.
- write(static_cast<ELF::Elf64_Xword>(UncompressedData.size()));
- write(static_cast<ELF::Elf64_Xword>(Sec.getAlignment()));
- } else {
- // Write Elf32_Chdr header otherwise.
- write(static_cast<ELF::Elf32_Word>(ELF::ELFCOMPRESS_ZLIB));
- write(static_cast<ELF::Elf32_Word>(UncompressedData.size()));
- write(static_cast<ELF::Elf32_Word>(Sec.getAlignment()));
- }
-
+ Asm.getContext().renameELFSection(&Section,
+ (".z" + SectionName.drop_front(1)).str());
getStream() << CompressedContents;
}
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index aa15ff69904..67463e583d7 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -285,6 +285,22 @@ MCSectionMachO *MCContext::getMachOSection(StringRef Segment, StringRef Section,
Segment, Section, TypeAndAttributes, Reserved2, Kind, Begin);
}
+void MCContext::renameELFSection(MCSectionELF *Section, StringRef Name) {
+ StringRef GroupName;
+ if (const MCSymbol *Group = Section->getGroup())
+ GroupName = Group->getName();
+
+ unsigned UniqueID = Section->getUniqueID();
+ ELFUniquingMap.erase(
+ ELFSectionKey{Section->getSectionName(), GroupName, UniqueID});
+ auto I = ELFUniquingMap.insert(std::make_pair(
+ ELFSectionKey{Name, GroupName, UniqueID},
+ Section))
+ .first;
+ StringRef CachedName = I->first.SectionName;
+ const_cast<MCSectionELF *>(Section)->setSectionName(CachedName);
+}
+
MCSectionELF *MCContext::createELFRelSection(StringRef Name, unsigned Type,
unsigned Flags, unsigned EntrySize,
const MCSymbolELF *Group,
OpenPOWER on IntegriCloud