gross, and increasingly replaced through other mechanisms.
llvm-svn: 201011
HelpText<"Weakly link in the blocks runtime">;
def fsjlj_exceptions : Flag<["-"], "fsjlj-exceptions">,
HelpText<"Use SjLj style exceptions">;
-def fhidden_weak_vtables : Flag<["-"], "fhidden-weak-vtables">,
- HelpText<"Generate weak vtables and RTTI with hidden visibility">;
def main_file_name : Separate<["-"], "main-file-name">,
HelpText<"Main file name to use for debug info">;
def split_dwarf_file : Separate<["-"], "split-dwarf-file">,
CODEGENOPT(ForbidGuardVariables , 1, 0) ///< Issue errors if C++ guard variables
///< are required.
CODEGENOPT(FunctionSections , 1, 0) ///< Set when -ffunction-sections is enabled.
-CODEGENOPT(HiddenWeakVTables , 1, 0) ///< Emit weak vtables, RTTI, and thunks with
- ///< hidden visibility.
CODEGENOPT(InstrumentFunctions , 1, 0) ///< Set when -finstrument-functions is
///< enabled.
CODEGENOPT(InstrumentForProfiling , 1, 0) ///< Set when -pg is enabled.
OldGV->eraseFromParent();
}
- // 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)) {
- const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
-
- CGM.setTypeVisibility(GV, RD, CodeGenModule::TVK_ForRTTI);
- CGM.setTypeVisibility(TypeName, RD, CodeGenModule::TVK_ForRTTIName);
- } else {
- Visibility TypeInfoVisibility = DefaultVisibility;
- if (CGM.getCodeGenOpts().HiddenWeakVTables &&
- Linkage == llvm::GlobalValue::LinkOnceODRLinkage)
- TypeInfoVisibility = HiddenVisibility;
-
- // The type name should have the same visibility as the type itself.
- Visibility ExplicitVisibility = Ty->getVisibility();
- TypeName->setVisibility(CodeGenModule::
- GetLLVMVisibility(ExplicitVisibility));
-
- TypeInfoVisibility = minVisibility(TypeInfoVisibility, Ty->getVisibility());
- GV->setVisibility(CodeGenModule::GetLLVMVisibility(TypeInfoVisibility));
- }
-
+ // Give the type_info object and name the formal visibility of the
+ // type itself.
+ Visibility formalVisibility = Ty->getVisibility();
+ llvm::GlobalValue::VisibilityTypes llvmVisibility =
+ CodeGenModule::GetLLVMVisibility(formalVisibility);
+ TypeName->setVisibility(llvmVisibility);
+ GV->setVisibility(llvmVisibility);
+
+ // Contra the Itanium ABI, we do not rely or guarantee strict
+ // address-equivalence of type_info objects.
+ //
+ // The main effect of setting this flag is that LLVM will
+ // automatically decrease the visibility of linkonce_odr type_info
+ // objects.
GV->setUnnamedAddr(true);
return llvm::ConstantExpr::getBitCast(GV, CGM.Int8PtrTy);
VTT->setLinkage(Linkage);
// Set the right visibility.
- CGM.setTypeVisibility(VTT, RD, CodeGenModule::TVK_ForVTT);
+ CGM.setGlobalVisibility(VTT, RD);
}
llvm::GlobalVariable *CodeGenVTables::GetAddrOfVTT(const CXXRecordDecl *RD) {
static void setThunkVisibility(CodeGenModule &CGM, const CXXMethodDecl *MD,
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
- // emitted when the function is.
-
- // This follows CodeGenModule::setTypeVisibility; see the comments
- // there for explanation.
-
- if ((Fn->getLinkage() != llvm::GlobalVariable::LinkOnceODRLinkage &&
- Fn->getLinkage() != llvm::GlobalVariable::WeakODRLinkage) ||
- Fn->getVisibility() != llvm::GlobalVariable::DefaultVisibility)
- return;
-
- if (MD->getExplicitVisibility(ValueDecl::VisibilityForValue))
- return;
-
- switch (MD->getTemplateSpecializationKind()) {
- case TSK_ExplicitInstantiationDefinition:
- case TSK_ExplicitInstantiationDeclaration:
- return;
-
- case TSK_Undeclared:
- break;
-
- case TSK_ExplicitSpecialization:
- case TSK_ImplicitInstantiation:
- return;
- break;
- }
-
- // If there's an explicit definition, and that definition is
- // out-of-line, then we can't assume that all users will have a
- // definition to emit.
- const FunctionDecl *Def = 0;
- if (MD->hasBody(Def) && Def->isOutOfLine())
- return;
-
- Fn->setVisibility(llvm::GlobalValue::HiddenVisibility);
}
#ifndef NDEBUG
// Create the variable that will hold the construction vtable.
llvm::GlobalVariable *VTable =
CGM.CreateOrReplaceCXXRuntimeVariable(Name, ArrayType, Linkage);
- CGM.setTypeVisibility(VTable, RD, CodeGenModule::TVK_ForConstructionVTable);
+ CGM.setGlobalVisibility(VTable, RD);
// V-tables are always unnamed_addr.
VTable->setUnnamedAddr(true);
GV->setThreadLocalMode(TLM);
}
-/// Set the symbol visibility of type information (vtable and RTTI)
-/// associated with the given type.
-void CodeGenModule::setTypeVisibility(llvm::GlobalValue *GV,
- const CXXRecordDecl *RD,
- TypeVisibilityKind TVK) const {
- setGlobalVisibility(GV, RD);
-
- if (!CodeGenOpts.HiddenWeakVTables)
- return;
-
- // We never want to drop the visibility for RTTI names.
- if (TVK == TVK_ForRTTIName)
- 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.
-
- // This should be kept roughly in sync with setThunkVisibility
- // in CGVTables.cpp.
-
- // Preconditions.
- if (GV->getLinkage() != llvm::GlobalVariable::LinkOnceODRLinkage ||
- GV->getVisibility() != llvm::GlobalVariable::DefaultVisibility)
- return;
-
- // Don't override an explicit visibility attribute.
- if (RD->getExplicitVisibility(NamedDecl::VisibilityForType))
- return;
-
- switch (RD->getTemplateSpecializationKind()) {
- // We have to disable the optimization if this is an EI definition
- // because there might be EI declarations in other shared objects.
- case TSK_ExplicitInstantiationDefinition:
- case TSK_ExplicitInstantiationDeclaration:
- return;
-
- // Every use of a non-template class's type information has to emit it.
- case TSK_Undeclared:
- break;
-
- // In theory, implicit instantiations can ignore the possibility of
- // an explicit instantiation declaration because there necessarily
- // must be an EI definition somewhere with default visibility. In
- // practice, it's possible to have an explicit instantiation for
- // an arbitrary template class, and linkers aren't necessarily able
- // to deal with mixed-visibility symbols.
- case TSK_ExplicitSpecialization:
- case TSK_ImplicitInstantiation:
- return;
- }
-
- // If there's a key function, there may be translation units
- // that don't have the key function's definition. But ignore
- // this if we're emitting RTTI under -fno-rtti.
- if (!(TVK != TVK_ForRTTI) || LangOpts.RTTI) {
- // FIXME: what should we do if we "lose" the key function during
- // the emission of the file?
- if (Context.getCurrentKeyFunction(RD))
- return;
- }
-
- // Otherwise, drop the visibility to hidden.
- GV->setVisibility(llvm::GlobalValue::HiddenVisibility);
- GV->setUnnamedAddr(true);
-}
-
StringRef CodeGenModule::getMangledName(GlobalDecl GD) {
const NamedDecl *ND = cast<NamedDecl>(GD.getDecl());
/// for the thread-local variable declaration D.
void setTLSMode(llvm::GlobalVariable *GV, const VarDecl &D) const;
- /// TypeVisibilityKind - The kind of global variable that is passed to
- /// setTypeVisibility
- enum TypeVisibilityKind {
- TVK_ForVTT,
- TVK_ForVTable,
- TVK_ForConstructionVTable,
- TVK_ForRTTI,
- TVK_ForRTTIName
- };
-
- /// setTypeVisibility - Set the visibility for the given global
- /// value which holds information about a type.
- void setTypeVisibility(llvm::GlobalValue *GV, const CXXRecordDecl *D,
- TypeVisibilityKind TVK) const;
-
static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V) {
switch (V) {
case DefaultVisibility: return llvm::GlobalValue::DefaultVisibility;
VTable->setLinkage(Linkage);
// Set the right visibility.
- CGM.setTypeVisibility(VTable, RD, CodeGenModule::TVK_ForVTable);
+ CGM.setGlobalVisibility(VTable, RD);
// If this is the magic class __cxxabiv1::__fundamental_type_info,
// we will emit the typeinfo for the fundamental types. This is the
VTable->setInitializer(Init);
VTable->setLinkage(Linkage);
- CGM.setTypeVisibility(VTable, RD, CodeGenModule::TVK_ForVTable);
+ CGM.setGlobalVisibility(VTable, RD);
}
}
GV->setInitializer(Init);
// Set the right visibility.
- CGM.setTypeVisibility(GV, RD, CodeGenModule::TVK_ForVTable);
+ CGM.setGlobalVisibility(GV, RD);
}
llvm::Value *MicrosoftCXXABI::performThisAdjustment(CodeGenFunction &CGF,
Opts.DisableFree = Args.hasArg(OPT_disable_free);
Opts.DisableTailCalls = Args.hasArg(OPT_mdisable_tail_calls);
Opts.FloatABI = Args.getLastArgValue(OPT_mfloat_abi);
- Opts.HiddenWeakVTables = Args.hasArg(OPT_fhidden_weak_vtables);
Opts.LessPreciseFPMAD = Args.hasArg(OPT_cl_mad_enable);
Opts.LimitFloatPrecision = Args.getLastArgValue(OPT_mlimit_float_precision);
Opts.NoInfsFPMath = (Args.hasArg(OPT_menable_no_infinities) ||
-// RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -fhidden-weak-vtables -emit-llvm -o - | FileCheck %s
-// RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -fvisibility hidden -fhidden-weak-vtables -emit-llvm -o - | FileCheck -check-prefix=CHECK-WITH-HIDDEN %s
+// RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -fvisibility hidden -emit-llvm -o - | FileCheck -check-prefix=CHECK-WITH-HIDDEN %s
#include <typeinfo>
// CHECK: _ZTIM1CPS_ = internal unnamed_addr constant
// CHECK: _ZTSM1A1C = internal constant
// CHECK: _ZTS1A = linkonce_odr constant
-// CHECK: _ZTI1A = linkonce_odr hidden unnamed_addr constant
+// CHECK: _ZTI1A = linkonce_odr unnamed_addr constant
// CHECK: _ZTIM1A1C = internal unnamed_addr constant
// CHECK: _ZTSM1AP1C = internal constant
// CHECK: _ZTIM1AP1C = internal unnamed_addr constant
// CHECK: _ZTIFvN12_GLOBAL__N_11DEE = internal unnamed_addr constant
// CHECK: _ZTSPFvvE = linkonce_odr constant
// CHECK: _ZTSFvvE = linkonce_odr constant
-// CHECK: _ZTIFvvE = linkonce_odr hidden unnamed_addr constant
-// CHECK: _ZTIPFvvE = linkonce_odr hidden unnamed_addr constant
+// CHECK: _ZTIFvvE = linkonce_odr unnamed_addr constant
+// CHECK: _ZTIPFvvE = linkonce_odr unnamed_addr constant
// CHECK: _ZTSN12_GLOBAL__N_11EE = internal constant
// CHECK: _ZTIN12_GLOBAL__N_11EE = internal unnamed_addr constant
// CHECK: _ZTSA10_i = linkonce_odr constant
-// CHECK: _ZTIA10_i = linkonce_odr hidden unnamed_addr constant
+// CHECK: _ZTIA10_i = linkonce_odr unnamed_addr constant
// CHECK: _ZTI1TILj0EE = linkonce_odr unnamed_addr constant
// CHECK: _ZTI1TILj1EE = weak_odr unnamed_addr constant
// CHECK: _ZTI1TILj2EE = external constant
// RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -emit-llvm -o %t
-// RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -fhidden-weak-vtables -emit-llvm -o %t.hidden
// RUN: FileCheck --check-prefix=CHECK-TEST1 %s < %t
// RUN: FileCheck --check-prefix=CHECK-TEST2 %s < %t
-// RUN: FileCheck --check-prefix=CHECK-TEST2-HIDDEN %s < %t.hidden
#include <typeinfo>
// CHECK-TEST2: @_ZTSN5Test21AE = linkonce_odr constant
// CHECK-TEST2: @_ZTIN5Test21AE = linkonce_odr unnamed_addr constant
struct A { };
-
- // With -fhidden-weak-vtables, the typeinfo for A is marked hidden, but not its name.
- // CHECK-TEST2-HIDDEN: _ZTSN5Test21AE = linkonce_odr constant
- // CHECK-TEST2-HIDDEN: @_ZTIN5Test21AE = linkonce_odr hidden unnamed_addr constant
void f() {
(void)typeid(A);
}
// RUN: %clang_cc1 %s -triple=x86_64-pc-linux-gnu -munwind-tables -emit-llvm -o - | FileCheck %s
// RUN: %clang_cc1 %s -triple=x86_64-pc-linux-gnu -munwind-tables -emit-llvm -o - -O1 -disable-llvm-optzns | FileCheck %s
-// RUN: %clang_cc1 %s -triple=x86_64-pc-linux-gnu -munwind-tables -fhidden-weak-vtables -emit-llvm -o - | FileCheck -check-prefix=CHECK-HIDDEN %s
namespace Test1 {
struct B { virtual void foo(); };
struct C : A, B { void foo() {} };
- // CHECK-HIDDEN-LABEL: define linkonce_odr void @_ZN6Test101C3fooEv
- // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void @_ZThn8_N6Test101C3fooEv
-
+ // Test later.
void test() {
C c;
}
/**** The following has to go at the end of the file ****/
+// This is from Test10:
+// CHECK-LABEL: define linkonce_odr void @_ZN6Test101C3fooEv
+// CHECK-LABEL: define linkonce_odr void @_ZThn8_N6Test101C3fooEv
+
// This is from Test5:
// CHECK-LABEL: define linkonce_odr void @_ZTv0_n24_N5Test51B1fEv
// CHECK-LABEL: define internal void @_ZThn8_N6Test4B12_GLOBAL__N_11C1fEv(
// 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: %clang_cc1 %s -triple=x86_64-apple-darwin10 -disable-llvm-optzns -O3 -emit-llvm -o %t.opt
// RUN: FileCheck --check-prefix=CHECK %s < %t
-// RUN: FileCheck --check-prefix=CHECK-HIDDEN %s < %t.hidden
// RUN: FileCheck --check-prefix=CHECK-OPT %s < %t.opt
namespace {
// CHECK-DAG: @_ZTS1C = linkonce_odr constant
// CHECK-DAG: @_ZTI1C = linkonce_odr unnamed_addr constant
// CHECK-DAG: @_ZTT1C = linkonce_odr unnamed_addr constant
-// CHECK-HIDDEN-DAG: @_ZTV1C = linkonce_odr hidden unnamed_addr constant
-// CHECK-HIDDEN-DAG: @_ZTS1C = linkonce_odr constant
-// CHECK-HIDDEN-DAG: @_ZTI1C = linkonce_odr hidden unnamed_addr constant
-// CHECK-HIDDEN-DAG: @_ZTT1C = linkonce_odr hidden unnamed_addr constant
// D has a key function that is defined in this translation unit so its vtable is
// defined in the translation unit.
// CHECK-DAG: @_ZTV1EIsE = weak_odr unnamed_addr constant
// CHECK-DAG: @_ZTS1EIsE = weak_odr constant
// CHECK-DAG: @_ZTI1EIsE = weak_odr unnamed_addr constant
-// CHECK-HIDDEN-DAG: @_ZTV1EIsE = weak_odr unnamed_addr constant
-// CHECK-HIDDEN-DAG: @_ZTS1EIsE = weak_odr constant
-// CHECK-HIDDEN-DAG: @_ZTI1EIsE = weak_odr unnamed_addr constant
// F<short> is an explicit template instantiation without a key
// function, so its vtable should have weak_odr linkage
// CHECK-DAG: @_ZTV1FIsE = weak_odr unnamed_addr constant
// CHECK-DAG: @_ZTS1FIsE = weak_odr constant
// CHECK-DAG: @_ZTI1FIsE = weak_odr unnamed_addr constant
-// CHECK-HIDDEN-DAG: @_ZTV1FIsE = weak_odr unnamed_addr constant
-// CHECK-HIDDEN-DAG: @_ZTS1FIsE = weak_odr constant
-// CHECK-HIDDEN-DAG: @_ZTI1FIsE = weak_odr unnamed_addr constant
// E<long> is an implicit template instantiation with a key function
// defined in this translation unit, so its vtable should have