]> granicus.if.org Git - clang/commitdiff
Add PIC-level support to Clang.
authorJustin Hibbits <jrh29@alumni.cwru.edu>
Tue, 18 Nov 2014 06:17:20 +0000 (06:17 +0000)
committerJustin Hibbits <jrh29@alumni.cwru.edu>
Tue, 18 Nov 2014 06:17:20 +0000 (06:17 +0000)
Summary:
This distinguishes between -fpic and -fPIC now, with the additions in LLVM for
PIC level support.

Test Plan: No regressions

Reviewers: echristo, rafael

Reviewed By: rafael

Subscribers: rnk, emaste, llvm-commits

Differential Revision: http://reviews.llvm.org/D5400

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@222227 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenModule.cpp
test/CodeGen/piclevels.c [new file with mode: 0644]

index fe565523fd9cd5d1a4dcb92b07f0a445812ca8df..a68f36945773e163b8aa967ce13b30acc4dced0a 100644 (file)
@@ -391,6 +391,18 @@ void CodeGenModule::Release() {
     getModule().addModuleFlag(llvm::Module::Error, "min_enum_size", EnumWidth);
   }
 
+  if (uint32_t PLevel = Context.getLangOpts().PICLevel) {
+    llvm::PICLevel::Level PL = llvm::PICLevel::Default;
+    switch (PLevel) {
+    case 0: break;
+    case 1: PL = llvm::PICLevel::Small; break;
+    case 2: PL = llvm::PICLevel::Large; break;
+    default: llvm_unreachable("Invalid PIC Level");
+    }
+
+    getModule().setPICLevel(PL);
+  }
+
   SimplifyPersonality();
 
   if (getCodeGenOpts().EmitDeclMetadata)
diff --git a/test/CodeGen/piclevels.c b/test/CodeGen/piclevels.c
new file mode 100644 (file)
index 0000000..1cd750c
--- /dev/null
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -emit-llvm -pic-level 2 %s -o - | FileCheck %s -check-prefix=CHECK-BIGPIC
+// RUN: %clang_cc1 -emit-llvm -pic-level 1 %s -o - | FileCheck %s -check-prefix=CHECK-SMALLPIC
+
+// CHECK-BIGPIC: !llvm.module.flags = !{{{.*}}}
+// CHECK-BIGPIC: !{{[0-9]+}} = metadata !{i32 1, metadata !"PIC Level", i32 2}
+// CHECK-SMALLPIC: !llvm.module.flags = !{{{.*}}}
+// CHECK-SMALLPIC: !{{[0-9]+}} = metadata !{i32 1, metadata !"PIC Level", i32 1}