Skip to content

Commit 60a0ea1

Browse files
author
George Rimar
committed
[ELF] - Make LLD remove gnu-lib compression prefix (".z") after decompression when using -r
This is PR33289. Previously LLD leaved section naming as is and that lead to wrong result, because we decompress sections when using -r, and hence should remove ".z" prefix. Differential revision: https://reviews.llvm.org/D33885 llvm-svn: 304711
1 parent fbe891e commit 60a0ea1

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

lld/ELF/Writer.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ template <class ELFT> class Writer {
9393
} // anonymous namespace
9494

9595
StringRef elf::getOutputSectionName(StringRef Name) {
96+
// ".zdebug_" is a prefix for ZLIB-compressed sections.
97+
// Because we decompressed input sections, we want to remove 'z'.
98+
if (Name.startswith(".zdebug_"))
99+
return Saver.save("." + Name.substr(2));
100+
96101
if (Config->Relocatable)
97102
return Name;
98103

@@ -122,10 +127,6 @@ StringRef elf::getOutputSectionName(StringRef Name) {
122127
if (Name == "COMMON")
123128
return ".bss";
124129

125-
// ".zdebug_" is a prefix for ZLIB-compressed sections.
126-
// Because we decompressed input sections, we want to remove 'z'.
127-
if (Name.startswith(".zdebug_"))
128-
return Saver.save("." + Name.substr(2));
129130
return Name;
130131
}
131132

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# REQUIRES: zlib
2+
3+
# RUN: llvm-mc -compress-debug-sections=zlib-gnu -filetype=obj -triple=x86_64-unknown-linux %s -o %t1
4+
# RUN: llvm-readobj -sections %t1 | FileCheck -check-prefix=GNU %s
5+
# GNU: Name: .zdebug_str
6+
7+
# RUN: ld.lld %t1 -o %t2 -r
8+
# RUN: llvm-readobj -sections -section-data %t2 | FileCheck %s
9+
10+
## Check we decompress section and remove ".z" prefix specific for zlib-gnu compression.
11+
# CHECK: Section {
12+
# CHECK: Index:
13+
# CHECK: Name: .debug_str
14+
# CHECK-NEXT: Type: SHT_PROGBITS
15+
# CHECK-NEXT: Flags [
16+
# CHECK-NEXT: SHF_MERGE
17+
# CHECK-NEXT: SHF_STRINGS
18+
# CHECK-NEXT: ]
19+
# CHECK-NEXT: Address:
20+
# CHECK-NEXT: Offset:
21+
# CHECK-NEXT: Size:
22+
# CHECK-NEXT: Link:
23+
# CHECK-NEXT: Info:
24+
# CHECK-NEXT: AddressAlignment: 1
25+
# CHECK-NEXT: EntrySize: 1
26+
# CHECK-NEXT: SectionData (
27+
# CHECK-NEXT: 0000: {{.*}} |short unsigned i|
28+
# CHECK-NEXT: 0010: {{.*}} |nt.unsigned int.|
29+
# CHECK-NEXT: 0020: {{.*}} |long unsigned in|
30+
# CHECK-NEXT: 0030: {{.*}} |t.char.unsigned |
31+
# CHECK-NEXT: 0040: {{.*}} |char.|
32+
# CHECK-NEXT: )
33+
# CHECK-NEXT: }
34+
35+
.section .debug_str,"MS",@progbits,1
36+
.LASF2:
37+
.string "short unsigned int"
38+
.LASF3:
39+
.string "unsigned int"
40+
.LASF0:
41+
.string "long unsigned int"
42+
.LASF8:
43+
.string "char"
44+
.LASF1:
45+
.string "unsigned char"

0 commit comments

Comments
 (0)