[objcopy][coff] Place section name first in strtab (#145266)
The prioritized string table builder was introduced in9cc9efc. This patch sets highest priority for the section name to place it at the start of string table to avoid the issue described in4d2eda2.
This commit is contained in:
@@ -120,8 +120,11 @@ void COFFWriter::layoutSections() {
|
|||||||
|
|
||||||
Expected<size_t> COFFWriter::finalizeStringTable() {
|
Expected<size_t> COFFWriter::finalizeStringTable() {
|
||||||
for (const auto &S : Obj.getSections())
|
for (const auto &S : Obj.getSections())
|
||||||
if (S.Name.size() > COFF::NameSize)
|
if (S.Name.size() > COFF::NameSize) {
|
||||||
StrTabBuilder.add(S.Name);
|
// Put the section name at the start of strtab to ensure its offset is
|
||||||
|
// less than Max7DecimalOffset. Otherwise, lldb/gdb will not read it.
|
||||||
|
StrTabBuilder.add(S.Name, /*Priority=*/UINT8_MAX);
|
||||||
|
}
|
||||||
|
|
||||||
for (const auto &S : Obj.getSymbols())
|
for (const auto &S : Obj.getSymbols())
|
||||||
if (S.Name.size() > COFF::NameSize)
|
if (S.Name.size() > COFF::NameSize)
|
||||||
|
|||||||
34
llvm/test/tools/llvm-objcopy/COFF/string-table.test
Normal file
34
llvm/test/tools/llvm-objcopy/COFF/string-table.test
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
## Show that section names appear before symbol names in the COFF strtab.
|
||||||
|
## These names are only added to the strtab if they exceed 8 characters.
|
||||||
|
|
||||||
|
# RUN: yaml2obj %s -o %t
|
||||||
|
# RUN: touch %t.sec
|
||||||
|
# RUN: llvm-objcopy --add-section=.debug_str=%t.sec %t %t1
|
||||||
|
# RUN: llvm-readobj --string-table %t1 | FileCheck %s
|
||||||
|
|
||||||
|
# CHECK: StringTable {
|
||||||
|
# CHECK-NEXT: Length: 37
|
||||||
|
# CHECK-NEXT: [ 4] .debug_str
|
||||||
|
# CHECK-NEXT: [ f] symbol_zzz
|
||||||
|
# CHECK-NEXT: [ 1a] symbol_aaa
|
||||||
|
# CHECK-NEXT: }
|
||||||
|
|
||||||
|
--- !COFF
|
||||||
|
header:
|
||||||
|
Machine: IMAGE_FILE_MACHINE_AMD64
|
||||||
|
sections:
|
||||||
|
- Name: .text
|
||||||
|
Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
|
||||||
|
symbols:
|
||||||
|
- Name: symbol_aaa
|
||||||
|
Value: 0
|
||||||
|
SectionNumber: 1
|
||||||
|
SimpleType: IMAGE_SYM_TYPE_NULL
|
||||||
|
ComplexType: IMAGE_SYM_DTYPE_FUNCTION
|
||||||
|
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
|
||||||
|
- Name: symbol_zzz
|
||||||
|
Value: 0
|
||||||
|
SectionNumber: 1
|
||||||
|
SimpleType: IMAGE_SYM_TYPE_NULL
|
||||||
|
ComplexType: IMAGE_SYM_DTYPE_FUNCTION
|
||||||
|
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
|
||||||
Reference in New Issue
Block a user