Set __PIC__ (more) correctly.

- Add -pic-level clang-cc option to specify the value for the define,
   updated driver to pass this.

 - Added __pic__

 - Added OBJC_ZEROCOST_EXCEPTIONS define while I was here (to match gcc).

llvm-svn: 68584
This commit is contained in:
Daniel Dunbar 2009-04-08 03:03:23 +00:00
parent a60cbcdfe6
commit ab7b2f5623
5 changed files with 44 additions and 2 deletions

View File

@ -68,6 +68,8 @@ public:
unsigned Optimize : 1; // Whether __OPTIMIZE__ should be defined.
unsigned OptimizeSize : 1; // Whether __OPTIMIZE_SIZE__ should be
// defined.
unsigned PICLevel : 2; // The value for __PIC__, if non-zero.
private:
unsigned GC : 2; // Objective-C Garbage Collection modes. We declare
// this enum as unsigned because MSVC insists on making enums
@ -106,6 +108,8 @@ public:
Optimize = 0;
OptimizeSize = 0;
PICLevel = 0;
}
GCMode getGCMode() const { return (GCMode) GC; }

View File

@ -124,6 +124,17 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("--relocation-model");
CmdArgs.push_back(Model);
// Infer the __PIC__ value.
//
// FIXME: This isn't quite right on Darwin, which always sets
// __PIC__=2.
if (strcmp(Model, "pic") == 0 || strcmp(Model, "dynamic-no-pic") == 0) {
if (Args.hasArg(options::OPT_fPIC))
CmdArgs.push_back("-pic-level=2");
else
CmdArgs.push_back("-pic-level=1");
}
if (Args.hasArg(options::OPT_ftime_report))
CmdArgs.push_back("--time-passes");
// FIXME: Set --enable-unsafe-fp-math.

View File

@ -497,8 +497,10 @@ static void InitializePredefinedMacros(Preprocessor &PP,
if (PP.getLangOptions().ObjC1) {
DefineBuiltinMacro(Buf, "__OBJC__=1");
if (PP.getLangOptions().ObjCNonFragileABI)
if (PP.getLangOptions().ObjCNonFragileABI) {
DefineBuiltinMacro(Buf, "__OBJC2__=1");
DefineBuiltinMacro(Buf, "OBJC_ZEROCOST_EXCEPTIONS=1");
}
if (PP.getLangOptions().getGCMode() != LangOptions::NonGC)
DefineBuiltinMacro(Buf, "__OBJC_GC__=1");
@ -629,7 +631,14 @@ static void InitializePredefinedMacros(Preprocessor &PP,
DefineBuiltinMacro(Buf, "__DYNAMIC__=1");
DefineBuiltinMacro(Buf, "__FINITE_MATH_ONLY__=0");
DefineBuiltinMacro(Buf, "__NO_INLINE__=1");
DefineBuiltinMacro(Buf, "__PIC__=1");
if (unsigned PICLevel = PP.getLangOptions().PICLevel) {
sprintf(MacroBuf, "__PIC__=%d", PICLevel);
DefineBuiltinMacro(Buf, MacroBuf);
sprintf(MacroBuf, "__pic__=%d", PICLevel);
DefineBuiltinMacro(Buf, MacroBuf);
}
// Macros to control C99 numerics and <float.h>
DefineBuiltinMacro(Buf, "__FLT_EVAL_METHOD__=0");

View File

@ -0,0 +1,10 @@
// RUN: clang -static -dM -E -o %t %s &&
// RUN: grep '#define __PIC__' %t | count 0 &&
// RUN: grep '#define __pic__' %t | count 0 &&
// RUN: clang -fpic -dM -E -o %t %s &&
// RUN: grep '#define __PIC__ 1' %t | count 1 &&
// RUN: grep '#define __pic__ 1' %t | count 1 &&
// RUN: clang -fPIC -dM -E -o %t %s &&
// RUN: grep '#define __PIC__ 2' %t | count 1 &&
// RUN: grep '#define __pic__ 2' %t | count 1 &&
// RUN: true

View File

@ -620,6 +620,11 @@ OptLevel("O", llvm::cl::Prefix,
llvm::cl::desc("Optimization level"),
llvm::cl::init(0));
static llvm::cl::opt<unsigned>
PICLevel("pic-level", llvm::cl::Prefix,
llvm::cl::desc("Value for __PIC__"),
llvm::cl::init(0));
// FIXME: add:
// -fdollars-in-identifiers
static void InitializeLanguageStandard(LangOptions &Options, LangKind LK,
@ -769,6 +774,9 @@ static void InitializeLanguageStandard(LangOptions &Options, LangKind LK,
// -Os implies -O2
if (Options.OptimizeSize || OptLevel)
Options.Optimize = 1;
assert(PICLevel <= 2 && "Invalid value for -pic-level");
Options.PICLevel = PICLevel;
}
static llvm::cl::opt<bool>