diff options
author | Jorge Gorbe Moya <jgorbe@google.com> | 2019-10-14 23:25:25 +0000 |
---|---|---|
committer | Jorge Gorbe Moya <jgorbe@google.com> | 2019-10-14 23:25:25 +0000 |
commit | b052331bd614ff2d06bbb3e5af15e899e3f7e52f (patch) | |
tree | 820eb125616254eeeefc9d6ad5d3c3c174ed78b9 /clang/lib | |
parent | 3be9169caab619c9c87ec29b5530bd2db8382938 (diff) | |
download | bcm5719-llvm-b052331bd614ff2d06bbb3e5af15e899e3f7e52f.tar.gz bcm5719-llvm-b052331bd614ff2d06bbb3e5af15e899e3f7e52f.zip |
Revert "Dead Virtual Function Elimination"
This reverts commit 9f6a873268e1ad9855873d9d8007086c0d01cf4f.
llvm-svn: 374844
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/CodeGen/CGClass.cpp | 18 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGVTables.cpp | 35 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.h | 10 | ||||
-rw-r--r-- | clang/lib/CodeGen/ItaniumCXXABI.cpp | 105 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChains/Clang.cpp | 27 | ||||
-rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 2 |
6 files changed, 45 insertions, 152 deletions
diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp index 7cff6210c29..ab8588303d2 100644 --- a/clang/lib/CodeGen/CGClass.cpp +++ b/clang/lib/CodeGen/CGClass.cpp @@ -2784,16 +2784,11 @@ void CodeGenFunction::EmitVTablePtrCheck(const CXXRecordDecl *RD, bool CodeGenFunction::ShouldEmitVTableTypeCheckedLoad(const CXXRecordDecl *RD) { if (!CGM.getCodeGenOpts().WholeProgramVTables || + !SanOpts.has(SanitizerKind::CFIVCall) || + !CGM.getCodeGenOpts().SanitizeTrap.has(SanitizerKind::CFIVCall) || !CGM.HasHiddenLTOVisibility(RD)) return false; - if (CGM.getCodeGenOpts().VirtualFunctionElimination) - return true; - - if (!SanOpts.has(SanitizerKind::CFIVCall) || - !CGM.getCodeGenOpts().SanitizeTrap.has(SanitizerKind::CFIVCall)) - return false; - std::string TypeName = RD->getQualifiedNameAsString(); return !getContext().getSanitizerBlacklist().isBlacklistedType( SanitizerKind::CFIVCall, TypeName); @@ -2816,13 +2811,8 @@ llvm::Value *CodeGenFunction::EmitVTableTypeCheckedLoad( TypeId}); llvm::Value *CheckResult = Builder.CreateExtractValue(CheckedLoad, 1); - std::string TypeName = RD->getQualifiedNameAsString(); - if (SanOpts.has(SanitizerKind::CFIVCall) && - !getContext().getSanitizerBlacklist().isBlacklistedType( - SanitizerKind::CFIVCall, TypeName)) { - EmitCheck(std::make_pair(CheckResult, SanitizerKind::CFIVCall), - SanitizerHandler::CFICheckFail, {}, {}); - } + EmitCheck(std::make_pair(CheckResult, SanitizerKind::CFIVCall), + SanitizerHandler::CFICheckFail, nullptr, nullptr); return Builder.CreateBitCast( Builder.CreateExtractValue(CheckedLoad, 0), diff --git a/clang/lib/CodeGen/CGVTables.cpp b/clang/lib/CodeGen/CGVTables.cpp index f9f25e7e57a..a74905fd70f 100644 --- a/clang/lib/CodeGen/CGVTables.cpp +++ b/clang/lib/CodeGen/CGVTables.cpp @@ -808,7 +808,7 @@ CodeGenVTables::GenerateConstructionVTable(const CXXRecordDecl *RD, assert(!VTable->isDeclaration() && "Shouldn't set properties on declaration"); CGM.setGVProperties(VTable, RD); - CGM.EmitVTableTypeMetadata(RD, VTable, *VTLayout.get()); + CGM.EmitVTableTypeMetadata(VTable, *VTLayout.get()); return VTable; } @@ -1039,32 +1039,7 @@ bool CodeGenModule::HasHiddenLTOVisibility(const CXXRecordDecl *RD) { return true; } -llvm::GlobalObject::VCallVisibility -CodeGenModule::GetVCallVisibilityLevel(const CXXRecordDecl *RD) { - LinkageInfo LV = RD->getLinkageAndVisibility(); - llvm::GlobalObject::VCallVisibility TypeVis; - if (!isExternallyVisible(LV.getLinkage())) - TypeVis = llvm::GlobalObject::VCallVisibilityTranslationUnit; - else if (HasHiddenLTOVisibility(RD)) - TypeVis = llvm::GlobalObject::VCallVisibilityLinkageUnit; - else - TypeVis = llvm::GlobalObject::VCallVisibilityPublic; - - for (auto B : RD->bases()) - if (B.getType()->getAsCXXRecordDecl()->isDynamicClass()) - TypeVis = std::min(TypeVis, - GetVCallVisibilityLevel(B.getType()->getAsCXXRecordDecl())); - - for (auto B : RD->vbases()) - if (B.getType()->getAsCXXRecordDecl()->isDynamicClass()) - TypeVis = std::min(TypeVis, - GetVCallVisibilityLevel(B.getType()->getAsCXXRecordDecl())); - - return TypeVis; -} - -void CodeGenModule::EmitVTableTypeMetadata(const CXXRecordDecl *RD, - llvm::GlobalVariable *VTable, +void CodeGenModule::EmitVTableTypeMetadata(llvm::GlobalVariable *VTable, const VTableLayout &VTLayout) { if (!getCodeGenOpts().LTOUnit) return; @@ -1124,10 +1099,4 @@ void CodeGenModule::EmitVTableTypeMetadata(const CXXRecordDecl *RD, VTable->addTypeMetadata((PointerWidth * I).getQuantity(), MD); } } - - if (getCodeGenOpts().VirtualFunctionElimination) { - llvm::GlobalObject::VCallVisibility TypeVis = GetVCallVisibilityLevel(RD); - if (TypeVis != llvm::GlobalObject::VCallVisibilityPublic) - VTable->addVCallVisibilityMetadata(TypeVis); - } } diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index 73f81adae35..597b8d712ca 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -1280,16 +1280,8 @@ public: /// optimization. bool HasHiddenLTOVisibility(const CXXRecordDecl *RD); - /// Returns the vcall visibility of the given type. This is the scope in which - /// a virtual function call could be made which ends up being dispatched to a - /// member function of this class. This scope can be wider than the visibility - /// of the class itself when the class has a more-visible dynamic base class. - llvm::GlobalObject::VCallVisibility - GetVCallVisibilityLevel(const CXXRecordDecl *RD); - /// Emit type metadata for the given vtable using the given layout. - void EmitVTableTypeMetadata(const CXXRecordDecl *RD, - llvm::GlobalVariable *VTable, + void EmitVTableTypeMetadata(llvm::GlobalVariable *VTable, const VTableLayout &VTLayout); /// Generate a cross-DSO type identifier for MD. diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp index 8f9b16470b6..2945dec0bd7 100644 --- a/clang/lib/CodeGen/ItaniumCXXABI.cpp +++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -644,6 +644,8 @@ CGCallee ItaniumCXXABI::EmitLoadOfMemberFunctionPointer( VTableOffset = Builder.CreateTrunc(VTableOffset, CGF.Int32Ty); VTableOffset = Builder.CreateZExt(VTableOffset, CGM.PtrDiffTy); } + // Compute the address of the virtual function pointer. + llvm::Value *VFPAddr = Builder.CreateGEP(VTable, VTableOffset); // Check the address of the function pointer if CFI on member function // pointers is enabled. @@ -651,81 +653,44 @@ CGCallee ItaniumCXXABI::EmitLoadOfMemberFunctionPointer( llvm::Constant *CheckTypeDesc; bool ShouldEmitCFICheck = CGF.SanOpts.has(SanitizerKind::CFIMFCall) && CGM.HasHiddenLTOVisibility(RD); - bool ShouldEmitVFEInfo = CGM.getCodeGenOpts().VirtualFunctionElimination && - CGM.HasHiddenLTOVisibility(RD); - llvm::Value *VirtualFn = nullptr; - - { + if (ShouldEmitCFICheck) { CodeGenFunction::SanitizerScope SanScope(&CGF); - llvm::Value *TypeId = nullptr; - llvm::Value *CheckResult = nullptr; - - if (ShouldEmitCFICheck || ShouldEmitVFEInfo) { - // If doing CFI or VFE, we will need the metadata node to check against. - llvm::Metadata *MD = - CGM.CreateMetadataIdentifierForVirtualMemPtrType(QualType(MPT, 0)); - TypeId = llvm::MetadataAsValue::get(CGF.getLLVMContext(), MD); - } - llvm::Value *VFPAddr = Builder.CreateGEP(VTable, VTableOffset); - - if (ShouldEmitVFEInfo) { - // If doing VFE, load from the vtable with a type.checked.load intrinsic - // call. Note that we use the GEP to calculate the address to load from - // and pass 0 as the offset to the intrinsic. This is because every - // vtable slot of the correct type is marked with matching metadata, and - // we know that the load must be from one of these slots. - llvm::Value *CheckedLoad = Builder.CreateCall( - CGM.getIntrinsic(llvm::Intrinsic::type_checked_load), - {VFPAddr, llvm::ConstantInt::get(CGM.Int32Ty, 0), TypeId}); - CheckResult = Builder.CreateExtractValue(CheckedLoad, 1); - VirtualFn = Builder.CreateExtractValue(CheckedLoad, 0); - VirtualFn = Builder.CreateBitCast(VirtualFn, FTy->getPointerTo(), - "memptr.virtualfn"); - } else { - // When not doing VFE, emit a normal load, as it allows more - // optimisations than type.checked.load. - if (ShouldEmitCFICheck) { - CheckResult = Builder.CreateCall( - CGM.getIntrinsic(llvm::Intrinsic::type_test), - {Builder.CreateBitCast(VFPAddr, CGF.Int8PtrTy), TypeId}); - } - VFPAddr = - Builder.CreateBitCast(VFPAddr, FTy->getPointerTo()->getPointerTo()); - VirtualFn = Builder.CreateAlignedLoad(VFPAddr, CGF.getPointerAlign(), - "memptr.virtualfn"); - } - assert(VirtualFn && "Virtual fuction pointer not created!"); - assert((!ShouldEmitCFICheck || !ShouldEmitVFEInfo || CheckResult) && - "Check result required but not created!"); - - if (ShouldEmitCFICheck) { - // If doing CFI, emit the check. - CheckSourceLocation = CGF.EmitCheckSourceLocation(E->getBeginLoc()); - CheckTypeDesc = CGF.EmitCheckTypeDescriptor(QualType(MPT, 0)); - llvm::Constant *StaticData[] = { - llvm::ConstantInt::get(CGF.Int8Ty, CodeGenFunction::CFITCK_VMFCall), - CheckSourceLocation, - CheckTypeDesc, - }; + CheckSourceLocation = CGF.EmitCheckSourceLocation(E->getBeginLoc()); + CheckTypeDesc = CGF.EmitCheckTypeDescriptor(QualType(MPT, 0)); + llvm::Constant *StaticData[] = { + llvm::ConstantInt::get(CGF.Int8Ty, CodeGenFunction::CFITCK_VMFCall), + CheckSourceLocation, + CheckTypeDesc, + }; - if (CGM.getCodeGenOpts().SanitizeTrap.has(SanitizerKind::CFIMFCall)) { - CGF.EmitTrapCheck(CheckResult); - } else { - llvm::Value *AllVtables = llvm::MetadataAsValue::get( - CGM.getLLVMContext(), - llvm::MDString::get(CGM.getLLVMContext(), "all-vtables")); - llvm::Value *ValidVtable = Builder.CreateCall( - CGM.getIntrinsic(llvm::Intrinsic::type_test), {VTable, AllVtables}); - CGF.EmitCheck(std::make_pair(CheckResult, SanitizerKind::CFIMFCall), - SanitizerHandler::CFICheckFail, StaticData, - {VTable, ValidVtable}); - } + llvm::Metadata *MD = + CGM.CreateMetadataIdentifierForVirtualMemPtrType(QualType(MPT, 0)); + llvm::Value *TypeId = llvm::MetadataAsValue::get(CGF.getLLVMContext(), MD); + + llvm::Value *TypeTest = Builder.CreateCall( + CGM.getIntrinsic(llvm::Intrinsic::type_test), {VFPAddr, TypeId}); - FnVirtual = Builder.GetInsertBlock(); + if (CGM.getCodeGenOpts().SanitizeTrap.has(SanitizerKind::CFIMFCall)) { + CGF.EmitTrapCheck(TypeTest); + } else { + llvm::Value *AllVtables = llvm::MetadataAsValue::get( + CGM.getLLVMContext(), + llvm::MDString::get(CGM.getLLVMContext(), "all-vtables")); + llvm::Value *ValidVtable = Builder.CreateCall( + CGM.getIntrinsic(llvm::Intrinsic::type_test), {VTable, AllVtables}); + CGF.EmitCheck(std::make_pair(TypeTest, SanitizerKind::CFIMFCall), + SanitizerHandler::CFICheckFail, StaticData, + {VTable, ValidVtable}); } - } // End of sanitizer scope + FnVirtual = Builder.GetInsertBlock(); + } + + // Load the virtual function to call. + VFPAddr = Builder.CreateBitCast(VFPAddr, FTy->getPointerTo()->getPointerTo()); + llvm::Value *VirtualFn = Builder.CreateAlignedLoad( + VFPAddr, CGF.getPointerAlign(), "memptr.virtualfn"); CGF.EmitBranch(FnEnd); // In the non-virtual path, the function pointer is actually a @@ -1669,7 +1634,7 @@ void ItaniumCXXABI::emitVTableDefinitions(CodeGenVTables &CGVT, EmitFundamentalRTTIDescriptors(RD); if (!VTable->isDeclarationForLinker()) - CGM.EmitVTableTypeMetadata(RD, VTable, VTLayout); + CGM.EmitVTableTypeMetadata(VTable, VTLayout); } bool ItaniumCXXABI::isVirtualOffsetNeededForVTableField( diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index dfb3f336086..1ecc4d216da 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -5366,30 +5366,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back(Args.MakeArgString(TargetInfo.str())); } - bool VirtualFunctionElimination = - Args.hasFlag(options::OPT_fvirtual_function_elimination, - options::OPT_fno_virtual_function_elimination, false); - if (VirtualFunctionElimination) { - // VFE requires full LTO (currently, this might be relaxed to allow ThinLTO - // in the future). - if (D.getLTOMode() != LTOK_Full) - D.Diag(diag::err_drv_argument_only_allowed_with) - << "-fvirtual-function-elimination" - << "-flto=full"; - - CmdArgs.push_back("-fvirtual-function-elimination"); - } - - // VFE requires whole-program-vtables, and enables it by default. - bool WholeProgramVTables = Args.hasFlag( - options::OPT_fwhole_program_vtables, - options::OPT_fno_whole_program_vtables, VirtualFunctionElimination); - if (VirtualFunctionElimination && !WholeProgramVTables) { - D.Diag(diag::err_drv_argument_not_allowed_with) - << "-fno-whole-program-vtables" - << "-fvirtual-function-elimination"; - } - + bool WholeProgramVTables = + Args.hasFlag(options::OPT_fwhole_program_vtables, + options::OPT_fno_whole_program_vtables, false); if (WholeProgramVTables) { if (!D.isUsingLTO()) D.Diag(diag::err_drv_argument_only_allowed_with) diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 9d5987f07f1..59e2301db2b 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -758,8 +758,6 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Opts.CodeViewGHash = Args.hasArg(OPT_gcodeview_ghash); Opts.MacroDebugInfo = Args.hasArg(OPT_debug_info_macro); Opts.WholeProgramVTables = Args.hasArg(OPT_fwhole_program_vtables); - Opts.VirtualFunctionElimination = - Args.hasArg(OPT_fvirtual_function_elimination); Opts.LTOVisibilityPublicStd = Args.hasArg(OPT_flto_visibility_public_std); Opts.SplitDwarfFile = Args.getLastArgValue(OPT_split_dwarf_file); Opts.SplitDwarfOutput = Args.getLastArgValue(OPT_split_dwarf_output); |