[PATCH] D51882: [Sanitizers] [MinGW] Produce undecorated symbols for /export: directives when in MinGW mode

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 10 12:31:16 PDT 2018


mstorsjo created this revision.
mstorsjo added reviewers: rnk, timurrrr.
Herald added subscribers: Sanitizers, kubamracek.

In MinGW mode, the /export: directives in object files are interpreted differently; the symbols are not assumed to be decorated.

Since the GNU linker doesn't support the /alternatename and /include directives, there's no such distinction for them in lld. This assumes that the resulting sanitizer libraries will be linked by lld.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D51882

Files:
  lib/sanitizer_common/sanitizer_win_defs.h


Index: lib/sanitizer_common/sanitizer_win_defs.h
===================================================================
--- lib/sanitizer_common/sanitizer_win_defs.h
+++ lib/sanitizer_common/sanitizer_win_defs.h
@@ -30,6 +30,16 @@
 #define WIN_SYM_PREFIX "_"
 #endif
 
+// For MinGW, the /export: directives contain undecorated symbols, contrary to
+// link/lld-link. The GNU linker doesn't support /alternatename and /include
+// though, thus lld-link in MinGW mode interprets them in the same way as
+// in the default mode.
+#ifdef __MINGW32__
+#define WIN_EXPORT_PREFIX
+#else
+#define WIN_EXPORT_PREFIX WIN_SYM_PREFIX
+#endif
+
 // Intermediate macro to ensure the parameter is expanded before stringified.
 #define STRINGIFY_(A) #A
 #define STRINGIFY(A) STRINGIFY_(A)
@@ -62,8 +72,8 @@
   __pragma(comment(linker, "/include:" WIN_SYM_PREFIX STRINGIFY(Name)))
 
 #define WIN_EXPORT(ExportedName, Name)                                         \
-  __pragma(comment(linker, "/export:" WIN_SYM_PREFIX STRINGIFY(ExportedName)   \
-                                  "=" WIN_SYM_PREFIX STRINGIFY(Name)))
+  __pragma(comment(linker, "/export:" WIN_EXPORT_PREFIX STRINGIFY(ExportedName)   \
+                                  "=" WIN_EXPORT_PREFIX STRINGIFY(Name)))
 
 // We cannot define weak functions on Windows, but we can use WIN_WEAK_ALIAS()
 // which defines an alias to a default implementation, and only works when


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51882.164723.patch
Type: text/x-patch
Size: 1418 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180910/b8caa690/attachment.bin>


More information about the llvm-commits mailing list