diff options
author | Dmitry Mikulin <dmitry.mikulin@sony.com> | 2019-10-16 17:51:40 +0000 |
---|---|---|
committer | Dmitry Mikulin <dmitry.mikulin@sony.com> | 2019-10-16 17:51:40 +0000 |
commit | e2692b3bc0327606748b6d291b9009d2c845ced5 (patch) | |
tree | 1708317b476af3609f0ef2432327ef3db80c3f8b /clang/lib/CodeGen | |
parent | 97ed5625442d66d882c304a72ffe0de9fdad59a1 (diff) | |
download | bcm5719-llvm-e2692b3bc0327606748b6d291b9009d2c845ced5.tar.gz bcm5719-llvm-e2692b3bc0327606748b6d291b9009d2c845ced5.zip |
Tag CFI-generated data structures with "#pragma clang section" attributes.
Differential Revision: https://reviews.llvm.org/D68808
llvm-svn: 375022
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r-- | clang/lib/CodeGen/CGExpr.cpp | 3 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 27 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.h | 5 |
3 files changed, 30 insertions, 5 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 2bd1b0ba7e3..570d1601566 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -2821,6 +2821,7 @@ llvm::Constant *CodeGenFunction::EmitCheckTypeDescriptor(QualType T) { CGM.getModule(), Descriptor->getType(), /*isConstant=*/true, llvm::GlobalVariable::PrivateLinkage, Descriptor); GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global); + CGM.setPragmaSectionAttributes(CurFuncDecl, GV); CGM.getSanitizerMetadata()->disableSanitizerForGlobal(GV); // Remember the descriptor for this type. @@ -2900,6 +2901,7 @@ llvm::Constant *CodeGenFunction::EmitCheckSourceLocation(SourceLocation Loc) { } auto FilenameGV = CGM.GetAddrOfConstantCString(FilenameString, ".src"); + CGM.setPragmaSectionAttributes(CurFuncDecl, cast<llvm::GlobalVariable>(FilenameGV.getPointer())); CGM.getSanitizerMetadata()->disableSanitizerForGlobal( cast<llvm::GlobalVariable>(FilenameGV.getPointer())); Filename = FilenameGV.getPointer(); @@ -3073,6 +3075,7 @@ void CodeGenFunction::EmitCheck( new llvm::GlobalVariable(CGM.getModule(), Info->getType(), false, llvm::GlobalVariable::PrivateLinkage, Info); InfoPtr->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global); + CGM.setPragmaSectionAttributes(CurFuncDecl, InfoPtr); CGM.getSanitizerMetadata()->disableSanitizerForGlobal(InfoPtr); Args.push_back(Builder.CreateBitCast(InfoPtr, Int8PtrTy)); ArgTypes.push_back(Int8PtrTy); diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 8eb2176ca3a..a4859e7fbbf 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -1699,11 +1699,8 @@ bool CodeGenModule::GetCPUAndFeaturesAttributes(GlobalDecl GD, return AddedAttr; } -void CodeGenModule::setNonAliasAttributes(GlobalDecl GD, - llvm::GlobalObject *GO) { - const Decl *D = GD.getDecl(); - SetCommonAttributes(GD, GO); - +void CodeGenModule::setPragmaSectionAttributes(const Decl *D, + llvm::GlobalObject *GO) { if (D) { if (auto *GV = dyn_cast<llvm::GlobalVariable>(GO)) { if (auto *SA = D->getAttr<PragmaClangBSSSectionAttr>()) @@ -1721,6 +1718,26 @@ void CodeGenModule::setNonAliasAttributes(GlobalDecl GD, if (!D->getAttr<SectionAttr>()) F->addFnAttr("implicit-section-name", SA->getName()); + if (auto *SA = D->getAttr<PragmaClangBSSSectionAttr>()) + F->addFnAttr("bss-section", SA->getName()); + if (auto *SA = D->getAttr<PragmaClangDataSectionAttr>()) + F->addFnAttr("data-section", SA->getName()); + if (auto *SA = D->getAttr<PragmaClangRodataSectionAttr>()) + F->addFnAttr("rodata-section", SA->getName()); + if (auto *SA = D->getAttr<PragmaClangRelroSectionAttr>()) + F->addFnAttr("relro-section", SA->getName()); + } + } +} + +void CodeGenModule::setNonAliasAttributes(GlobalDecl GD, + llvm::GlobalObject *GO) { + const Decl *D = GD.getDecl(); + SetCommonAttributes(GD, GO); + setPragmaSectionAttributes(D, GO); + + if (D) { + if (auto *F = dyn_cast<llvm::Function>(GO)) { llvm::AttrBuilder Attrs; if (GetCPUAndFeaturesAttributes(GD, Attrs)) { // We know that GetCPUAndFeaturesAttributes will always have the diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index 597b8d712ca..a6662da5f55 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -1347,6 +1347,11 @@ public: /// \param QT is the clang QualType of the null pointer. llvm::Constant *getNullPointer(llvm::PointerType *T, QualType QT); + /// Set section attributes requested by "#pragma clang section" + /// \param D is the declaration to read semantic attributes from. + /// \param GO is the global object to set section attributes. + void setPragmaSectionAttributes(const Decl *D, llvm::GlobalObject *GO); + private: llvm::Constant *GetOrCreateLLVMFunction( StringRef MangledName, llvm::Type *Ty, GlobalDecl D, bool ForVTable, |