HelpText<"Assert that the compilation takes place in a freestanding environment">;
def fgnu_runtime : Flag<"-fgnu-runtime">,
HelpText<"Generate output compatible with the standard GNU Objective-C runtime">;
+def fhidden_weak_vtables : Flag<"-fhidden-weak-vtables">,
+ HelpText<"Generate weak vtables and RTTI with hidden visibility">;
def std_EQ : Joined<"-std=">,
HelpText<"Language standard to compile for">;
def fmath_errno : Flag<"-fmath-errno">,
/// various IR entities came from. Only useful
/// when running CodeGen as a subroutine.
unsigned FunctionSections : 1; /// Set when -ffunction-sections is enabled
- unsigned EmitWeakTemplatesHidden : 1; /// Emit weak vtables and typeinfo for
+ unsigned HiddenWeakTemplateVTables : 1; /// Emit weak vtables and RTTI for
/// template classes with hidden visibility
+ unsigned HiddenWeakVTables : 1; /// Emit weak vtables, RTTI, and thunks with
+ /// hidden visibility
unsigned InstrumentFunctions : 1; /// Set when -finstrument-functions is enabled
unsigned MergeAllConstants : 1; /// Merge identical constants.
unsigned NoCommon : 1; /// Set when -fno-common or C++ is enabled.
DisableRedZone = 0;
EmitDeclMetadata = 0;
FunctionSections = 0;
- EmitWeakTemplatesHidden = 0;
+ HiddenWeakTemplateVTables = 0;
+ HiddenWeakVTables = 0;
MergeAllConstants = 1;
NoCommon = 0;
NoImplicitFloat = 0;
//
//===----------------------------------------------------------------------===//
-#include "clang/AST/Type.h"
-#include "clang/AST/RecordLayout.h"
#include "CodeGenModule.h"
+#include "clang/AST/RecordLayout.h"
+#include "clang/AST/Type.h"
+#include "clang/Frontend/CodeGenOptions.h"
+
using namespace clang;
using namespace CodeGen;
// GCC only relies on the uniqueness of the type names, not the
// type_infos themselves, so we can emit these as hidden symbols.
+ // But don't do this if we're worried about strict visibility
+ // compatibility.
if (const RecordType *RT = dyn_cast<RecordType>(Ty))
CGM.setTypeVisibility(GV, cast<CXXRecordDecl>(RT->getDecl()),
/*ForRTTI*/ true);
- else if (Linkage == llvm::GlobalValue::WeakODRLinkage)
+ else if (CGM.getCodeGenOpts().HiddenWeakVTables &&
+ Linkage == llvm::GlobalValue::WeakODRLinkage)
GV->setVisibility(llvm::GlobalValue::HiddenVisibility);
return llvm::ConstantExpr::getBitCast(GV, Int8PtrTy);
const ThunkInfo &Thunk, llvm::Function *Fn) {
CGM.setGlobalVisibility(Fn, MD);
+ if (!CGM.getCodeGenOpts().HiddenWeakVTables)
+ return;
+
// If the thunk has weak/linkonce linkage, but the function must be
// emitted in every translation unit that references it, then we can
// emit its thunks with hidden visibility, since its thunks must be
case TSK_ExplicitSpecialization:
case TSK_ImplicitInstantiation:
- if (!CGM.getCodeGenOpts().EmitWeakTemplatesHidden)
+ if (!CGM.getCodeGenOpts().HiddenWeakTemplateVTables)
return;
break;
}
bool IsForRTTI) const {
setGlobalVisibility(GV, RD);
+ if (!CodeGenOpts.HiddenWeakVTables)
+ return;
+
// We want to drop the visibility to hidden for weak type symbols.
// This isn't possible if there might be unresolved references
// elsewhere that rely on this symbol being visible.
// to deal with mixed-visibility symbols.
case TSK_ExplicitSpecialization:
case TSK_ImplicitInstantiation:
- if (!CodeGenOpts.EmitWeakTemplatesHidden)
+ if (!CodeGenOpts.HiddenWeakTemplateVTables)
return;
break;
}
Opts.DebugPass = Args.getLastArgValue(OPT_mdebug_pass);
Opts.DisableFPElim = Args.hasArg(OPT_mdisable_fp_elim);
Opts.FloatABI = Args.getLastArgValue(OPT_mfloat_abi);
+ Opts.HiddenWeakVTables = Args.hasArg(OPT_fhidden_weak_vtables);
Opts.LimitFloatPrecision = Args.getLastArgValue(OPT_mlimit_float_precision);
Opts.NoZeroInitializedInBSS = Args.hasArg(OPT_mno_zero_initialized_in_bss);
Opts.RelaxAll = Args.hasArg(OPT_mrelax_all);
// RUN: %clang_cc1 -fno-rtti -fexceptions %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
-// CHECK: @_ZTIN5test11AE = weak_odr hidden constant
-// CHECK: @_ZTIN5test11BE = weak_odr hidden constant
-// CHECK: @_ZTIN5test11CE = weak_odr hidden constant
-// CHECK: @_ZTIN5test11DE = weak_odr hidden constant
-// CHECK: @_ZTIPN5test11DE = weak_odr hidden constant {{.*}} @_ZTIN5test11DE
+// CHECK: @_ZTIN5test11AE = weak_odr constant
+// CHECK: @_ZTIN5test11BE = weak_odr constant
+// CHECK: @_ZTIN5test11CE = weak_odr constant
+// CHECK: @_ZTIN5test11DE = weak_odr constant
+// CHECK: @_ZTIPN5test11DE = weak_odr constant {{.*}} @_ZTIN5test11DE
// PR6974: this shouldn't crash
namespace test0 {
// CHECK: @_ZTV5testa = constant [3 x i8*] [i8* null
// CHECK: @_ZTV5testc = weak_odr constant [3 x i8*] [i8* null
// CHECK: @_ZTVN12_GLOBAL__N_15testgE = internal constant [3 x i8*] [i8* null
-// CHECK: @_ZTV5teste = weak_odr hidden constant [3 x i8*] [i8* null
-// CHECK: @_ZTV5testb = weak_odr hidden constant [3 x i8*] [i8* null
+// CHECK: @_ZTV5teste = weak_odr constant [3 x i8*] [i8* null
+// CHECK: @_ZTV5testb = weak_odr constant [3 x i8*] [i8* null
-// RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -emit-llvm -o - | sort | FileCheck %s
+// RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -fhidden-weak-vtables -emit-llvm -o - | sort | FileCheck %s
// FIXME: Fails on Win32, dunno why.
// XFAIL: win32
// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -fhidden-weak-vtables -emit-llvm -o - | FileCheck -check-prefix=HIDDEN %s
namespace Test1 {
struct B { virtual void foo(); };
struct C : A, B { void foo() {} };
- // CHECK: define linkonce_odr void @_ZN6Test101C3fooEv
- // CHECK: define linkonce_odr hidden void @_ZThn8_N6Test101C3fooEv
+ // CHECK-HIDDEN: define linkonce_odr void @_ZN6Test101C3fooEv
+ // CHECK-HIDDEN: define linkonce_odr hidden void @_ZThn8_N6Test101C3fooEv
void test() {
C c;
/**** The following has to go at the end of the file ****/
// This is from Test5:
-// CHECK: define linkonce_odr hidden void @_ZTv0_n24_N5Test51B1fEv
+// CHECK: define linkonce_odr void @_ZTv0_n24_N5Test51B1fEv
// CHECK: define internal void @_ZThn8_N12_GLOBAL__N_11C1fEv(
template class A<short>;
-// CHECK: @_ZTV1B = weak_odr hidden constant
+// CHECK: @_ZTV1B = weak_odr constant
// CHECK: @_ZTV1AIlE = weak_odr constant
// CHECK: @_ZTV1AIsE = weak_odr constant
// CHECK: @_ZTV1AIiE = weak_odr constant
// A does not have a key function, so the first constructor we emit should
// cause the vtable to be defined (without assertions.)
-// CHECK: @_ZTVN6PR56971AE = weak_odr hidden constant
+// CHECK: @_ZTVN6PR56971AE = weak_odr constant
A::A() { }
A::A(int) { }
}
// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o %t
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -fhidden-weak-vtables -emit-llvm -o %t.hidden
// RUN: FileCheck --check-prefix=CHECK-1 %s < %t
// RUN: FileCheck --check-prefix=CHECK-2 %s < %t
+// RUN: FileCheck --check-prefix=CHECK-2-HIDDEN %s < %t.hidden
// RUN: FileCheck --check-prefix=CHECK-3 %s < %t
// RUN: FileCheck --check-prefix=CHECK-4 %s < %t
// RUN: FileCheck --check-prefix=CHECK-5 %s < %t
+// RUN: FileCheck --check-prefix=CHECK-5-HIDDEN %s < %t.hidden
// RUN: FileCheck --check-prefix=CHECK-6 %s < %t
+// RUN: FileCheck --check-prefix=CHECK-6-HIDDEN %s < %t.hidden
// RUN: FileCheck --check-prefix=CHECK-7 %s < %t
// RUN: FileCheck --check-prefix=CHECK-8 %s < %t
// RUN: FileCheck --check-prefix=CHECK-9 %s < %t
// C has no key function, so its vtable should have weak_odr linkage
// and hidden visibility (rdar://problem/7523229).
-// CHECK-2: @_ZTV1C = weak_odr hidden constant
+// CHECK-2: @_ZTV1C = weak_odr constant
// CHECK-2: @_ZTS1C = weak_odr constant
-// CHECK-2: @_ZTI1C = weak_odr hidden constant
+// CHECK-2: @_ZTI1C = weak_odr constant
+// CHECK-2-HIDDEN: @_ZTV1C = weak_odr hidden constant
+// CHECK-2-HIDDEN: @_ZTS1C = weak_odr constant
+// CHECK-2-HIDDEN: @_ZTI1C = weak_odr hidden constant
// D has a key function that is defined in this translation unit so its vtable is
// defined in the translation unit.
// CHECK-5: @_ZTV1EIsE = weak_odr constant
// CHECK-5: @_ZTS1EIsE = weak_odr constant
// CHECK-5: @_ZTI1EIsE = weak_odr constant
+// CHECK-5-HIDDEN: @_ZTV1EIsE = weak_odr constant
+// CHECK-5-HIDDEN: @_ZTS1EIsE = weak_odr constant
+// CHECK-5-HIDDEN: @_ZTI1EIsE = weak_odr constant
// F<short> is an explicit template instantiation without a key
// function, so its vtable should have weak_odr linkage
// CHECK-6: @_ZTV1FIsE = weak_odr constant
// CHECK-6: @_ZTS1FIsE = weak_odr constant
// CHECK-6: @_ZTI1FIsE = weak_odr constant
+// CHECK-6-HIDDEN: @_ZTV1FIsE = weak_odr constant
+// CHECK-6-HIDDEN: @_ZTS1FIsE = weak_odr constant
+// CHECK-6-HIDDEN: @_ZTI1FIsE = weak_odr constant
// E<long> is an implicit template instantiation with a key function
// defined in this translation unit, so its vtable should have
namespace std { class type_info; }
-// CHECK: @_ZTI1A = weak_odr hidden constant {{.*}}@_ZTVN10__cxxabiv117__class_type_infoE{{.*}}@_ZTS1A
+// CHECK: @_ZTI1A = weak_odr constant {{.*}}@_ZTVN10__cxxabiv117__class_type_infoE{{.*}}@_ZTS1A
@interface A
@end
-// CHECK: @_ZTI1B = weak_odr hidden constant {{.*}}@_ZTVN10__cxxabiv120__si_class_type_infoE{{.*}}@_ZTS1B{{.*}}@_ZTI1A
+// CHECK: @_ZTI1B = weak_odr constant {{.*}}@_ZTVN10__cxxabiv120__si_class_type_infoE{{.*}}@_ZTS1B{{.*}}@_ZTI1A
@interface B : A
@end
-// CHECK: @_ZTIP1B = weak_odr hidden constant {{.*}}@_ZTVN10__cxxabiv119__pointer_type_infoE{{.*}}@_ZTSP1B{{.*}}), i32 0, {{.*}}@_ZTI1B
-// CHECK: @_ZTI11objc_object = weak_odr hidden constant {{.*}}@_ZTVN10__cxxabiv117__class_type_infoE{{.*}}@_ZTS11objc_object
-// CHECK: @_ZTIP11objc_object = weak_odr hidden constant {{.*}}@_ZTVN10__cxxabiv119__pointer_type_infoE{{.*}}@_ZTSP11objc_object{{.*}}@_ZTI11objc_object
-// CHECK: @_ZTI10objc_class = weak_odr hidden constant {{.*}}@_ZTVN10__cxxabiv117__class_type_infoE{{.*}}@_ZTS10objc_class
-// CHECK: @_ZTIP10objc_class = weak_odr hidden constant {{.*}}@_ZTVN10__cxxabiv119__pointer_type_infoE{{.*}}@_ZTSP10objc_class{{.*}}@_ZTI10objc_class
+// CHECK: @_ZTIP1B = weak_odr constant {{.*}}@_ZTVN10__cxxabiv119__pointer_type_infoE{{.*}}@_ZTSP1B{{.*}}), i32 0, {{.*}}@_ZTI1B
+// CHECK: @_ZTI11objc_object = weak_odr constant {{.*}}@_ZTVN10__cxxabiv117__class_type_infoE{{.*}}@_ZTS11objc_object
+// CHECK: @_ZTIP11objc_object = weak_odr constant {{.*}}@_ZTVN10__cxxabiv119__pointer_type_infoE{{.*}}@_ZTSP11objc_object{{.*}}@_ZTI11objc_object
+// CHECK: @_ZTI10objc_class = weak_odr constant {{.*}}@_ZTVN10__cxxabiv117__class_type_infoE{{.*}}@_ZTS10objc_class
+// CHECK: @_ZTIP10objc_class = weak_odr constant {{.*}}@_ZTVN10__cxxabiv119__pointer_type_infoE{{.*}}@_ZTSP10objc_class{{.*}}@_ZTI10objc_class
@protocol P;
void f() {
// CHECK: @_ZTS1X = weak_odr constant
- // CHECK: @_ZTI1X = weak_odr hidden constant
+ // CHECK: @_ZTI1X = weak_odr constant
(void)typeid(X&);
}