Restructure the propagation of -fPIC/-fPIE.

The PIC and PIE levels are not independent. In fact, if PIE is defined
it is always the same as PIC.

This is clear in the driver where ParsePICArgs returns a PIC level and
a IsPIE boolean. Unfortunately that is currently lost and we pass two
redundant levels down the pipeline.

This patch keeps a bool and a PIC level all the way down to codegen.

llvm-svn: 273566
This commit is contained in:
Rafael Espindola 2016-06-23 15:07:32 +00:00
parent fcc7f6fad2
commit c9d336e549
12 changed files with 31 additions and 36 deletions

View File

@ -158,7 +158,7 @@ VALUE_LANGOPT(MaxTypeAlign , 32, 0,
"default maximum alignment for types")
VALUE_LANGOPT(AlignDouble , 1, 0, "Controls if doubles should be aligned to 8 bytes (x86 only)")
COMPATIBLE_VALUE_LANGOPT(PICLevel , 2, 0, "__PIC__ level")
COMPATIBLE_VALUE_LANGOPT(PIELevel , 2, 0, "__PIE__ level")
COMPATIBLE_VALUE_LANGOPT(PIE , 1, 0, "is pie")
COMPATIBLE_LANGOPT(GNUInline , 1, 0, "GNU inline semantics")
COMPATIBLE_LANGOPT(NoInlineDefine , 1, 0, "__NO_INLINE__ predefined macro")
COMPATIBLE_LANGOPT(Deprecated , 1, 0, "__DEPRECATED predefined macro")

View File

@ -546,8 +546,8 @@ def fencode_extended_block_signature : Flag<["-"], "fencode-extended-block-signa
HelpText<"enable extended encoding of block type signature">;
def pic_level : Separate<["-"], "pic-level">,
HelpText<"Value for __PIC__">;
def pie_level : Separate<["-"], "pie-level">,
HelpText<"Value for __PIE__">;
def pic_is_pie : Flag<["-"], "pic-is-pie">,
HelpText<"File is for a position independent executable">;
def fno_validate_pch : Flag<["-"], "fno-validate-pch">,
HelpText<"Disable validation of precompiled headers">;
def dump_deserialized_pch_decls : Flag<["-"], "dump-deserialized-decls">,

View File

@ -2830,7 +2830,7 @@ llvm::GlobalVariable *CGObjCGNU::ObjCIvarOffsetVariable(
// to replace it with the real version for a library. In non-PIC code you
// must compile with the fragile ABI if you want to use ivars from a
// GCC-compiled class.
if (CGM.getLangOpts().PICLevel || CGM.getLangOpts().PIELevel) {
if (CGM.getLangOpts().PICLevel) {
llvm::GlobalVariable *IvarOffsetGV = new llvm::GlobalVariable(TheModule,
Int32Ty, false,
llvm::GlobalValue::PrivateLinkage, OffsetGuess, Name+".guess");

View File

@ -480,11 +480,8 @@ void CodeGenModule::Release() {
if (uint32_t PLevel = Context.getLangOpts().PICLevel) {
assert(PLevel < 3 && "Invalid PIC Level");
getModule().setPICLevel(static_cast<llvm::PICLevel::Level>(PLevel));
}
if (uint32_t PLevel = Context.getLangOpts().PIELevel) {
assert(PLevel < 3 && "Invalid PIE Level");
getModule().setPIELevel(static_cast<llvm::PIELevel::Level>(PLevel));
if (Context.getLangOpts().PIE)
getModule().setPIELevel(static_cast<llvm::PIELevel::Level>(PLevel));
}
SimplifyPersonality();

View File

@ -4016,10 +4016,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
if (PICLevel > 0) {
CmdArgs.push_back("-pic-level");
CmdArgs.push_back(PICLevel == 1 ? "1" : "2");
if (IsPIE) {
CmdArgs.push_back("-pie-level");
CmdArgs.push_back(PICLevel == 1 ? "1" : "2");
}
if (IsPIE)
CmdArgs.push_back("-pic-is-pie");
}
if (Arg *A = Args.getLastArg(options::OPT_meabi)) {

View File

@ -1904,7 +1904,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
Opts.MaxTypeAlign = getLastArgIntValue(Args, OPT_fmax_type_align_EQ, 0, Diags);
Opts.AlignDouble = Args.hasArg(OPT_malign_double);
Opts.PICLevel = getLastArgIntValue(Args, OPT_pic_level, 0, Diags);
Opts.PIELevel = getLastArgIntValue(Args, OPT_pie_level, 0, Diags);
Opts.PIE = Args.hasArg(OPT_pic_is_pie);
Opts.Static = Args.hasArg(OPT_static_define);
Opts.DumpRecordLayoutsSimple = Args.hasArg(OPT_fdump_record_layouts_simple);
Opts.DumpRecordLayouts = Opts.DumpRecordLayoutsSimple
@ -2339,7 +2339,7 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
// PIClevel and PIELevel are needed during code generation and this should be
// set regardless of the input type.
LangOpts.PICLevel = getLastArgIntValue(Args, OPT_pic_level, 0, Diags);
LangOpts.PIELevel = getLastArgIntValue(Args, OPT_pie_level, 0, Diags);
LangOpts.PIE = Args.hasArg(OPT_pic_is_pie);
parseSanitizerKinds("-fsanitize=", Args.getAllArgValues(OPT_fsanitize_EQ),
Diags, LangOpts.Sanitize);
} else {

View File

@ -873,10 +873,10 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
if (unsigned PICLevel = LangOpts.PICLevel) {
Builder.defineMacro("__PIC__", Twine(PICLevel));
Builder.defineMacro("__pic__", Twine(PICLevel));
}
if (unsigned PIELevel = LangOpts.PIELevel) {
Builder.defineMacro("__PIE__", Twine(PIELevel));
Builder.defineMacro("__pie__", Twine(PIELevel));
if (LangOpts.PIE) {
Builder.defineMacro("__PIE__", Twine(PICLevel));
Builder.defineMacro("__pie__", Twine(PICLevel));
}
}
// Macros to control C99 numerics and <float.h>

View File

@ -188,7 +188,7 @@
// CHECK-NO-PIE: "-mrelocation-model" "static"
// CHECK-NO-PIE-NOT: "-pie"
// CHECK-PIE: "-mrelocation-model" "pic" "-pic-level" "2" "-pie-level" "2"
// CHECK-PIE: "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie"
// CHECK-PIE: "-pie"
// RUN: %clang -target arm-linux-androideabi %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ANDROID-NO-ASAN

View File

@ -3,26 +3,26 @@
//
// CHECK-NO-PIC: "-mrelocation-model" "static"
// CHECK-NO-PIC-NOT: "-pic-level"
// CHECK-NO-PIC-NOT: "-pie-level"
// CHECK-NO-PIC-NOT: "-pic-is-pie"
//
// CHECK-PIC1: "-mrelocation-model" "pic"
// CHECK-PIC1: "-pic-level" "1"
// CHECK-PIC1-NOT: "-pie-level"
// CHECK-PIC1-NOT: "-pic-is-pie"
//
// CHECK-PIC2: "-mrelocation-model" "pic"
// CHECK-PIC2: "-pic-level" "2"
// CHECK-PIC2-NOT: "-pie-level"
// CHECK-PIC2-NOT: "-pic-is-pie"
//
// CHECK-STATIC: "-static"
// CHECK-NO-STATIC-NOT: "-static"
//
// CHECK-PIE1: "-mrelocation-model" "pic"
// CHECK-PIE1: "-pic-level" "1"
// CHECK-PIE1: "-pie-level" "1"
// CHECK-PIE1: "-pic-is-pie"
//
// CHECK-PIE2: "-mrelocation-model" "pic"
// CHECK-PIE2: "-pic-level" "2"
// CHECK-PIE2: "-pie-level" "2"
// CHECK-PIE2: "-pic-is-pie"
//
// CHECK-PIE-LD: "{{.*}}ld{{(.exe)?}}"
// CHECK-PIE-LD: "-pie"
@ -33,11 +33,11 @@
//
// CHECK-DYNAMIC-NO-PIC-32: "-mrelocation-model" "dynamic-no-pic"
// CHECK-DYNAMIC-NO-PIC-32-NOT: "-pic-level"
// CHECK-DYNAMIC-NO-PIC-32-NOT: "-pie-level"
// CHECK-DYNAMIC-NO-PIC-32-NOT: "-pic-is-pie"
//
// CHECK-DYNAMIC-NO-PIC-64: "-mrelocation-model" "dynamic-no-pic"
// CHECK-DYNAMIC-NO-PIC-64: "-pic-level" "2"
// CHECK-DYNAMIC-NO-PIC-64-NOT: "-pie-level"
// CHECK-DYNAMIC-NO-PIC-64-NOT: "-pic-is-pie"
//
// CHECK-NON-DARWIN-DYNAMIC-NO-PIC: error: unsupported option '-mdynamic-no-pic' for target 'i386-unknown-unknown'
//

View File

@ -6,7 +6,7 @@
//
// CHECK-NO-PIC: "-mrelocation-model" "static"
// CHECK-NO-PIC-NOT: "-pic-level"
// CHECK-NO-PIC-NOT: "-pie-level"
// CHECK-NO-PIC-NOT: "-pic-is-pie"
//
// CHECK-DYNAMIC-NO-PIC2: unsupported option '-mdynamic-no-pic'
// CHECK-DYNAMIC-NO-PIC2: "-mrelocation-model" "dynamic-no-pic"
@ -15,7 +15,7 @@
// CHECK-PIC2: "-pic-level" "2"
//
// CHECK-PIE2: "-mrelocation-model" "pic"
// CHECK-PIE2: "-pie-level" "2"
// CHECK-PIE2: "-pic-is-pie"
//
// CHECK-NOPIC-IGNORED: using '-fPIC'
// CHECK-NOPIC-IGNORED: "-mrelocation-model" "pic"

View File

@ -24,7 +24,7 @@
// Can use the module if -fPIC/-fPIE flags change.
// RUN: %clang_cc1 -fmodules -DBAR=2 -pic-level 2 -x c++ -fmodule-map-file=%t/map -fmodule-file=%t/tmp.pcm -verify -I%t %s
// RUN: %clang_cc1 -fmodules -DBAR=2 -pie-level 1 -x c++ -fmodule-map-file=%t/map -fmodule-file=%t/tmp.pcm -verify -I%t %s
// RUN: %clang_cc1 -fmodules -DBAR=2 -pic-level 1 -pic-is-pie -x c++ -fmodule-map-file=%t/map -fmodule-file=%t/tmp.pcm -verify -I%t %s
// Can use the module if -static flag changes.
// RUN: %clang_cc1 -fmodules -DBAR=2 -static-define -x c++ -fmodule-map-file=%t/map -fmodule-file=%t/tmp.pcm -verify -I%t %s

View File

@ -19,16 +19,16 @@
// CHECK-PIC2: #define __pic__ 2
// CHECK-PIC2-NOT: #define __pie__
//
// RUN: %clang_cc1 -pie-level 1 -dM -E -o - %s \
// RUN: %clang_cc1 -pic-level 1 -pic-is-pie -dM -E -o - %s \
// RUN: | FileCheck --check-prefix=CHECK-PIE1 %s
// CHECK-PIE1-NOT: #define __PIC__
// CHECK-PIE1: #define __PIC__ 1
// CHECK-PIE1: #define __PIE__ 1
// CHECK-PIE1-NOT: #define __pic__
// CHECK-PIE1: #define __pic__ 1
// CHECK-PIE1: #define __pie__ 1
//
// RUN: %clang_cc1 -pie-level 2 -dM -E -o - %s \
// RUN: %clang_cc1 -pic-level 2 -pic-is-pie -dM -E -o - %s \
// RUN: | FileCheck --check-prefix=CHECK-PIE2 %s
// CHECK-PIE2-NOT: #define __PIC__
// CHECK-PIE2: #define __PIC__ 2
// CHECK-PIE2: #define __PIE__ 2
// CHECK-PIE2-NOT: #define __pic__
// CHECK-PIE2: #define __pic__ 2
// CHECK-PIE2: #define __pie__ 2