[PATCH] CodeGen: Assign an appropriate comdat to thunks.

Peter Collingbourne peter at pcc.me.uk
Mon Jun 29 20:32:12 PDT 2015


Hi majnemer,

Previously we were not assigning a comdat to thunks in the Microsoft
ABI, which
would have required us to emit these functions outside of a comdat.
(Due to an inconsistency in how we were emitting objects, we
were getting this right most of the time, but only when compiling
without function sections.) This code generator change causes
us to create a comdat for each thunk.

http://reviews.llvm.org/D10829

Files:
  lib/CodeGen/MicrosoftCXXABI.cpp
  test/CodeGenCXX/microsoft-abi-thunks.cpp

Index: lib/CodeGen/MicrosoftCXXABI.cpp
===================================================================
--- lib/CodeGen/MicrosoftCXXABI.cpp
+++ lib/CodeGen/MicrosoftCXXABI.cpp
@@ -308,6 +308,9 @@
       Thunk->setLinkage(llvm::GlobalValue::WeakODRLinkage);
     else
       Thunk->setLinkage(llvm::GlobalValue::LinkOnceODRLinkage);
+
+    if (Linkage != GVA_Internal)
+      Thunk->setComdat(CGM.getModule().getOrInsertComdat(Thunk->getName()));
   }
 
   llvm::Value *performThisAdjustment(CodeGenFunction &CGF, llvm::Value *This,
Index: test/CodeGenCXX/microsoft-abi-thunks.cpp
===================================================================
--- test/CodeGenCXX/microsoft-abi-thunks.cpp
+++ test/CodeGenCXX/microsoft-abi-thunks.cpp
@@ -91,7 +91,7 @@
 
 E::E() {}  // Emits vftable and forces thunk generation.
 
-// CODEGEN-LABEL: define weak_odr x86_thiscallcc %struct.C* @"\01?goo at E@@QAEPAUB@@XZ"
+// CODEGEN-LABEL: define weak_odr x86_thiscallcc %struct.C* @"\01?goo at E@@QAEPAUB@@XZ"{{.*}} comdat
 // CODEGEN:   call x86_thiscallcc %struct.C* @"\01?goo at E@@UAEPAUC@@XZ"
 // CODEGEN:   getelementptr inbounds i8, i8* {{.*}}, i32 4
 // CODEGEN: ret
@@ -124,7 +124,7 @@
 
 I::I() {}  // Emits vftable and forces thunk generation.
 
-// CODEGEN-LABEL: define weak_odr x86_thiscallcc %struct.{{[BF]}}* @"\01?goo at I@@QAEPAUB@@XZ"
+// CODEGEN-LABEL: define weak_odr x86_thiscallcc %struct.{{[BF]}}* @"\01?goo at I@@QAEPAUB@@XZ"{{.*}} comdat
 // CODEGEN: %[[ORIG_RET:.*]] = call x86_thiscallcc %struct.F* @"\01?goo at I@@UAEPAUF@@XZ"
 // CODEGEN: %[[ORIG_RET_i8:.*]] = bitcast %struct.F* %[[ORIG_RET]] to i8*
 // CODEGEN: %[[VBPTR_i8:.*]] = getelementptr inbounds i8, i8* %[[ORIG_RET_i8]], i32 4

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10829.28746.patch
Type: text/x-patch
Size: 1691 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150630/ffec8044/attachment.bin>


More information about the cfe-commits mailing list