[PATCH] D134464: [LLD][COFF] Reduce chance of symbol name collision with delay-load

Alvin Wong via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 22 11:48:02 PDT 2022


alvinhochun created this revision.
alvinhochun added reviewers: rnk, mstorsjo, ajpaverd.
Herald added a project: All.
alvinhochun requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Delay-loaded imports creats a load thunk with a symbol name. Before this
change, the name uses a `__imp_load_` prefix. On the other hand, normal
import uses the `__imp_` prefix for the import address pointer. If an
import symbol named `load_func` is imported normally and another named
`func` is imported using delay-load, this can cause a symbol name
collision.

This patch changes delay-load imports to use `__imp___load_` prefix.
Because it is less likely for normal imports to have a name starting in
`__load_` this should reduce the chance of a name collision.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134464

Files:
  lld/COFF/DLL.cpp


Index: lld/COFF/DLL.cpp
===================================================================
--- lld/COFF/DLL.cpp
+++ lld/COFF/DLL.cpp
@@ -659,10 +659,10 @@
         auto *c = make<HintNameChunk>(extName, 0);
         names.push_back(make<LookupChunk>(c));
         hintNames.push_back(c);
-        // Add a syntentic symbol for this load thunk, using the "__imp_load"
+        // Add a syntentic symbol for this load thunk, using the "__imp___load"
         // prefix, in case this thunk needs to be added to the list of valid
         // call targets for Control Flow Guard.
-        StringRef symName = saver().save("__imp_load_" + extName);
+        StringRef symName = saver().save("__imp___load_" + extName);
         s->loadThunkSym =
             cast<DefinedSynthetic>(ctx.symtab.addSynthetic(symName, t));
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134464.462255.patch
Type: text/x-patch
Size: 824 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220922/382b1bab/attachment.bin>


More information about the llvm-commits mailing list