<div dir="ltr">Could you include/provide a link to the spec that describes this format, just for the record?<br><br>Also - could you update libObject to handle this format? For now, I imagine that libObject can't handle this & thus llvm-dwarfdump & other tools won't be able to dump the contents of such a compressed section.</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, May 19, 2016 at 8:08 AM, George Rimar via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: grimar<br>
Date: Thu May 19 10:08:31 2016<br>
New Revision: 270070<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=270070&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=270070&view=rev</a><br>
Log:<br>
[llvm-mc] - Teach llvm-mc to generate compressed debug sections in zlib style.<br>
<br>
Before this patch llvm-mc generated zlib-gnu styled sections.<br>
That means no SHF_COMPRESSED flag was set, magic 'zlib' signature<br>
was used in combination with full size field. Sections were renamed to "*.z*".<br>
This patch reimplements the compression style to zlib one as zlib-gnu looks<br>
to be depricated everywhere.<br>
<br>
Differential revision: <a href="http://reviews.llvm.org/D20331" rel="noreferrer" target="_blank">http://reviews.llvm.org/D20331</a><br>
<br>
Modified:<br>
llvm/trunk/include/llvm/MC/MCContext.h<br>
llvm/trunk/include/llvm/MC/MCSectionELF.h<br>
llvm/trunk/lib/MC/ELFObjectWriter.cpp<br>
llvm/trunk/lib/MC/MCContext.cpp<br>
llvm/trunk/test/MC/ELF/compression.s<br>
<br>
Modified: llvm/trunk/include/llvm/MC/MCContext.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCContext.h?rev=270070&r1=270069&r2=270070&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCContext.h?rev=270070&r1=270069&r2=270070&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/MC/MCContext.h (original)<br>
+++ llvm/trunk/include/llvm/MC/MCContext.h Thu May 19 10:08:31 2016<br>
@@ -385,8 +385,6 @@ namespace llvm {<br>
const MCSymbolELF *Group,<br>
const MCSectionELF *Associated);<br>
<br>
- void renameELFSection(MCSectionELF *Section, StringRef Name);<br>
-<br>
MCSectionELF *createELFGroupSection(const MCSymbolELF *Group);<br>
<br>
MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics,<br>
<br>
Modified: llvm/trunk/include/llvm/MC/MCSectionELF.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSectionELF.h?rev=270070&r1=270069&r2=270070&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSectionELF.h?rev=270070&r1=270069&r2=270070&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/MC/MCSectionELF.h (original)<br>
+++ llvm/trunk/include/llvm/MC/MCSectionELF.h Thu May 19 10:08:31 2016<br>
@@ -62,8 +62,6 @@ private:<br>
Group->setIsSignature();<br>
}<br>
<br>
- void setSectionName(StringRef Name) { SectionName = Name; }<br>
-<br>
public:<br>
~MCSectionELF();<br>
<br>
@@ -75,6 +73,7 @@ public:<br>
unsigned getType() const { return Type; }<br>
unsigned getFlags() const { return Flags; }<br>
unsigned getEntrySize() const { return EntrySize; }<br>
+ void setFlags(unsigned F) { Flags = F; }<br>
const MCSymbolELF *getGroup() const { return Group; }<br>
<br>
void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,<br>
<br>
Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=270070&r1=270069&r2=270070&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=270070&r1=270069&r2=270070&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)<br>
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Thu May 19 10:08:31 2016<br>
@@ -979,26 +979,6 @@ ELFObjectWriter::createRelocationSection<br>
return RelaSection;<br>
}<br>
<br>
-// Include the debug info compression header:<br>
-// "ZLIB" followed by 8 bytes representing the uncompressed size of the section,<br>
-// useful for consumers to preallocate a buffer to decompress into.<br>
-static bool<br>
-prependCompressionHeader(uint64_t Size,<br>
- SmallVectorImpl<char> &CompressedContents) {<br>
- const StringRef Magic = "ZLIB";<br>
- if (Size <= Magic.size() + sizeof(Size) + CompressedContents.size())<br>
- return false;<br>
- if (sys::IsLittleEndianHost)<br>
- sys::swapByteOrder(Size);<br>
- CompressedContents.insert(CompressedContents.begin(),<br>
- Magic.size() + sizeof(Size), 0);<br>
- std::copy(Magic.begin(), Magic.end(), CompressedContents.begin());<br>
- std::copy(reinterpret_cast<char *>(&Size),<br>
- reinterpret_cast<char *>(&Size + 1),<br>
- CompressedContents.begin() + Magic.size());<br>
- return true;<br>
-}<br>
-<br>
void ELFObjectWriter::writeSectionData(const MCAssembler &Asm, MCSection &Sec,<br>
const MCAsmLayout &Layout) {<br>
MCSectionELF &Section = static_cast<MCSectionELF &>(Sec);<br>
@@ -1029,12 +1009,30 @@ void ELFObjectWriter::writeSectionData(c<br>
return;<br>
}<br>
<br>
- if (!prependCompressionHeader(UncompressedData.size(), CompressedContents)) {<br>
+ uint64_t HdrSize =<br>
+ is64Bit() ? sizeof(ELF::Elf32_Chdr) : sizeof(ELF::Elf64_Chdr);<br>
+ if (UncompressedData.size() <= HdrSize + CompressedContents.size()) {<br>
getStream() << UncompressedData;<br>
return;<br>
}<br>
- Asm.getContext().renameELFSection(&Section,<br>
- (".z" + SectionName.drop_front(1)).str());<br>
+<br>
+ // Set the compressed flag. That is zlib style.<br>
+ Section.setFlags(Section.getFlags() | ELF::SHF_COMPRESSED);<br>
+<br>
+ // Platform specific header is followed by compressed data.<br>
+ if (is64Bit()) {<br>
+ // Write Elf64_Chdr header.<br>
+ write(static_cast<ELF::Elf64_Word>(ELF::ELFCOMPRESS_ZLIB));<br>
+ write(static_cast<ELF::Elf64_Word>(0)); // ch_reserved field.<br>
+ write(static_cast<ELF::Elf64_Xword>(UncompressedData.size()));<br>
+ write(static_cast<ELF::Elf64_Xword>(Sec.getAlignment()));<br>
+ } else {<br>
+ // Write Elf32_Chdr header otherwise.<br>
+ write(static_cast<ELF::Elf32_Word>(ELF::ELFCOMPRESS_ZLIB));<br>
+ write(static_cast<ELF::Elf32_Word>(UncompressedData.size()));<br>
+ write(static_cast<ELF::Elf32_Word>(Sec.getAlignment()));<br>
+ }<br>
+<br>
getStream() << CompressedContents;<br>
}<br>
<br>
<br>
Modified: llvm/trunk/lib/MC/MCContext.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=270070&r1=270069&r2=270070&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=270070&r1=270069&r2=270070&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/MC/MCContext.cpp (original)<br>
+++ llvm/trunk/lib/MC/MCContext.cpp Thu May 19 10:08:31 2016<br>
@@ -285,22 +285,6 @@ MCSectionMachO *MCContext::getMachOSecti<br>
Segment, Section, TypeAndAttributes, Reserved2, Kind, Begin);<br>
}<br>
<br>
-void MCContext::renameELFSection(MCSectionELF *Section, StringRef Name) {<br>
- StringRef GroupName;<br>
- if (const MCSymbol *Group = Section->getGroup())<br>
- GroupName = Group->getName();<br>
-<br>
- unsigned UniqueID = Section->getUniqueID();<br>
- ELFUniquingMap.erase(<br>
- ELFSectionKey{Section->getSectionName(), GroupName, UniqueID});<br>
- auto I = ELFUniquingMap.insert(std::make_pair(<br>
- ELFSectionKey{Name, GroupName, UniqueID},<br>
- Section))<br>
- .first;<br>
- StringRef CachedName = I->first.SectionName;<br>
- const_cast<MCSectionELF *>(Section)->setSectionName(CachedName);<br>
-}<br>
-<br>
MCSectionELF *MCContext::createELFRelSection(StringRef Name, unsigned Type,<br>
unsigned Flags, unsigned EntrySize,<br>
const MCSymbolELF *Group,<br>
<br>
Modified: llvm/trunk/test/MC/ELF/compression.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/compression.s?rev=270070&r1=270069&r2=270070&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/compression.s?rev=270070&r1=270069&r2=270070&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/MC/ELF/compression.s (original)<br>
+++ llvm/trunk/test/MC/ELF/compression.s Thu May 19 10:08:31 2016<br>
@@ -3,13 +3,19 @@<br>
// RUN: llvm-dwarfdump -debug-dump=info %t | FileCheck --check-prefix=INFO %s<br>
// RUN: llvm-mc -filetype=obj -compress-debug-sections -triple i386-pc-linux-gnu < %s \<br>
// RUN: | llvm-readobj -symbols - | FileCheck --check-prefix=386-SYMBOLS %s<br>
+// RUN: llvm-readobj -sections %t | FileCheck --check-prefix=ZLIB %s<br>
<br>
// REQUIRES: zlib<br>
<br>
-// CHECK: Contents of section .zdebug_line:<br>
-// Check for the 'ZLIB' file magic at the start of the section only<br>
-// CHECK-NEXT: ZLIB<br>
-// CHECK-NOT: ZLIB<br>
+// Check that debug_line section was not renamed, so it is<br>
+// zlib-style, not zlib-gnu one. Check that SHF_COMPRESSED was set.<br>
+// ZLIB: Section {<br>
+// ZLIB: Index:<br>
+// ZLIB: Name: .debug_line<br>
+// ZLIB-NEXT: Type: SHT_PROGBITS<br>
+// ZLIB-NEXT: Flags [<br>
+// ZLIB-NEXT: SHF_COMPRESSED<br>
+// ZLIB-NEXT: ]<br>
<br>
// Don't compress small sections, such as this simple debug_abbrev example<br>
// CHECK: Contents of section .debug_abbrev:<br>
@@ -30,7 +36,7 @@<br>
// sections, so make sure we handle symbols inside compressed sections<br>
// 386-SYMBOLS: Name: .Linfo_string0<br>
// 386-SYMBOLS-NOT: }<br>
-// 386-SYMBOLS: Section: .zdebug_str<br>
+// 386-SYMBOLS: Section: .debug_str<br>
<br>
.section .debug_line,"",@progbits<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>