From: Zequan Wu Date: Thu, 15 Apr 2021 23:23:33 +0000 (-0700) Subject: [lld-link] Warn on exported deleting dtor X-Git-Tag: llvmorg-14-init~9009 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=aa80955f638f26360a1a137d69f61d5ac4970295;p=platform%2Fupstream%2Fllvm.git [lld-link] Warn on exported deleting dtor MSVC linker has this [[ https://docs.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-warning-lnk4102?view=msvc-160 | warning]], so lld-link should also warn on this. Differential Revision: https://reviews.llvm.org/D100606 --- diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp index 09c456e..422a85c 100644 --- a/lld/COFF/Writer.cpp +++ b/lld/COFF/Writer.cpp @@ -1078,6 +1078,10 @@ void Writer::createExportTable() { edataStart = edataSec->chunks.front(); edataEnd = edataSec->chunks.back(); } + // Warn on exported deleting destructor. + for (auto e : config->exports) + if (e.sym && e.sym->getName().startswith("??_G")) + warn("export of deleting dtor: " + toString(*e.sym)); } void Writer::removeUnusedSections() { diff --git a/lld/test/COFF/export-deleting-dtor.s b/lld/test/COFF/export-deleting-dtor.s new file mode 100644 index 0000000..5d7b39c --- /dev/null +++ b/lld/test/COFF/export-deleting-dtor.s @@ -0,0 +1,26 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -triple=x86_64-windows-msvc -defsym drectve=0 %s -filetype=obj -o %t.obj +# RUN: echo "EXPORTS ??_GFoo@@UEAAPEAXI@Z" > %t.def + +# RUN: lld-link %t.obj -entry:dllmain -dll -export:'??_GFoo@@UEAAPEAXI@Z' -out:%t.1.dll 2>&1 | FileCheck %s + +# RUN: lld-link %t.obj -entry:dllmain -dll -def:%t.def -out:%t.2.dll 2>&1 | FileCheck %s + +# RUN: llvm-mc -filetype=obj -triple=x86_64-windows-msvc -defsym drectve=1 %s -o %t.drectve.obj +# RUN: lld-link %t.drectve.obj -entry:dllmain -dll -out:%t.3.dll 2>&1 | FileCheck %s + +# CHECK: export of deleting dtor:{{.*}}Foo{{.*}} + + .text + .globl dllmain + .globl "??_GFoo@@UEAAPEAXI@Z" +dllmain: + ret +"??_GFoo@@UEAAPEAXI@Z": + ret + +.if drectve==1 + .section .drectve + .ascii "-export:??_GFoo@@UEAAPEAXI@Z" +.endif