This is an archive of the discontinued LLVM Phabricator instance.

[llvm-mc] - Teach llvm-mc to generate zlib styled compression sections.
ClosedPublic

Authored by grimar on May 26 2016, 5:35 AM.

Details

Summary

This patch is strongly based on previously reverted D20331.
(because of gnuutils < 2.26 does not support compressed debug sections in non zlib-gnu style)

Difference that this patch supports both zlib and zlib-gnu styles.

-compress-debug-sections option now supports next values:

  1. -compress-debug-sections=zlib-gnu
  2. -compress-debug-sections=zlib
  3. -compress-debug-sections=none

Previously specifying -compress-debug-sections enabled zlib-gnu compression,
so anyone can put "-compress-debug-sections=zlib-gnu" to restore the behavior
that was before this patch for case when compression was enabled.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar updated this revision to Diff 58593.May 26 2016, 5:35 AM
grimar retitled this revision from to [llvm-mc] - Teach llvm-mc to work generate zlib styled compression sections..
grimar updated this object.
grimar added reviewers: rafael, davide.
grimar added subscribers: llvm-commits, grimar.
grimar added inline comments.May 26 2016, 5:40 AM
tools/llvm-mc/llvm-mc.cpp
60 ↗(On Diff #58593)

At first I tried:

static cl::opt<DebugCompressionType>
CompressDebugSections("compress-debug-sections", cl::ValueOptional,
  cl::init(DebugCompressionType::DCT_None),
  cl::desc("Choose DWARF debug sections compression:"),
  cl::values(
    clEnumValN(DebugCompressionType::DCT_None, "none",
      "No compression"),
    clEnumValN(DebugCompressionType::DCT_Zlib, "zlib",
      "Use zlib compression"),
    clEnumValN(DebugCompressionType::DCT_Zlib, "zlib-gabi",
      "The same as zlib"),
    clEnumValN(DebugCompressionType::DCT_ZlibGnu, "zlib-gnu",
      "Use zlib-gnu compression (depricated)"),
    clEnumValEnd));

But this does not allow just to write "-compress-debug-sections", without
specifying the value for some reason. Approach that uses std::string works well.

grimar retitled this revision from [llvm-mc] - Teach llvm-mc to work generate zlib styled compression sections. to [llvm-mc] - Teach llvm-mc to generate zlib styled compression sections..May 26 2016, 5:41 AM
rafael added inline comments.May 26 2016, 5:44 AM
include/llvm/MC/MCAsmInfo.h
57 ↗(On Diff #58593)

You shouldn't need the Unknown bit. See the comment about the option in llvm-mc.

lib/CodeGen/LLVMTargetMachine.cpp
74 ↗(On Diff #58593)

I think in the first patch you will have to default to zlib-gnu. The reason is that right now there would be no way for someone using clang to set which one to use.

Once this patch is in with zlib-gnu as the default, we can teach TargetMachine and clang about the two types and change the default.

tools/llvm-mc/llvm-mc.cpp
412 ↗(On Diff #58593)

llvm-mc doesn't need to be command line compatible with as, so please simplify this.
The option can be a cl::opt over an enum with just 3 values: none, zlib, zlib-gnu.

See FileType for a similar option.

grimar added inline comments.May 26 2016, 5:53 AM
lib/CodeGen/LLVMTargetMachine.cpp
74 ↗(On Diff #58593)

Ok. I started with it, but switched to the zlib here at last second. Just because previous patch has compression on/off only and had zlib as default.
Will switch back.

tools/llvm-mc/llvm-mc.cpp
412 ↗(On Diff #58593)

Yep, that what I did at first (see my comment above), but I thought command line compatibility is important, so had to do that.
I am happy to simplify this to enum parse way.

grimar updated this revision to Diff 58602.May 26 2016, 6:46 AM
grimar marked an inline comment as done.
  • Addressed review comments.
rafael added inline comments.May 26 2016, 8:07 AM
lib/MC/ELFObjectWriter.cpp
987 ↗(On Diff #58602)

This function does different things depending on the format

  • for zlib it writes the header
  • for gnu it prepends the header to CompressedContents

I would be cleaner to rename this to maybeWriteCompression header and have it write the header in both cases.

grimar updated this revision to Diff 58624.May 26 2016, 8:59 AM
  • Addressed review comments

Oops, let me update this again.

grimar updated this revision to Diff 58625.May 26 2016, 9:09 AM
  • Now it do what I wanted to write.
grimar updated this revision to Diff 58629.May 26 2016, 9:16 AM
  • Removed unrelated change.
rafael accepted this revision.May 26 2016, 7:24 PM
rafael edited edge metadata.

LGTM. Thanks!

This revision is now accepted and ready to land.May 26 2016, 7:25 PM
grimar updated this object.May 27 2016, 3:03 AM
grimar edited edge metadata.
This revision was automatically updated to reflect the committed changes.