Skip to content

Commit c3b1d73

Browse files
committed
[COFF] Handle .eh_frame$symbol as associative comdat for MinGW
This matches how it is done for .xdata and .pdata already. On i386, the symbol name in the section name suffix does not contain the extra underscore prefix. This is one part of a fix for PR42217. Differential Revision: https://reviews.llvm.org/D63350 llvm-svn: 363456
1 parent 9e5fa33 commit c3b1d73

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

lld/COFF/InputFiles.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ void ObjFile::recordPrevailingSymbolForMingw(
288288
if (SC && SC->getOutputCharacteristics() & IMAGE_SCN_MEM_EXECUTE) {
289289
StringRef Name;
290290
COFFObj->getSymbolName(Sym, Name);
291+
if (getMachineType() == I386)
292+
Name.consume_front("_");
291293
PrevailingSectionMap[Name] = SectionNumber;
292294
}
293295
}
@@ -297,9 +299,10 @@ void ObjFile::maybeAssociateSEHForMingw(
297299
const DenseMap<StringRef, uint32_t> &PrevailingSectionMap) {
298300
StringRef Name;
299301
COFFObj->getSymbolName(Sym, Name);
300-
if (Name.consume_front(".pdata$") || Name.consume_front(".xdata$")) {
301-
// For MinGW, treat .[px]data$<func> as implicitly associative to
302-
// the symbol <func>.
302+
if (Name.consume_front(".pdata$") || Name.consume_front(".xdata$") ||
303+
Name.consume_front(".eh_frame$")) {
304+
// For MinGW, treat .[px]data$<func> and .eh_frame$<func> as implicitly
305+
// associative to the symbol <func>.
303306
auto ParentSym = PrevailingSectionMap.find(Name);
304307
if (ParentSym != PrevailingSectionMap.end())
305308
readAssociativeDefinition(Sym, Def, ParentSym->second);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# REQUIRES: x86
2+
3+
# RUN: llvm-mc -triple=i686-windows-gnu %s -filetype=obj -o %t.obj
4+
5+
# RUN: lld-link -lldmingw -entry:main %t.obj -out:%t.exe
6+
# RUN: llvm-objdump -s %t.exe | FileCheck %s
7+
8+
# Check that the .eh_frame comdat was included, even if it had no symbols,
9+
# due to associativity with the symbol _foo.
10+
11+
# CHECK: Contents of section .eh_fram:
12+
# CHECK: 403000 42
13+
14+
.text
15+
.def _main;
16+
.scl 2;
17+
.type 32;
18+
.endef
19+
.globl _main
20+
.p2align 4, 0x90
21+
_main:
22+
call _foo
23+
ret
24+
25+
.section .eh_frame$foo,"dr"
26+
.linkonce discard
27+
.byte 0x42
28+
29+
.def _foo;
30+
.scl 2;
31+
.type 32;
32+
.endef
33+
.section .text$foo,"xr",discard,foo
34+
.globl _foo
35+
.p2align 4
36+
_foo:
37+
ret

0 commit comments

Comments
 (0)