[PATCH] D36487: Emit section information for extern variables.

Elizabeth Andrews via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 14 13:54:58 PDT 2017


eandrews updated this revision to Diff 111064.
eandrews added a comment.

As per review comments, removed extra RUNS in lit test.


https://reviews.llvm.org/D36487

Files:
  lib/CodeGen/CodeGenModule.cpp
  test/CodeGenCXX/extern-section-attribute.cpp


Index: test/CodeGenCXX/extern-section-attribute.cpp
===================================================================
--- /dev/null
+++ test/CodeGenCXX/extern-section-attribute.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - -ffreestanding -triple=x86_64-pc-linux-gnu | FileCheck %s 
+
+extern int aa __attribute__((section(".sdata")));
+// CHECK-DAG: @aa = external global i32, section ".sdata", align 4
+
+extern int bb __attribute__((section(".sdata"))) = 1;
+// CHECK-DAG: @bb = global i32 1, section ".sdata", align 4
+
+int foo() {
+  return aa + bb;
+}
Index: lib/CodeGen/CodeGenModule.cpp
===================================================================
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -2430,6 +2430,12 @@
       EmitGlobalVarDefinition(D);
     }
 
+    // Emit section information for extern variables.
+    if (D->hasExternalStorage() && !D->isThisDeclarationADefinition()) {
+      if (const SectionAttr *SA = D->getAttr<SectionAttr>())
+        GV->setSection(SA->getName());
+    }
+
     // Handle XCore specific ABI requirements.
     if (getTriple().getArch() == llvm::Triple::xcore &&
         D->getLanguageLinkage() == CLanguageLinkage &&


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36487.111064.patch
Type: text/x-patch
Size: 1215 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170814/d551496d/attachment-0001.bin>


More information about the cfe-commits mailing list