r359513 - Re-land r359250, [COFF] Statically link certain runtime library functions

Reid Kleckner via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 29 16:05:48 PDT 2019


Author: rnk
Date: Mon Apr 29 16:05:47 2019
New Revision: 359513

URL: http://llvm.org/viewvc/llvm-project?rev=359513&view=rev
Log:
Re-land r359250, [COFF] Statically link certain runtime library functions

Reverts the revert of r359251, this time with fixed tests.

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

Added:
    cfe/trunk/test/CodeGenCXX/dllimport-runtime-fns.cpp
Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/test/CodeGenCXX/runtime-dllstorage.cpp
    cfe/trunk/test/CodeGenObjC/gnu-init.m
    cfe/trunk/test/CodeGenObjCXX/msabi-stret.mm

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=359513&r1=359512&r2=359513&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Apr 29 16:05:47 2019
@@ -3000,9 +3000,13 @@ CodeGenModule::CreateRuntimeFunction(llv
     if (F->empty()) {
       F->setCallingConv(getRuntimeCC());
 
-      if (!Local && getTriple().isOSBinFormatCOFF() &&
-          !getCodeGenOpts().LTOVisibilityPublicStd &&
-          !getTriple().isWindowsGNUEnvironment()) {
+      // In Windows Itanium environments, try to mark runtime functions
+      // dllimport. For Mingw and MSVC, don't. We don't really know if the user
+      // will link their standard library statically or dynamically. Marking
+      // functions imported when they are not imported can cause linker errors
+      // and warnings.
+      if (!Local && getTriple().isWindowsItaniumEnvironment() &&
+          !getCodeGenOpts().LTOVisibilityPublicStd) {
         const FunctionDecl *FD = GetRuntimeFunctionDecl(Context, Name);
         if (!FD || FD->hasAttr<DLLImportAttr>()) {
           F->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);

Added: cfe/trunk/test/CodeGenCXX/dllimport-runtime-fns.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllimport-runtime-fns.cpp?rev=359513&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/dllimport-runtime-fns.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/dllimport-runtime-fns.cpp Mon Apr 29 16:05:47 2019
@@ -0,0 +1,63 @@
+// RUN: %clang_cc1 -fms-extensions -fms-compatibility-version=19.20 -triple x86_64-windows-msvc -fexceptions -fcxx-exceptions -emit-llvm -o - %s | FileCheck %s --check-prefix=MSVC
+// RUN: %clang_cc1 -fms-extensions -fms-compatibility-version=19.20 -triple aarch64-windows-msvc -fexceptions -fcxx-exceptions -emit-llvm -o - %s | FileCheck %s --check-prefix=MSVC
+// RUN: %clang_cc1 -triple x86_64-windows-itanium -fexceptions -fcxx-exceptions -emit-llvm -o - %s | FileCheck %s --check-prefix=ITANIUM
+// RUN: %clang_cc1 -triple aarch64-windows-gnu -fexceptions -fcxx-exceptions -emit-llvm -o - %s | FileCheck %s --check-prefix=GNU
+
+void foo1() { throw 1; }
+// _CxxThrowException should not be marked dllimport.
+// MSVC-LABEL: define dso_local void @"?foo1@@YAXXZ"
+// MSVC: call void @_CxxThrowException
+// MSVC: declare dso_local void @_CxxThrowException(i8*, %eh.ThrowInfo*)
+
+// __cxa_throw should be marked dllimport for *-windows-itanium.
+// ITANIUM-LABEL: define dso_local void @_Z4foo1v()
+// ITANIUM: call void @__cxa_throw({{.*}})
+// ITANIUM: declare dllimport void @__cxa_throw({{.*}})
+
+// ... but not for *-windows-gnu.
+// GNU-LABEL: define dso_local void @_Z4foo1v()
+// GNU: call void @__cxa_throw({{.*}})
+// GNU: declare dso_local void @__cxa_throw({{.*}})
+
+
+void bar();
+void foo2() noexcept(true) { bar(); }
+// __std_terminate should not be marked dllimport.
+// MSVC-LABEL: define dso_local void @"?foo2@@YAXXZ"
+// MSVC: call void @__std_terminate()
+// MSVC: declare dso_local void @__std_terminate()
+
+// _ZSt9terminatev and __cxa_begin_catch should be marked dllimport.
+// ITANIUM-LABEL: define linkonce_odr hidden void @__clang_call_terminate(i8*)
+// ITANIUM: call i8* @__cxa_begin_catch({{.*}})
+// ITANIUM: call void @_ZSt9terminatev()
+// ITANIUM: declare dllimport i8* @__cxa_begin_catch(i8*)
+// ITANIUM: declare dllimport void @_ZSt9terminatev()
+
+// .. not for mingw.
+// GNU-LABEL: define linkonce_odr hidden void @__clang_call_terminate(i8*)
+// GNU: call i8* @__cxa_begin_catch({{.*}})
+// GNU: call void @_ZSt9terminatev()
+// GNU: declare dso_local i8* @__cxa_begin_catch(i8*)
+// GNU: declare dso_local void @_ZSt9terminatev()
+
+
+struct A {};
+struct B { virtual void f(); };
+struct C : A, virtual B {};
+struct T {};
+T *foo3() { return dynamic_cast<T *>((C *)0); }
+// __RTDynamicCast should not be marked dllimport.
+// MSVC-LABEL: define dso_local %struct.T* @"?foo3@@YAPEAUT@@XZ"
+// MSVC: call i8* @__RTDynamicCast({{.*}})
+// MSVC: declare dso_local i8* @__RTDynamicCast(i8*, i32, i8*, i8*, i32)
+
+// Again, imported
+// ITANIUM-LABEL: define dso_local %struct.T* @_Z4foo3v()
+// ITANIUM: call i8* @__dynamic_cast({{.*}})
+// ITANIUM: declare dllimport i8* @__dynamic_cast({{.*}})
+
+// Not imported
+// GNU-LABEL: define dso_local %struct.T* @_Z4foo3v()
+// GNU: call i8* @__dynamic_cast({{.*}})
+// GNU: declare dso_local i8* @__dynamic_cast({{.*}})

Modified: cfe/trunk/test/CodeGenCXX/runtime-dllstorage.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/runtime-dllstorage.cpp?rev=359513&r1=359512&r2=359513&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/runtime-dllstorage.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/runtime-dllstorage.cpp Mon Apr 29 16:05:47 2019
@@ -14,7 +14,7 @@
 
 // RUN: %clang_cc1 -triple i686-windows-gnu -std=c++11 -fdeclspec -fms-compatibility -fexceptions -fcxx-exceptions -emit-llvm -o - %s | FileCheck -allow-deprecated-dag-overlap %s -check-prefix CHECK-IA -check-prefix CHECK-STATIC-IA
 // RUN: %clang_cc1 -triple i686-windows-gnu -std=c++11 -fdeclspec -fms-compatibility -fexceptions -fcxx-exceptions -flto-visibility-public-std -emit-llvm -o - %s | FileCheck -allow-deprecated-dag-overlap %s -check-prefix CHECK-IA -check-prefix CHECK-STATIC-IA
-// RUN: %clang_cc1 -triple i686-windows-cygnus -std=c++11 -fdeclspec -fms-compatibility -fexceptions -fcxx-exceptions -emit-llvm -o - %s | FileCheck -allow-deprecated-dag-overlap %s -check-prefix CHECK-IA -check-prefix CHECK-DYNAMIC-IA
+// RUN: %clang_cc1 -triple i686-windows-cygnus -std=c++11 -fdeclspec -fms-compatibility -fexceptions -fcxx-exceptions -emit-llvm -o - %s | FileCheck -allow-deprecated-dag-overlap %s -check-prefix CHECK-IA -check-prefix CHECK-STATIC-IA
 // RUN: %clang_cc1 -triple i686-windows-cygnus -std=c++11 -fdeclspec -fms-compatibility -fexceptions -fcxx-exceptions -flto-visibility-public-std -emit-llvm -o - %s | FileCheck -allow-deprecated-dag-overlap %s -check-prefix CHECK-IA -check-prefix CHECK-STATIC-IA
 
 #if defined(IMPORT_DECLARATIONS)
@@ -108,7 +108,7 @@ void l() {
 // CHECK-MS-DAG: @_Init_thread_epoch = external thread_local global i32
 // CHECK-MS-DAG: declare dso_local i32 @__tlregdtor(void ()*)
 // CHECK-MS-DAG: declare dso_local i32 @atexit(void ()*)
-// CHECK-MS-DYNAMIC-DAG: declare dllimport {{.*}} void @_CxxThrowException
+// CHECK-MS-DYNAMIC-DAG: declare {{.*}} void @_CxxThrowException
 // CHECK-MS-STATIC-DAG: declare {{.*}} void @_CxxThrowException
 // CHECK-MS-DAG: declare dso_local noalias i8* @"??2 at YAPAXI@Z"
 // CHECK-MS-DAG: declare dso_local void @_Init_thread_header(i32*)

Modified: cfe/trunk/test/CodeGenObjC/gnu-init.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/gnu-init.m?rev=359513&r1=359512&r2=359513&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjC/gnu-init.m (original)
+++ cfe/trunk/test/CodeGenObjC/gnu-init.m Mon Apr 29 16:05:47 2019
@@ -100,6 +100,6 @@
 // Check our load function is in a comdat.
 // CHECK-WIN: define linkonce_odr hidden void @.objcv2_load_function() comdat {
 
-// Make sure we have dllimport on the load function
-// CHECK-WIN: declare dllimport void @__objc_load
+// Make sure we do not have dllimport on the load function
+// CHECK-WIN: declare dso_local void @__objc_load
 

Modified: cfe/trunk/test/CodeGenObjCXX/msabi-stret.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/msabi-stret.mm?rev=359513&r1=359512&r2=359513&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjCXX/msabi-stret.mm (original)
+++ cfe/trunk/test/CodeGenObjCXX/msabi-stret.mm Mon Apr 29 16:05:47 2019
@@ -13,6 +13,5 @@ S f() {
   return [I m:S()];
 }
 
-// CHECK: declare dllimport void @objc_msgSend_stret(i8*, i8*, ...)
+// CHECK: declare dso_local void @objc_msgSend_stret(i8*, i8*, ...)
 // CHECK-NOT: declare dllimport void @objc_msgSend(i8*, i8*, ...)
-




More information about the cfe-commits mailing list