Skip to content

Commit 2401b47

Browse files
committed
[objcopy][coff] Place section name first in strtab
The prioritized string table builder was introduced in 9cc9efc. This patch sets highest priority for the section name to place it at the start of string table to avoid the issue described in 4d2eda2.
1 parent 29dcf90 commit 2401b47

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

llvm/lib/ObjCopy/COFF/COFFWriter.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,11 @@ void COFFWriter::layoutSections() {
120120

121121
Expected<size_t> COFFWriter::finalizeStringTable() {
122122
for (const auto &S : Obj.getSections())
123-
if (S.Name.size() > COFF::NameSize)
124-
StrTabBuilder.add(S.Name);
123+
if (S.Name.size() > COFF::NameSize) {
124+
// Put the section name at the start of strtab to ensure its offset is
125+
// less than Max7DecimalOffset. Otherwise, lldb/gdb will not read it.
126+
StrTabBuilder.add(S.Name, /*Priority=*/UINT8_MAX);
127+
}
125128

126129
for (const auto &S : Obj.getSymbols())
127130
if (S.Name.size() > COFF::NameSize)

llvm/test/tools/llvm-objcopy/COFF/string-table.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
# CHECK: StringTable {
77
# CHECK-NEXT: Length: 26
8-
# CHECK-NEXT: [ 4] symbol_zzz
9-
# CHECK-NEXT: [ f] .debug_str
8+
# CHECK-NEXT: [ 4] .debug_str
9+
# CHECK-NEXT: [ f] symbol_zzz
1010
# CHECK-NEXT: }
1111

1212
--- !COFF

0 commit comments

Comments
 (0)