<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, May 27, 2016 at 5:27 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: Fri May 27 07:27:32 2016<br>
New Revision: 270987<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=270987&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=270987&view=rev</a><br>
Log:<br>
Recommit 270977 - [llvm-mc] - Teach llvm-mc to generate zlib styled compression sections.<br>
<br>
Fix: updated clang code which was not updated by mistake.<br>
<br>
Original commit message:<br>
[llvm-mc] - Teach llvm-mc to generate zlib styled compression sections.<br>
<br>
This patch is strongly based on previously reverted D20331.<br>
(because of gnuutils < 2.26 does not support compressed debug sections in non zlib-gnu style)<br>
<br>
Difference that this patch supports both zlib and zlib-gnu styles.<br>
<br>
-compress-debug-sections option now supports next values:<br>
<br>
-compress-debug-sections=zlib-gnu<br>
-compress-debug-sections=zlib<br>
-compress-debug-sections=none<br>
Previously specifying -compress-debug-sections enabled zlib-gnu compression,<br>
so anyone can put "-compress-debug-sections=zlib-gnu" to restore the behavior<br>
that was before this patch for case when compression was enabled.<br></blockquote><div><br></div><div>I take it the default is zlib? Should we keep the default as zlib-gnu given the lack of available support currently? (perhaps tweak it on any platforms that are particularly forward - I imagine FreeBSD might have support for this sooner than the rest, for example (if it's moving to LLD and other LLVM tools that have/will probably grow support for zlib-gnu compressed input sections sooner rather than later))</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Differential revision: <a href="http://reviews.llvm.org/D20676" rel="noreferrer" target="_blank">http://reviews.llvm.org/D20676</a><br>
<br>
Modified:<br>
llvm/trunk/include/llvm/MC/MCAsmInfo.h<br>
llvm/trunk/include/llvm/MC/MCSectionELF.h<br>
llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp<br>
llvm/trunk/lib/MC/ELFObjectWriter.cpp<br>
llvm/trunk/lib/MC/MCAsmInfo.cpp<br>
llvm/trunk/test/MC/ELF/compression.s<br>
llvm/trunk/tools/llvm-mc/llvm-mc.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/MC/MCAsmInfo.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAsmInfo.h?rev=270987&r1=270986&r2=270987&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAsmInfo.h?rev=270987&r1=270986&r2=270987&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/MC/MCAsmInfo.h (original)<br>
+++ llvm/trunk/include/llvm/MC/MCAsmInfo.h Fri May 27 07:27:32 2016<br>
@@ -53,6 +53,12 @@ namespace LCOMM {<br>
enum LCOMMType { NoAlignment, ByteAlignment, Log2Alignment };<br>
}<br>
<br>
+enum class DebugCompressionType {<br>
+ DCT_None, // no compression<br>
+ DCT_Zlib, // zlib style complession<br>
+ DCT_ZlibGnu // zlib-gnu style compression<br>
+};<br>
+<br>
/// This class is intended to be used as a base class for asm<br>
/// properties and features specific to the target.<br>
class MCAsmInfo {<br>
@@ -356,8 +362,8 @@ protected:<br>
/// construction (see LLVMTargetMachine::initAsmInfo()).<br>
bool UseIntegratedAssembler;<br>
<br>
- /// Compress DWARF debug sections. Defaults to false.<br>
- bool CompressDebugSections;<br>
+ /// Compress DWARF debug sections. Defaults to no compression.<br>
+ DebugCompressionType CompressDebugSections;<br>
<br>
/// True if the integrated assembler should interpret 'a >> b' constant<br>
/// expressions as logical rather than arithmetic.<br>
@@ -565,9 +571,11 @@ public:<br>
UseIntegratedAssembler = Value;<br>
}<br>
<br>
- bool compressDebugSections() const { return CompressDebugSections; }<br>
+ DebugCompressionType compressDebugSections() const {<br>
+ return CompressDebugSections;<br>
+ }<br>
<br>
- void setCompressDebugSections(bool CompressDebugSections) {<br>
+ void setCompressDebugSections(DebugCompressionType CompressDebugSections) {<br>
this->CompressDebugSections = CompressDebugSections;<br>
}<br>
<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=270987&r1=270986&r2=270987&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSectionELF.h?rev=270987&r1=270986&r2=270987&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/MC/MCSectionELF.h (original)<br>
+++ llvm/trunk/include/llvm/MC/MCSectionELF.h Fri May 27 07:27:32 2016<br>
@@ -75,6 +75,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/CodeGen/LLVMTargetMachine.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp?rev=270987&r1=270986&r2=270987&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp?rev=270987&r1=270986&r2=270987&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp Fri May 27 07:27:32 2016<br>
@@ -71,7 +71,7 @@ void LLVMTargetMachine::initAsmInfo() {<br>
TmpAsmInfo->setUseIntegratedAssembler(false);<br>
<br>
if (Options.CompressDebugSections)<br>
- TmpAsmInfo->setCompressDebugSections(true);<br>
+ TmpAsmInfo->setCompressDebugSections(DebugCompressionType::DCT_ZlibGnu);<br>
<br>
AsmInfo = TmpAsmInfo;<br>
}<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=270987&r1=270986&r2=270987&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=270987&r1=270986&r2=270987&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)<br>
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Fri May 27 07:27:32 2016<br>
@@ -136,6 +136,10 @@ class ELFObjectWriter : public MCObjectW<br>
<br>
void align(unsigned Alignment);<br>
<br>
+ bool maybeWriteCompression(uint64_t Size,<br>
+ SmallVectorImpl<char> &CompressedContents,<br>
+ bool ZLibStyle, unsigned Alignment);<br>
+<br>
public:<br>
ELFObjectWriter(MCELFObjectTargetWriter *MOTW, raw_pwrite_stream &OS,<br>
bool IsLittleEndian)<br>
@@ -979,23 +983,38 @@ 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>
+// Include the debug info compression header.<br>
+bool ELFObjectWriter::maybeWriteCompression(<br>
+ uint64_t Size, SmallVectorImpl<char> &CompressedContents, bool ZLibStyle,<br>
+ unsigned Alignment) {<br>
+ if (ZLibStyle) {<br>
+ uint64_t HdrSize =<br>
+ is64Bit() ? sizeof(ELF::Elf32_Chdr) : sizeof(ELF::Elf64_Chdr);<br>
+ if (Size <= HdrSize + CompressedContents.size())<br>
+ return false;<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>(Size));<br>
+ write(static_cast<ELF::Elf64_Xword>(Alignment));<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>(Size));<br>
+ write(static_cast<ELF::Elf32_Word>(Alignment));<br>
+ }<br>
+ return true;<br>
+ }<br>
+<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>
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>
+ write(ArrayRef<char>(Magic.begin(), Magic.size()));<br>
+ writeBE64(Size);<br>
return true;<br>
}<br>
<br>
@@ -1007,8 +1026,11 @@ void ELFObjectWriter::writeSectionData(c<br>
// Compressing debug_frame requires handling alignment fragments which is<br>
// more work (possibly generalizing MCAssembler.cpp:writeFragment to allow<br>
// for writing to arbitrary buffers) for little benefit.<br>
- if (!Asm.getContext().getAsmInfo()->compressDebugSections() ||<br>
- !SectionName.startswith(".debug_") || SectionName == ".debug_frame") {<br>
+ bool CompressionEnabled =<br>
+ Asm.getContext().getAsmInfo()->compressDebugSections() !=<br>
+ DebugCompressionType::DCT_None;<br>
+ if (!CompressionEnabled || !SectionName.startswith(".debug_") ||<br>
+ SectionName == ".debug_frame") {<br>
Asm.writeSectionData(&Section, Layout);<br>
return;<br>
}<br>
@@ -1029,12 +1051,21 @@ void ELFObjectWriter::writeSectionData(c<br>
return;<br>
}<br>
<br>
- if (!prependCompressionHeader(UncompressedData.size(), CompressedContents)) {<br>
+ bool ZlibStyle = Asm.getContext().getAsmInfo()->compressDebugSections() ==<br>
+ DebugCompressionType::DCT_Zlib;<br>
+ if (!maybeWriteCompression(UncompressedData.size(), CompressedContents,<br>
+ ZlibStyle, Sec.getAlignment())) {<br>
getStream() << UncompressedData;<br>
return;<br>
}<br>
- Asm.getContext().renameELFSection(&Section,<br>
- (".z" + SectionName.drop_front(1)).str());<br>
+<br>
+ if (ZlibStyle)<br>
+ // Set the compressed flag. That is zlib style.<br>
+ Section.setFlags(Section.getFlags() | ELF::SHF_COMPRESSED);<br>
+ else<br>
+ // Add "z" prefix to section name. This is zlib-gnu style.<br>
+ Asm.getContext().renameELFSection(&Section,<br>
+ (".z" + SectionName.drop_front(1)).str());<br>
getStream() << CompressedContents;<br>
}<br>
<br>
<br>
Modified: llvm/trunk/lib/MC/MCAsmInfo.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmInfo.cpp?rev=270987&r1=270986&r2=270987&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmInfo.cpp?rev=270987&r1=270986&r2=270987&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/MC/MCAsmInfo.cpp (original)<br>
+++ llvm/trunk/lib/MC/MCAsmInfo.cpp Fri May 27 07:27:32 2016<br>
@@ -108,7 +108,7 @@ MCAsmInfo::MCAsmInfo() {<br>
// - The target subclasses for AArch64, ARM, and X86 handle these cases<br>
UseIntegratedAssembler = false;<br>
<br>
- CompressDebugSections = false;<br>
+ CompressDebugSections = DebugCompressionType::DCT_None;<br>
}<br>
<br>
MCAsmInfo::~MCAsmInfo() {<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=270987&r1=270986&r2=270987&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/compression.s?rev=270987&r1=270986&r2=270987&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/MC/ELF/compression.s (original)<br>
+++ llvm/trunk/test/MC/ELF/compression.s Fri May 27 07:27:32 2016<br>
@@ -1,27 +1,35 @@<br>
-// RUN: llvm-mc -filetype=obj -compress-debug-sections -triple x86_64-pc-linux-gnu < %s -o %t<br>
-// RUN: llvm-objdump -s %t | FileCheck %s<br>
+// Check zlib-gnu style<br>
+// RUN: llvm-mc -filetype=obj -compress-debug-sections=zlib-gnu -triple x86_64-pc-linux-gnu < %s -o %t<br>
+// RUN: llvm-objdump -s %t | FileCheck --check-prefix=CHECK-GNU-STYLE %s<br>
// RUN: llvm-dwarfdump -debug-dump=str %t | FileCheck --check-prefix=STR %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-mc -filetype=obj -compress-debug-sections=zlib-gnu -triple i386-pc-linux-gnu < %s \<br>
+// RUN: | llvm-readobj -symbols - | FileCheck --check-prefix=386-SYMBOLS-GNU %s<br>
+<br>
+// Check zlib style<br>
+// RUN: llvm-mc -filetype=obj -compress-debug-sections=zlib -triple x86_64-pc-linux-gnu < %s -o %t<br>
+// RUN: llvm-objdump -s %t | FileCheck --check-prefix=CHECK-ZLIB-STYLE %s<br>
+// RUN: llvm-dwarfdump -debug-dump=str %t | FileCheck --check-prefix=STR %s<br>
+// RUN: llvm-mc -filetype=obj -compress-debug-sections=zlib -triple i386-pc-linux-gnu < %s \<br>
+// RUN: | llvm-readobj -symbols - | FileCheck --check-prefix=386-SYMBOLS-ZLIB %s<br>
+// RUN: llvm-readobj -sections %t | FileCheck --check-prefix=ZLIB-STYLE-FLAGS %s<br>
<br>
// REQUIRES: zlib<br>
<br>
// Don't compress small sections, such as this simple debug_abbrev example<br>
-// CHECK: Contents of section .debug_abbrev:<br>
-// CHECK-NOT: ZLIB<br>
-// CHECK-NOT: Contents of<br>
+// CHECK-GNU-STYLE: Contents of section .debug_abbrev:<br>
+// CHECK-GNU-STYLE-NOT: ZLIB<br>
+// CHECK-GNU-STYLE-NOT: Contents of<br>
<br>
-// CHECK: Contents of section .debug_info:<br>
+// CHECK-GNU-STYLE: Contents of section .debug_info:<br>
<br>
-// CHECK: Contents of section .zdebug_str:<br>
+// CHECK-GNU-STYLE: Contents of section .zdebug_str:<br>
// Check for the 'ZLIB' file magic at the start of the section only<br>
-// CHECK-NEXT: ZLIB<br>
-// CHECK-NOT: ZLIB<br>
-<br>
+// CHECK-GNU-STYLE-NEXT: ZLIB<br>
+// CHECK-GNU-STYLE-NOT: ZLIB<br>
// FIXME: Handle compressing alignment fragments to support compressing debug_frame<br>
-// CHECK: Contents of section .debug_frame:<br>
-// CHECK-NOT: ZLIB<br>
-// CHECK: Contents of<br>
+// CHECK-GNU-STYLE: Contents of section .debug_frame:<br>
+// CHECK-GNU-STYLE-NOT: ZLIB<br>
+// CHECK-GNU-STYLE: Contents of<br>
<br>
// Decompress one valid dwarf section just to check that this roundtrips,<br>
// we use .zdebug_str section for that<br>
@@ -29,9 +37,34 @@<br>
<br>
// In x86 32 bit named symbols are used for temporary symbols in merge<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-GNU: Name: .Linfo_string0<br>
+// 386-SYMBOLS-GNU-NOT: }<br>
+// 386-SYMBOLS-GNU: Section: .zdebug_str<br>
+<br>
+// Now check the zlib style output:<br>
+<br>
+// Don't compress small sections, such as this simple debug_abbrev example<br>
+// CHECK-ZLIB-STYLE: Contents of section .debug_abbrev:<br>
+// CHECK-ZLIB-STYLE-NOT: ZLIB<br>
+// CHECK-ZLIB-STYLE-NOT: Contents of<br>
+// CHECK-ZLIB-STYLE: Contents of section .debug_info:<br>
+// FIXME: Handle compressing alignment fragments to support compressing debug_frame<br>
+// CHECK-ZLIB-STYLE: Contents of section .debug_frame:<br>
+// CHECK-ZLIB-STYLE-NOT: ZLIB<br>
+// CHECK-ZLIB-STYLE: Contents of<br>
+<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-STYLE-FLAGS: Section {<br>
+// ZLIB-STYLE-FLAGS: Index:<br>
+// ZLIB-STYLE-FLAGS: Name: .debug_str<br>
+// ZLIB-STYLE-FLAGS-NEXT: Type: SHT_PROGBITS<br>
+// ZLIB-STYLE-FLAGS-NEXT: Flags [<br>
+// ZLIB-STYLE-FLAGS-NEXT: SHF_COMPRESSED<br>
+<br>
+// 386-SYMBOLS-ZLIB: Name: .Linfo_string0<br>
+// 386-SYMBOLS-ZLIB-NOT: }<br>
+// 386-SYMBOLS-ZLIB: Section: .debug_str<br>
<br>
.section .debug_line,"",@progbits<br>
<br>
<br>
Modified: llvm/trunk/tools/llvm-mc/llvm-mc.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/llvm-mc.cpp?rev=270987&r1=270986&r2=270987&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/llvm-mc.cpp?rev=270987&r1=270986&r2=270987&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-mc/llvm-mc.cpp (original)<br>
+++ llvm/trunk/tools/llvm-mc/llvm-mc.cpp Fri May 27 07:27:32 2016<br>
@@ -52,9 +52,18 @@ OutputFilename("o", cl::desc("Output fil<br>
static cl::opt<bool><br>
ShowEncoding("show-encoding", cl::desc("Show instruction encodings"));<br>
<br>
-static cl::opt<bool><br>
-CompressDebugSections("compress-debug-sections",<br>
- cl::desc("Compress DWARF debug sections"));<br>
+static cl::opt<DebugCompressionType><br>
+CompressDebugSections("compress-debug-sections", cl::ValueOptional,<br>
+ cl::init(DebugCompressionType::DCT_None),<br>
+ cl::desc("Choose DWARF debug sections compression:"),<br>
+ cl::values(<br>
+ clEnumValN(DebugCompressionType::DCT_None, "none",<br>
+ "No compression"),<br>
+ clEnumValN(DebugCompressionType::DCT_Zlib, "zlib",<br>
+ "Use zlib compression"),<br>
+ clEnumValN(DebugCompressionType::DCT_ZlibGnu, "zlib-gnu",<br>
+ "Use zlib-gnu compression (depricated)"),<br>
+ clEnumValEnd));<br>
<br>
static cl::opt<bool><br>
ShowInst("show-inst", cl::desc("Show internal instruction representation"));<br>
@@ -407,13 +416,13 @@ int main(int argc, char **argv) {<br>
std::unique_ptr<MCAsmInfo> MAI(TheTarget->createMCAsmInfo(*MRI, TripleName));<br>
assert(MAI && "Unable to create target asm info!");<br>
<br>
- if (CompressDebugSections) {<br>
+ if (CompressDebugSections != DebugCompressionType::DCT_None) {<br>
if (!zlib::isAvailable()) {<br>
errs() << ProgName<br>
<< ": build tools with zlib to enable -compress-debug-sections";<br>
return 1;<br>
}<br>
- MAI->setCompressDebugSections(true);<br>
+ MAI->setCompressDebugSections(CompressDebugSections);<br>
}<br>
<br>
// FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and<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></div>