diff options
| author | Rui Ueyama <ruiu@google.com> | 2018-02-12 22:25:45 +0000 | 
|---|---|---|
| committer | Rui Ueyama <ruiu@google.com> | 2018-02-12 22:25:45 +0000 | 
| commit | 3cd48fb124bb7efe25acbfab5ac7bcfb33fec31d (patch) | |
| tree | 91105299f3edd3e9e15aca02bb1f1c1f20c89519 | |
| parent | f7854b669a3ce7fbc27824185b6ac7de5d17b554 (diff) | |
| download | bcm5719-llvm-3cd48fb124bb7efe25acbfab5ac7bcfb33fec31d.tar.gz bcm5719-llvm-3cd48fb124bb7efe25acbfab5ac7bcfb33fec31d.zip  | |
Remove 'z' in .zdebug when decompressing a section.
When decompressing a compressed debug section, we drop SHF_COMPRESSED
flag but we didn't drop "z" in ".zdebug" section name. This patch does
that for consistency.
This change also fixes the issue that .zdebug_gnu_pubnames are not
dropped when we are creating a .gdb_index section.
llvm-svn: 324949
| -rw-r--r-- | lld/ELF/InputSection.cpp | 11 | ||||
| -rw-r--r-- | lld/ELF/Writer.cpp | 5 | ||||
| -rw-r--r-- | lld/test/ELF/Inputs/gdb-index.s | 8 | ||||
| -rw-r--r-- | lld/test/ELF/gdb-index.s | 54 | 
4 files changed, 47 insertions, 31 deletions
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index c9a66f04865..769cc090ee3 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -181,17 +181,26 @@ void InputSectionBase::maybeDecompress() {    if (DecompressBuf || !Decompressor::isCompressedELFSection(Flags, Name))      return; +  // Decompress a section.    Decompressor Dec = check(Decompressor::create(Name, toStringRef(Data),                                                  Config->IsLE, Config->Is64));    size_t Size = Dec.getDecompressedSize(); -  DecompressBuf.reset(new char[Size]()); +  DecompressBuf.reset(new char[Size + Name.size()]());    if (Error E = Dec.decompress({DecompressBuf.get(), Size}))      fatal(toString(this) +            ": decompress failed: " + llvm::toString(std::move(E)));    Data = makeArrayRef((uint8_t *)DecompressBuf.get(), Size);    Flags &= ~(uint64_t)SHF_COMPRESSED; + +  // A section name may have been altered if compressed. If that's +  // the case, restore the original name. (i.e. ".zdebug_" -> ".debug_") +  if (Name.startswith(".zdebug")) { +    DecompressBuf[Size] = '.'; +    memcpy(&DecompressBuf[Size + 1], Name.data() + 2, Name.size() - 2); +    Name = StringRef(&DecompressBuf[Size], Name.size() - 1); +  }  }  InputSection *InputSectionBase::getLinkOrderDep() const { diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 6edc93d8c58..c0118ee451b 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -88,11 +88,6 @@ private:  } // anonymous namespace  StringRef elf::getOutputSectionName(InputSectionBase *S) { -  // ".zdebug_" is a prefix for ZLIB-compressed sections. -  // Because we decompressed input sections, we want to remove 'z'. -  if (S->Name.startswith(".zdebug_")) -    return Saver.save("." + S->Name.substr(2)); -    if (Config->Relocatable)      return S->Name; diff --git a/lld/test/ELF/Inputs/gdb-index.s b/lld/test/ELF/Inputs/gdb-index.s index 907a66d350b..794995c150f 100644 --- a/lld/test/ELF/Inputs/gdb-index.s +++ b/lld/test/ELF/Inputs/gdb-index.s @@ -1,8 +1,8 @@  .text  .Ltext0: -.globl main2 -.type main2, @function -main2: +.globl aaaaaaaaaaaaaaaa +.type aaaaaaaaaaaaaaaa, @function +aaaaaaaaaaaaaaaa:   nop   nop  .Letext0: @@ -59,7 +59,7 @@ main2:  .long 0x33  .long 0x18  .byte 0x30 -.string "main2" +.string "aaaaaaaaaaaaaaaa"  .long 0  .section .debug_gnu_pubtypes,"",@progbits diff --git a/lld/test/ELF/gdb-index.s b/lld/test/ELF/gdb-index.s index 8fea83d145f..ff8217bbc07 100644 --- a/lld/test/ELF/gdb-index.s +++ b/lld/test/ELF/gdb-index.s @@ -2,8 +2,18 @@  # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o  # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/gdb-index.s -o %t2.o  # RUN: ld.lld --gdb-index %t1.o %t2.o -o %t -# RUN: llvm-dwarfdump -gdb-index %t | FileCheck %s + +# RUN: llvm-objdump -d %t | FileCheck %s --check-prefix=DISASM +# RUN: llvm-dwarfdump -gdb-index %t | FileCheck %s --check-prefix=DWARF +# RUN: llvm-readelf -sections %t | FileCheck %s --check-prefix=SECTION + +# RUN: llvm-mc -compress-debug-sections=zlib-gnu -filetype=obj -triple=x86_64-pc-linux \ +# RUN:   %p/Inputs/gdb-index.s -o %t2.o +# RUN: ld.lld --gdb-index %t1.o %t2.o -o %t +  # RUN: llvm-objdump -d %t | FileCheck %s --check-prefix=DISASM +# RUN: llvm-dwarfdump -gdb-index %t | FileCheck %s --check-prefix=DWARF +# RUN: llvm-readelf -sections %t | FileCheck %s --check-prefix=SECTION  # DISASM:       Disassembly of section .text:  # DISASM:       entrypoint: @@ -11,29 +21,31 @@  # DISASM-CHECK:   201001: cc int3  # DISASM-CHECK:   201002: cc int3  # DISASM-CHECK:   201003: cc int3 -# DISASM:       main2: +# DISASM:       aaaaaaaaaaaaaaaa:  # DISASM-CHECK:   201004: 90 nop  # DISASM-CHECK:   201005: 90 nop -# CHECK:      .gnu_index contents: -# CHECK-NEXT:    Version = 7 -# CHECK:       CU list offset = 0x18, has 2 entries: -# CHECK-NEXT:    0: Offset = 0x0, Length = 0x34 -# CHECK-NEXT:    1: Offset = 0x34, Length = 0x34 -# CHECK:       Address area offset = 0x38, has 2 entries: -# CHECK-NEXT:    Low/High address = [0x201000, 0x201001) (Size: 0x1), CU id = 0 -# CHECK-NEXT:    Low/High address = [0x201004, 0x201006) (Size: 0x2), CU id = 1 -# CHECK:       Symbol table offset = 0x60, size = 1024, filled slots: -# CHECK-NEXT:    754: Name offset = 0x27, CU vector offset = 0x8 -# CHECK-NEXT:	   String name: int, CU vector index: 1 -# CHECK-NEXT:    822: Name offset = 0x1c, CU vector offset = 0x0 -# CHECK-NEXT:	   String name: entrypoint, CU vector index: 0 -# CHECK-NEXT:    956: Name offset = 0x2b, CU vector offset = 0x14 -# CHECK-NEXT:      String name: main2, CU vector index: 2 -# CHECK:       Constant pool offset = 0x2060, has 3 CU vectors: -# CHECK-NEXT:    0(0x0): 0x30000000 -# CHECK-NEXT:    1(0x8): 0x90000000 0x90000001 -# CHECK-NEXT:    2(0x14): 0x30000001 +# DWARF:      .gnu_index contents: +# DWARF-NEXT:    Version = 7 +# DWARF:       CU list offset = 0x18, has 2 entries: +# DWARF-NEXT:    0: Offset = 0x0, Length = 0x34 +# DWARF-NEXT:    1: Offset = 0x34, Length = 0x34 +# DWARF:       Address area offset = 0x38, has 2 entries: +# DWARF-NEXT:    Low/High address = [0x201000, 0x201001) (Size: 0x1), CU id = 0 +# DWARF-NEXT:    Low/High address = [0x201004, 0x201006) (Size: 0x2), CU id = 1 +# DWARF:       Symbol table offset = 0x60, size = 1024, filled slots: +# DWARF-NEXT:    512: Name offset = 0x2b, CU vector offset = 0x14 +# DWARF-NEXT:      String name: aaaaaaaaaaaaaaaa, CU vector index: 2 +# DWARF-NEXT:    754: Name offset = 0x27, CU vector offset = 0x8 +# DWARF-NEXT:      String name: int, CU vector index: 1 +# DWARF-NEXT:    822: Name offset = 0x1c, CU vector offset = 0x0 +# DWARF-NEXT:      String name: entrypoint, CU vector index: 0 +# DWARF:       Constant pool offset = 0x2060, has 3 CU vectors: +# DWARF-NEXT:    0(0x0): 0x30000000 +# DWARF-NEXT:    1(0x8): 0x90000000 0x90000001 +# DWARF-NEXT:    2(0x14): 0x30000001 + +# SECTION-NOT: debug_gnu_pubnames  # RUN: ld.lld --gdb-index --no-gdb-index %t1.o %t2.o -o %t2  # RUN: llvm-readobj -sections %t2 | FileCheck -check-prefix=NOGDB %s  | 

