[llvm] r270569 - Recommit r270070 ([llvm-mc] - Teach llvm-mc to generate compressed debug sections in zlib style.)

Richard Smith via llvm-commits llvm-commits at lists.llvm.org
Tue May 24 17:21:18 PDT 2016


This breaks linking on Linux with -Wa,--compress-debug-sections (it causes
errors with GNU ld and crashes Gold). Reverted in r270638. Sorry :( Maybe
this could be brought back behind a flag?

Testcase (using attached x.c):

$ clang -Wa,--compress-debug-sections x.c -c -o x.o -g
$ ld x.o -o x
ld: x.o(.debug_info+0x85): reloc against `.debug_str': error 2
$ gold x.o -o x
gold: warning: x.o: last entry in mergeable string section
'.debug_gdb_scripts' not null terminated
gold: internal error in read_header_prolog, at
../../gold/dwarf_reader.cc:1618
$ ld --version
GNU ld (GNU Binutils for Ubuntu) 2.24
[...]
$ gold --version
GNU gold (GNU Binutils for Ubuntu 2.24) 1.11
[...]

On Tue, May 24, 2016 at 8:19 AM, George Rimar via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: grimar
> Date: Tue May 24 10:19:35 2016
> New Revision: 270569
>
> URL: http://llvm.org/viewvc/llvm-project?rev=270569&view=rev
> Log:
> Recommit r270070 ([llvm-mc] - Teach llvm-mc to generate compressed debug
> sections in zlib style.)
>
> Now, after landing r270560, r270557, r270320 it is a proper time.
>
> Original commit message:
> [llvm-mc] - Teach llvm-mc to generate compressed debug sections in zlib
> style.
>
> Before this patch llvm-mc generated zlib-gnu styled sections.
> That means no SHF_COMPRESSED flag was set, magic 'zlib' signature
> was used in combination with full size field. Sections were renamed to
> "*.z*".
> This patch reimplements the compression style to zlib one as zlib-gnu looks
> to be depricated everywhere.
>
> Differential revision: http://reviews.llvm.org/D20331
>
> Modified:
>     llvm/trunk/include/llvm/MC/MCContext.h
>     llvm/trunk/include/llvm/MC/MCSectionELF.h
>     llvm/trunk/lib/MC/ELFObjectWriter.cpp
>     llvm/trunk/lib/MC/MCContext.cpp
>     llvm/trunk/test/MC/ELF/compression.s
>
> Modified: llvm/trunk/include/llvm/MC/MCContext.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCContext.h?rev=270569&r1=270568&r2=270569&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/MC/MCContext.h (original)
> +++ llvm/trunk/include/llvm/MC/MCContext.h Tue May 24 10:19:35 2016
> @@ -385,8 +385,6 @@ namespace llvm {
>                                        const MCSymbolELF *Group,
>                                        const MCSectionELF *Associated);
>
> -    void renameELFSection(MCSectionELF *Section, StringRef Name);
> -
>      MCSectionELF *createELFGroupSection(const MCSymbolELF *Group);
>
>      MCSectionCOFF *getCOFFSection(StringRef Section, unsigned
> Characteristics,
>
> Modified: llvm/trunk/include/llvm/MC/MCSectionELF.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSectionELF.h?rev=270569&r1=270568&r2=270569&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/MC/MCSectionELF.h (original)
> +++ llvm/trunk/include/llvm/MC/MCSectionELF.h Tue May 24 10:19:35 2016
> @@ -62,8 +62,6 @@ private:
>        Group->setIsSignature();
>    }
>
> -  void setSectionName(StringRef Name) { SectionName = Name; }
> -
>  public:
>    ~MCSectionELF();
>
> @@ -75,6 +73,7 @@ public:
>    unsigned getType() const { return Type; }
>    unsigned getFlags() const { return Flags; }
>    unsigned getEntrySize() const { return EntrySize; }
> +  void setFlags(unsigned F) { Flags = F; }
>    const MCSymbolELF *getGroup() const { return Group; }
>
>    void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
>
> Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=270569&r1=270568&r2=270569&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
> +++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Tue May 24 10:19:35 2016
> @@ -979,26 +979,6 @@ ELFObjectWriter::createRelocationSection
>    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);
> @@ -1029,12 +1009,30 @@ void ELFObjectWriter::writeSectionData(c
>      return;
>    }
>
> -  if (!prependCompressionHeader(UncompressedData.size(),
> CompressedContents)) {
> +  uint64_t HdrSize =
> +    is64Bit() ? sizeof(ELF::Elf32_Chdr) : sizeof(ELF::Elf64_Chdr);
> +  if (UncompressedData.size() <= HdrSize + CompressedContents.size()) {
>      getStream() << UncompressedData;
>      return;
>    }
> -  Asm.getContext().renameELFSection(&Section,
> -                                    (".z" +
> SectionName.drop_front(1)).str());
> +
> +  // 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()));
> +  }
> +
>    getStream() << CompressedContents;
>  }
>
>
> Modified: llvm/trunk/lib/MC/MCContext.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=270569&r1=270568&r2=270569&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/MC/MCContext.cpp (original)
> +++ llvm/trunk/lib/MC/MCContext.cpp Tue May 24 10:19:35 2016
> @@ -285,22 +285,6 @@ MCSectionMachO *MCContext::getMachOSecti
>               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,
>
> Modified: llvm/trunk/test/MC/ELF/compression.s
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/compression.s?rev=270569&r1=270568&r2=270569&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/MC/ELF/compression.s (original)
> +++ llvm/trunk/test/MC/ELF/compression.s Tue May 24 10:19:35 2016
> @@ -3,6 +3,7 @@
>  // RUN: llvm-dwarfdump -debug-dump=str %t | FileCheck --check-prefix=STR
> %s
>  // RUN: llvm-mc -filetype=obj -compress-debug-sections -triple
> i386-pc-linux-gnu < %s \
>  // RUN:     | llvm-readobj -symbols - | FileCheck
> --check-prefix=386-SYMBOLS %s
> +// RUN: llvm-readobj -sections %t | FileCheck --check-prefix=ZLIB %s
>
>  // REQUIRES: zlib
>
> @@ -13,10 +14,14 @@
>
>  // CHECK: Contents of section .debug_info:
>
> -// CHECK: Contents of section .zdebug_str:
> -// Check for the 'ZLIB' file magic at the start of the section only
> -// CHECK-NEXT: ZLIB
> -// CHECK-NOT: ZLIB
> +// Check that debug_line section was not renamed, so it is
> +// zlib-style, not zlib-gnu one. Check that SHF_COMPRESSED was set.
> +// ZLIB:      Section {
> +// ZLIB:        Index:
> +// ZLIB:        Name: .debug_str
> +// ZLIB-NEXT:   Type: SHT_PROGBITS
> +// ZLIB-NEXT:   Flags [
> +// ZLIB-NEXT:     SHF_COMPRESSED
>
>  // FIXME: Handle compressing alignment fragments to support compressing
> debug_frame
>  // CHECK: Contents of section .debug_frame:
> @@ -31,7 +36,7 @@
>  // sections, so make sure we handle symbols inside compressed sections
>  // 386-SYMBOLS: Name: .Linfo_string0
>  // 386-SYMBOLS-NOT: }
> -// 386-SYMBOLS: Section: .zdebug_str
> +// 386-SYMBOLS: Section: .debug_str
>
>         .section        .debug_line,"", at progbits
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160524/904a6ef2/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: x.c
Type: text/x-csrc
Size: 10302 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160524/904a6ef2/attachment-0001.c>


More information about the llvm-commits mailing list