[lld] 0ce4f57 - [LLD][COFF] Reduce chance of symbol name collision with delay-load

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 3 00:59:23 PDT 2022


Author: Alvin Wong
Date: 2022-10-03T10:58:45+03:00
New Revision: 0ce4f57052c393b05d9896bb996de2b76855a21b

URL: https://github.com/llvm/llvm-project/commit/0ce4f57052c393b05d9896bb996de2b76855a21b
DIFF: https://github.com/llvm/llvm-project/commit/0ce4f57052c393b05d9896bb996de2b76855a21b.diff

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

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.

Reviewed By: mstorsjo

Differential Revision: https://reviews.llvm.org/D134464

Added: 
    

Modified: 
    lld/COFF/DLL.cpp

Removed: 
    


################################################################################
diff  --git a/lld/COFF/DLL.cpp b/lld/COFF/DLL.cpp
index 17b20fecfed2..58c3eff4a72c 100644
--- a/lld/COFF/DLL.cpp
+++ b/lld/COFF/DLL.cpp
@@ -659,10 +659,10 @@ void DelayLoadContents::create(COFFLinkerContext &ctx, Defined *h) {
         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));
       }


        


More information about the llvm-commits mailing list