From e2692b3bc0327606748b6d291b9009d2c845ced5 Mon Sep 17 00:00:00 2001 From: Dmitry Mikulin Date: Wed, 16 Oct 2019 17:51:40 +0000 Subject: Tag CFI-generated data structures with "#pragma clang section" attributes. Differential Revision: https://reviews.llvm.org/D68808 llvm-svn: 375022 --- clang/lib/CodeGen/CodeGenModule.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 8eb2176ca3a8..a4859e7fbbf4 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(GO)) { if (auto *SA = D->getAttr()) @@ -1721,6 +1718,26 @@ void CodeGenModule::setNonAliasAttributes(GlobalDecl GD, if (!D->getAttr()) F->addFnAttr("implicit-section-name", SA->getName()); + if (auto *SA = D->getAttr()) + F->addFnAttr("bss-section", SA->getName()); + if (auto *SA = D->getAttr()) + F->addFnAttr("data-section", SA->getName()); + if (auto *SA = D->getAttr()) + F->addFnAttr("rodata-section", SA->getName()); + if (auto *SA = D->getAttr()) + 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(GO)) { llvm::AttrBuilder Attrs; if (GetCPUAndFeaturesAttributes(GD, Attrs)) { // We know that GetCPUAndFeaturesAttributes will always have the -- cgit v1.2.3