[PATCH] D100606: [lld-link] Warn on exported deleting dtor

Zequan Wu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 19 15:27:59 PDT 2021


zequanwu updated this revision to Diff 338658.
zequanwu added a comment.

- Check `e.sym` for null. If the flag `/export=foo` is provided and `foo` is not in the object file. `e.sym` will be null.
- Remove `$` in exported name to have same name on windows and linux.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100606/new/

https://reviews.llvm.org/D100606

Files:
  lld/COFF/Writer.cpp
  lld/test/COFF/export-deleting-dtor.s


Index: lld/test/COFF/export-deleting-dtor.s
===================================================================
--- /dev/null
+++ 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 at Z" > %t.def
+
+# RUN: lld-link %t.obj -entry:dllmain -dll -export:'??_GFoo@@UEAAPEAXI at 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 at Z"
+dllmain:
+        ret
+"??_GFoo@@UEAAPEAXI at Z":
+        ret
+
+.if drectve==1
+        .section .drectve
+        .ascii "-export:??_GFoo@@UEAAPEAXI at Z"
+.endif
Index: lld/COFF/Writer.cpp
===================================================================
--- lld/COFF/Writer.cpp
+++ lld/COFF/Writer.cpp
@@ -1078,6 +1078,10 @@
     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() {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100606.338658.patch
Type: text/x-patch
Size: 1523 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210419/6c668787/attachment-0001.bin>


More information about the llvm-commits mailing list