[PATCH] D40025: [LLD] [COFF] Always truncate the .eh_frame section name
Martin Storsjö via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 14 06:21:00 PST 2017
mstorsjo created this revision.
When writing a long section name, the actual section name gets written into the string table, which isn't loaded/mapped at runtime. This means that libunwind can't find the section by iterating over sections but would have to resort to static registration of .eh_frame sections.
Therefore, prefer truncation over using a long section name for .eh_frame when targeting MinGW.
This relates to the issue discussed in https://reviews.llvm.org/D39918.
https://reviews.llvm.org/D40025
Files:
COFF/Writer.cpp
test/COFF/long-section-name.test
Index: test/COFF/long-section-name.test
===================================================================
--- test/COFF/long-section-name.test
+++ test/COFF/long-section-name.test
@@ -2,9 +2,17 @@
# RUN: lld-link /debug /out:%t.exe /entry:main %t.obj
# RUN: llvm-readobj -sections %t.exe | FileCheck %s
+# RUN: lld-link /lldmingw /debug /out:%t.exe /entry:main %t.obj
+# RUN: llvm-readobj -sections %t.exe | FileCheck -check-prefix=MINGW %s
+
# CHECK: Name: .data_long_section_name
+# CHECK: Name: .eh_frame
# CHECK: Name: .text_long_section_name
+# MINGW: Name: .data_long_section_name
+# MINGW: Name: .eh_fram (
+# MINGW: Name: .text_long_section_name
+
--- !COFF
header:
Machine: IMAGE_FILE_MACHINE_AMD64
@@ -18,6 +26,10 @@
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
Alignment: 4
SectionData: "00"
+ - Name: .eh_frame
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
+ Alignment: 4
+ SectionData: "00"
symbols:
- Name: "@comp.id"
Value: 10394907
@@ -49,6 +61,18 @@
NumberOfLinenumbers: 0
CheckSum: 0
Number: 0
+ - Name: .eh_frame
+ Value: 0
+ SectionNumber: 3
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 0
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
- Name: main
Value: 0
SectionNumber: 1
Index: COFF/Writer.cpp
===================================================================
--- COFF/Writer.cpp
+++ COFF/Writer.cpp
@@ -210,7 +210,8 @@
// If name is too long, write offset into the string table as a name.
sprintf(Hdr->Name, "/%d", StringTableOff);
} else {
- assert(!Config->Debug || Name.size() <= COFF::NameSize);
+ assert((!Config->Debug || (Name == ".eh_frame" && Config->MinGW)) ||
+ Name.size() <= COFF::NameSize);
strncpy(Hdr->Name, Name.data(),
std::min(Name.size(), (size_t)COFF::NameSize));
}
@@ -540,6 +541,8 @@
StringRef Name = Sec->getName();
if (Name.size() <= COFF::NameSize)
continue;
+ if (Name == ".eh_frame" && Config->MinGW)
+ continue;
Sec->setStringTableOff(addEntryToStringTable(Name));
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40025.122832.patch
Type: text/x-patch
Size: 2515 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171114/0477d695/attachment.bin>
More information about the llvm-commits
mailing list