[PATCH] D86701: [LLD] [COFF] Error out if creating a DLL with too many exported symbols

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 30 13:19:39 PDT 2020


mstorsjo updated this revision to Diff 288868.
mstorsjo edited the summary of this revision.
mstorsjo added a comment.
Herald added a subscriber: danielkiss.

Added a testcase with a tiny python script that generates def files that export the same symbol a number of times. It generates two 566 KB def files, for testing the case below and above the limit. The successful link case produces a 1 MB DLL and a 8 MB import library.


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

https://reviews.llvm.org/D86701

Files:
  lld/COFF/DriverUtils.cpp
  lld/test/COFF/Inputs/def-many.py
  lld/test/COFF/export-limit.s


Index: lld/test/COFF/export-limit.s
===================================================================
--- /dev/null
+++ lld/test/COFF/export-limit.s
@@ -0,0 +1,13 @@
+# REQUIRES: x86
+# RUN: %python %p/Inputs/def-many.py 65535 > %t-65535.def
+# RUN: %python %p/Inputs/def-many.py 65536 > %t-65536.def
+# RUN: llvm-mc -triple x86_64-win32 %s -filetype=obj -o %t.obj
+# RUN: lld-link -dll -noentry %t.obj -out:%t.dll -def:%t-65535.def
+# RUN: not lld-link -dll -noentry %t.obj -out:%t.dll -def:%t-65536.def 2>&1 | FileCheck %s
+
+# CHECK: error: too many exported symbols
+
+        .text
+        .globl f
+f:
+        ret
Index: lld/test/COFF/Inputs/def-many.py
===================================================================
--- /dev/null
+++ lld/test/COFF/Inputs/def-many.py
@@ -0,0 +1,5 @@
+import sys
+
+print("EXPORTS")
+for i in range(0, int(sys.argv[1])):
+  print("f%d=f" % (i))
Index: lld/COFF/DriverUtils.cpp
===================================================================
--- lld/COFF/DriverUtils.cpp
+++ lld/COFF/DriverUtils.cpp
@@ -32,6 +32,7 @@
 #include "llvm/Support/Program.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/WindowsManifest/WindowsManifestMerger.h"
+#include <limits>
 #include <memory>
 
 using namespace llvm::COFF;
@@ -673,12 +674,15 @@
 
 void assignExportOrdinals() {
   // Assign unique ordinals if default (= 0).
-  uint16_t max = 0;
+  uint32_t max = 0;
   for (Export &e : config->exports)
-    max = std::max(max, e.ordinal);
+    max = std::max(max, (uint32_t)e.ordinal);
   for (Export &e : config->exports)
     if (e.ordinal == 0)
       e.ordinal = ++max;
+  if (max > std::numeric_limits<uint16_t>::max())
+    fatal("too many exported symbols (max " +
+          Twine(std::numeric_limits<uint16_t>::max()) + ")");
 }
 
 // Parses a string in the form of "key=value" and check


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86701.288868.patch
Type: text/x-patch
Size: 1845 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200830/fb822d98/attachment.bin>


More information about the llvm-commits mailing list