From 99fdfb6a464467aeb8c8935b0aa8d68ba4f902a5 Mon Sep 17 00:00:00 2001 From: Erich Keane Date: Tue, 26 Sep 2017 23:42:34 +0000 Subject: Emit section information for extern variables. Currently, if _attribute_((section())) is used for extern variables, section information is not emitted in generated IR when the variables are used. This is expected since sections are not generated for external linkage objects. However NiosII requires this information as it uses special GP-relative accesses for any objects that use attribute section (.sdata). GCC keeps this attribute in middle-end. This change emits the section information for all targets. Patch By: Elizabeth Andrews Differential Revision:https://reviews.llvm.org/D36487 llvm-svn: 314262 --- clang/lib/CodeGen/CodeGenModule.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'clang/lib/CodeGen') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 03a3e36b831..89185c89518 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2432,6 +2432,12 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, EmitGlobalVarDefinition(D); } + // Emit section information for extern variables. + if (D->hasExternalStorage()) { + if (const SectionAttr *SA = D->getAttr()) + GV->setSection(SA->getName()); + } + // Handle XCore specific ABI requirements. if (getTriple().getArch() == llvm::Triple::xcore && D->getLanguageLinkage() == CLanguageLinkage && -- cgit v1.2.3