Author: rafael Date: Thu Jun 23 10:07:32 2016 New Revision: 273566 URL: http://llvm.org/viewvc/llvm-project?rev=273566&view=rev Log: 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. Modified: cfe/trunk/include/clang/Basic/LangOptions.def cfe/trunk/include/clang/Driver/CC1Options.td cfe/trunk/lib/CodeGen/CGObjCGNU.cpp cfe/trunk/lib/CodeGen/CodeGenModule.cpp cfe/trunk/lib/Driver/Tools.cpp cfe/trunk/lib/Frontend/CompilerInvocation.cpp cfe/trunk/lib/Frontend/InitPreprocessor.cpp cfe/trunk/test/Driver/fsanitize.c cfe/trunk/test/Driver/pic.c cfe/trunk/test/Driver/ps4-pic.c cfe/trunk/test/Modules/explicit-build-flags.cpp cfe/trunk/test/Preprocessor/pic.c Modified: cfe/trunk/include/clang/Basic/LangOptions.def URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.def?rev=273566&r1=273565&r2=273566&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/LangOptions.def (original) +++ cfe/trunk/include/clang/Basic/LangOptions.def Thu Jun 23 10:07:32 2016 @@ -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") Modified: cfe/trunk/include/clang/Driver/CC1Options.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=273566&r1=273565&r2=273566&view=diff ============================================================================== --- cfe/trunk/include/clang/Driver/CC1Options.td (original) +++ cfe/trunk/include/clang/Driver/CC1Options.td Thu Jun 23 10:07:32 2016 @@ -546,8 +546,8 @@ def fencode_extended_block_signature : F 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">, Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=273566&r1=273565&r2=273566&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original) +++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Thu Jun 23 10:07:32 2016 @@ -2830,7 +2830,7 @@ llvm::GlobalVariable *CGObjCGNU::ObjCIva // 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"); Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=273566&r1=273565&r2=273566&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original) +++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Jun 23 10:07:32 2016 @@ -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(); Modified: cfe/trunk/lib/Driver/Tools.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=273566&r1=273565&r2=273566&view=diff ============================================================================== --- cfe/trunk/lib/Driver/Tools.cpp (original) +++ cfe/trunk/lib/Driver/Tools.cpp Thu Jun 23 10:07:32 2016 @@ -4016,10 +4016,8 @@ void Clang::ConstructJob(Compilation &C, 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)) { Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=273566&r1=273565&r2=273566&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original) +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Thu Jun 23 10:07:32 2016 @@ -1904,7 +1904,7 @@ static void ParseLangArgs(LangOptions &O 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( // 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 { Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=273566&r1=273565&r2=273566&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original) +++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Thu Jun 23 10:07:32 2016 @@ -873,10 +873,10 @@ static void InitializePredefinedMacros(c 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> Modified: cfe/trunk/test/Driver/fsanitize.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fsanitize.c?rev=273566&r1=273565&r2=273566&view=diff ============================================================================== --- cfe/trunk/test/Driver/fsanitize.c (original) +++ cfe/trunk/test/Driver/fsanitize.c Thu Jun 23 10:07:32 2016 @@ -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 Modified: cfe/trunk/test/Driver/pic.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/pic.c?rev=273566&r1=273565&r2=273566&view=diff ============================================================================== --- cfe/trunk/test/Driver/pic.c (original) +++ cfe/trunk/test/Driver/pic.c Thu Jun 23 10:07:32 2016 @@ -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' // Modified: cfe/trunk/test/Driver/ps4-pic.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/ps4-pic.c?rev=273566&r1=273565&r2=273566&view=diff ============================================================================== --- cfe/trunk/test/Driver/ps4-pic.c (original) +++ cfe/trunk/test/Driver/ps4-pic.c Thu Jun 23 10:07:32 2016 @@ -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" Modified: cfe/trunk/test/Modules/explicit-build-flags.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/explicit-build-flags.cpp?rev=273566&r1=273565&r2=273566&view=diff ============================================================================== --- cfe/trunk/test/Modules/explicit-build-flags.cpp (original) +++ cfe/trunk/test/Modules/explicit-build-flags.cpp Thu Jun 23 10:07:32 2016 @@ -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 Modified: cfe/trunk/test/Preprocessor/pic.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/pic.c?rev=273566&r1=273565&r2=273566&view=diff ============================================================================== --- cfe/trunk/test/Preprocessor/pic.c (original) +++ cfe/trunk/test/Preprocessor/pic.c Thu Jun 23 10:07:32 2016 @@ -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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits