diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2016-06-23 15:07:32 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2016-06-23 15:07:32 +0000 |
commit | 465434bba5314276a479425b0b4d91be200c2db0 (patch) | |
tree | fc03f58326a7411ab1aace73eaaadcad5e57c6d9 | |
parent | d50bbd28750fdacc54a56b807bb0c513e19c02a6 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@273566 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/LangOptions.def | 2 | ||||
-rw-r--r-- | include/clang/Driver/CC1Options.td | 4 | ||||
-rw-r--r-- | lib/CodeGen/CGObjCGNU.cpp | 2 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenModule.cpp | 7 | ||||
-rw-r--r-- | lib/Driver/Tools.cpp | 6 | ||||
-rw-r--r-- | lib/Frontend/CompilerInvocation.cpp | 4 | ||||
-rw-r--r-- | lib/Frontend/InitPreprocessor.cpp | 8 | ||||
-rw-r--r-- | test/Driver/fsanitize.c | 2 | ||||
-rw-r--r-- | test/Driver/pic.c | 14 | ||||
-rw-r--r-- | test/Driver/ps4-pic.c | 4 | ||||
-rw-r--r-- | test/Modules/explicit-build-flags.cpp | 2 | ||||
-rw-r--r-- | test/Preprocessor/pic.c | 12 |
12 files changed, 31 insertions, 36 deletions
diff --git a/include/clang/Basic/LangOptions.def b/include/clang/Basic/LangOptions.def index 3fb4e9732d..03561961dd 100644 --- a/include/clang/Basic/LangOptions.def +++ b/include/clang/Basic/LangOptions.def @@ -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") diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index f8168448ea..8ff56e2e7c 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -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">, diff --git a/lib/CodeGen/CGObjCGNU.cpp b/lib/CodeGen/CGObjCGNU.cpp index bbe1b8b0e6..f9f48c8a47 100644 --- a/lib/CodeGen/CGObjCGNU.cpp +++ b/lib/CodeGen/CGObjCGNU.cpp @@ -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"); diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index a8abe72702..507772707c 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -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(); diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index b0a3f348b3..9e3aa46291 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -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)) { diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index ba6f6918aa..9a7992e254 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -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 { diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp index 27ef59a0c2..6b93c697d9 100644 --- a/lib/Frontend/InitPreprocessor.cpp +++ b/lib/Frontend/InitPreprocessor.cpp @@ -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> diff --git a/test/Driver/fsanitize.c b/test/Driver/fsanitize.c index fa43bfb4bb..b0cef81bc2 100644 --- a/test/Driver/fsanitize.c +++ b/test/Driver/fsanitize.c @@ -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 diff --git a/test/Driver/pic.c b/test/Driver/pic.c index d8af19a6d0..9f9d09c54c 100644 --- a/test/Driver/pic.c +++ b/test/Driver/pic.c @@ -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' // diff --git a/test/Driver/ps4-pic.c b/test/Driver/ps4-pic.c index 0cf9ad5f19..c023dcfd0c 100644 --- a/test/Driver/ps4-pic.c +++ b/test/Driver/ps4-pic.c @@ -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" diff --git a/test/Modules/explicit-build-flags.cpp b/test/Modules/explicit-build-flags.cpp index 39fd8d1e41..61300435e2 100644 --- a/test/Modules/explicit-build-flags.cpp +++ b/test/Modules/explicit-build-flags.cpp @@ -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 diff --git a/test/Preprocessor/pic.c b/test/Preprocessor/pic.c index 3e649ee5ea..ec8c9542f0 100644 --- a/test/Preprocessor/pic.c +++ b/test/Preprocessor/pic.c @@ -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 |