From c3b1d730d69fbb66e521a3abe1c56053ae4f94e2 Mon Sep 17 00:00:00 2001 From: Martin Storsjo Date: Fri, 14 Jun 2019 21:02:04 +0000 Subject: [PATCH] [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 --- lld/COFF/InputFiles.cpp | 9 +++-- lld/test/COFF/associative-comdat-mingw-i386.s | 37 +++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 lld/test/COFF/associative-comdat-mingw-i386.s diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp index 538a36e9508f..ebf6e4418439 100644 --- a/lld/COFF/InputFiles.cpp +++ b/lld/COFF/InputFiles.cpp @@ -288,6 +288,8 @@ void ObjFile::recordPrevailingSymbolForMingw( if (SC && SC->getOutputCharacteristics() & IMAGE_SCN_MEM_EXECUTE) { StringRef Name; COFFObj->getSymbolName(Sym, Name); + if (getMachineType() == I386) + Name.consume_front("_"); PrevailingSectionMap[Name] = SectionNumber; } } @@ -297,9 +299,10 @@ void ObjFile::maybeAssociateSEHForMingw( const DenseMap &PrevailingSectionMap) { StringRef Name; COFFObj->getSymbolName(Sym, Name); - if (Name.consume_front(".pdata$") || Name.consume_front(".xdata$")) { - // For MinGW, treat .[px]data$ as implicitly associative to - // the symbol . + if (Name.consume_front(".pdata$") || Name.consume_front(".xdata$") || + Name.consume_front(".eh_frame$")) { + // For MinGW, treat .[px]data$ and .eh_frame$ as implicitly + // associative to the symbol . auto ParentSym = PrevailingSectionMap.find(Name); if (ParentSym != PrevailingSectionMap.end()) readAssociativeDefinition(Sym, Def, ParentSym->second); diff --git a/lld/test/COFF/associative-comdat-mingw-i386.s b/lld/test/COFF/associative-comdat-mingw-i386.s new file mode 100644 index 000000000000..3f5e02330d50 --- /dev/null +++ b/lld/test/COFF/associative-comdat-mingw-i386.s @@ -0,0 +1,37 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -triple=i686-windows-gnu %s -filetype=obj -o %t.obj + +# RUN: lld-link -lldmingw -entry:main %t.obj -out:%t.exe +# RUN: llvm-objdump -s %t.exe | FileCheck %s + +# Check that the .eh_frame comdat was included, even if it had no symbols, +# due to associativity with the symbol _foo. + +# CHECK: Contents of section .eh_fram: +# CHECK: 403000 42 + + .text + .def _main; + .scl 2; + .type 32; + .endef + .globl _main + .p2align 4, 0x90 +_main: + call _foo + ret + + .section .eh_frame$foo,"dr" + .linkonce discard + .byte 0x42 + + .def _foo; + .scl 2; + .type 32; + .endef + .section .text$foo,"xr",discard,foo + .globl _foo + .p2align 4 +_foo: + ret