summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
authorJaved Absar <javed.absar@arm.com>2017-06-05 10:11:57 +0000
committerJaved Absar <javed.absar@arm.com>2017-06-05 10:11:57 +0000
commit2a67c9ee39c3a2dd298a9a0aec96a1eff6349344 (patch)
tree4ad76a7874c3308ece86e0e2b76b35f0ff1102df /clang/lib/Sema/SemaDecl.cpp
parentb16d146838b8f4b34e072f34a5f194d9a4df4cc5 (diff)
downloadbcm5719-llvm-2a67c9ee39c3a2dd298a9a0aec96a1eff6349344.tar.gz
bcm5719-llvm-2a67c9ee39c3a2dd298a9a0aec96a1eff6349344.zip
Add support for #pragma clang section
This patch provides a means to specify section-names for global variables, functions and static variables, using #pragma directives. This feature is only defined to work sensibly for ELF targets. One can specify section names as: #pragma clang section bss="myBSS" data="myData" rodata="myRodata" text="myText" One can "unspecify" a section name with empty string e.g. #pragma clang section bss="" data="" text="" rodata="" Reviewers: Roger Ferrer, Jonathan Roelofs, Reid Kleckner Differential Revision: https://reviews.llvm.org/D33412 llvm-svn: 304705
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r--clang/lib/Sema/SemaDecl.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index ef6dfaa2f28..cba220daf77 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -8651,6 +8651,14 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
NewFD->setInvalidDecl();
}
+ // Apply an implicit SectionAttr if '#pragma clang section text' is active
+ if (PragmaClangTextSection.Valid && D.isFunctionDefinition() &&
+ !NewFD->hasAttr<SectionAttr>()) {
+ NewFD->addAttr(PragmaClangTextSectionAttr::CreateImplicit(Context,
+ PragmaClangTextSection.SectionName,
+ PragmaClangTextSection.PragmaLocation));
+ }
+
// Apply an implicit SectionAttr if #pragma code_seg is active.
if (CodeSegStack.CurrentValue && D.isFunctionDefinition() &&
!NewFD->hasAttr<SectionAttr>()) {
@@ -11175,6 +11183,23 @@ void Sema::FinalizeDeclaration(Decl *ThisDecl) {
if (!VD)
return;
+ // Apply an implicit SectionAttr if '#pragma clang section bss|data|rodata' is active
+ if (VD->hasGlobalStorage() && VD->isThisDeclarationADefinition() &&
+ !inTemplateInstantiation() && !VD->hasAttr<SectionAttr>()) {
+ if (PragmaClangBSSSection.Valid)
+ VD->addAttr(PragmaClangBSSSectionAttr::CreateImplicit(Context,
+ PragmaClangBSSSection.SectionName,
+ PragmaClangBSSSection.PragmaLocation));
+ if (PragmaClangDataSection.Valid)
+ VD->addAttr(PragmaClangDataSectionAttr::CreateImplicit(Context,
+ PragmaClangDataSection.SectionName,
+ PragmaClangDataSection.PragmaLocation));
+ if (PragmaClangRodataSection.Valid)
+ VD->addAttr(PragmaClangRodataSectionAttr::CreateImplicit(Context,
+ PragmaClangRodataSection.SectionName,
+ PragmaClangRodataSection.PragmaLocation));
+ }
+
if (auto *DD = dyn_cast<DecompositionDecl>(ThisDecl)) {
for (auto *BD : DD->bindings()) {
FinalizeDeclaration(BD);
OpenPOWER on IntegriCloud