diff options
author | Javed Absar <javed.absar@arm.com> | 2017-06-05 10:11:57 +0000 |
---|---|---|
committer | Javed Absar <javed.absar@arm.com> | 2017-06-05 10:11:57 +0000 |
commit | 2a67c9ee39c3a2dd298a9a0aec96a1eff6349344 (patch) | |
tree | 4ad76a7874c3308ece86e0e2b76b35f0ff1102df /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | b16d146838b8f4b34e072f34a5f194d9a4df4cc5 (diff) | |
download | bcm5719-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/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index dde8f2e3692..77adf7b441a 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -1026,9 +1026,25 @@ void CodeGenModule::setNonAliasAttributes(const Decl *D, llvm::GlobalObject *GO) { SetCommonAttributes(D, GO); - if (D) + if (D) { + if (auto *GV = dyn_cast<llvm::GlobalVariable>(GO)) { + if (auto *SA = D->getAttr<PragmaClangBSSSectionAttr>()) + GV->addAttribute("bss-section", SA->getName()); + if (auto *SA = D->getAttr<PragmaClangDataSectionAttr>()) + GV->addAttribute("data-section", SA->getName()); + if (auto *SA = D->getAttr<PragmaClangRodataSectionAttr>()) + GV->addAttribute("rodata-section", SA->getName()); + } + + if (auto *F = dyn_cast<llvm::Function>(GO)) { + if (auto *SA = D->getAttr<PragmaClangTextSectionAttr>()) + if (!D->getAttr<SectionAttr>()) + F->addFnAttr("implicit-section-name", SA->getName()); + } + if (const SectionAttr *SA = D->getAttr<SectionAttr>()) GO->setSection(SA->getName()); + } getTargetCodeGenInfo().setTargetAttributes(D, GO, *this); } @@ -1127,6 +1143,10 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, llvm::Function *F, setLinkageAndVisibilityForGV(F, FD); + if (FD->getAttr<PragmaClangTextSectionAttr>()) { + F->addFnAttr("implicit-section-name"); + } + if (const SectionAttr *SA = FD->getAttr<SectionAttr>()) F->setSection(SA->getName()); @@ -2828,6 +2848,14 @@ static bool isVarDeclStrongDefinition(const ASTContext &Context, if (D->hasAttr<SectionAttr>()) return true; + // A variable cannot be both common and exist in a section. + // We dont try to determine which is the right section in the front-end. + // If no specialized section name is applicable, it will resort to default. + if (D->hasAttr<PragmaClangBSSSectionAttr>() || + D->hasAttr<PragmaClangDataSectionAttr>() || + D->hasAttr<PragmaClangRodataSectionAttr>()) + return true; + // Thread local vars aren't considered common linkage. if (D->getTLSKind()) return true; |