Skip to content

Commit

Permalink
Add PIC-level support to Clang.
Browse files Browse the repository at this point in the history
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

llvm-svn: 222227
  • Loading branch information
Justin Hibbits committed Nov 18, 2014
1 parent ae3e40d commit 90ca05e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions clang/test/CodeGen/piclevels.c
Original file line number Diff line number Diff line change
@@ -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}

0 comments on commit 90ca05e

Please sign in to comment.