awarzynski updated this revision to Diff 440628. awarzynski added a comment.
Update the test following the comments from @MaskRay Also added a comment in Linux.cpp and renamed no-pie.f90 as pic-flags.f90 (to avoid FileCheck matching e.g. `! CHECK: pie` against the file name). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D128333/new/ https://reviews.llvm.org/D128333 Files: clang/lib/Driver/ToolChains/Linux.cpp flang/test/Driver/pic-flags.f90 Index: flang/test/Driver/pic-flags.f90 =================================================================== --- /dev/null +++ flang/test/Driver/pic-flags.f90 @@ -0,0 +1,24 @@ +! Verify that in contrast to Clang, Flang does not default to generating position independent executables/code + +!------------- +! RUN COMMANDS +!------------- +! RUN: %flang -### %s -target aarch64-linux-gnu 2>&1 | FileCheck %s --check-prefix=CHECK-NOPIE +! RUN: %flang -### %s -target aarch64-linux-gnu -fno-pie 2>&1 | FileCheck %s --check-prefix=CHECK-NOPIE + +! RUN: %flang -### %s -target aarch64-linux-gnu -fpie 2>&1 | FileCheck %s --check-prefix=CHECK-PIE + +!---------------- +! EXPECTED OUTPUT +!---------------- +! CHECK-NOPIE: "-fc1" +! CHECk-NOPIE-NOT: fpic +! CHECK-NOPIE: "{{.*}}ld" +! CHECK-NOPIE-NOT: "-pie" + +! CHECK-PIE: "-fc1" +! TODO: Once Flang supports `-fpie`, it //should// use -fpic when invoking `flang -fc1`. Update the following line once `-fpie` is +! available. +! CHECk-PIE-NOT: fpic +! CHECK-PIE: "{{.*}}ld" +! CHECK-PIE-NOT: "-pie" Index: clang/lib/Driver/ToolChains/Linux.cpp =================================================================== --- clang/lib/Driver/ToolChains/Linux.cpp +++ clang/lib/Driver/ToolChains/Linux.cpp @@ -699,8 +699,11 @@ } bool Linux::isPIEDefault(const llvm::opt::ArgList &Args) const { - return CLANG_DEFAULT_PIE_ON_LINUX || getTriple().isAndroid() || - getTriple().isMusl() || getSanitizerArgs(Args).requiresPIE(); + // TODO: Remove the special treatment for Flang once its frontend driver can + // generate position independent code. + return !getDriver().IsFlangMode() && + (CLANG_DEFAULT_PIE_ON_LINUX || getTriple().isAndroid() || + getTriple().isMusl() || getSanitizerArgs(Args).requiresPIE()); } bool Linux::IsAArch64OutlineAtomicsDefault(const ArgList &Args) const {
Index: flang/test/Driver/pic-flags.f90 =================================================================== --- /dev/null +++ flang/test/Driver/pic-flags.f90 @@ -0,0 +1,24 @@ +! Verify that in contrast to Clang, Flang does not default to generating position independent executables/code + +!------------- +! RUN COMMANDS +!------------- +! RUN: %flang -### %s -target aarch64-linux-gnu 2>&1 | FileCheck %s --check-prefix=CHECK-NOPIE +! RUN: %flang -### %s -target aarch64-linux-gnu -fno-pie 2>&1 | FileCheck %s --check-prefix=CHECK-NOPIE + +! RUN: %flang -### %s -target aarch64-linux-gnu -fpie 2>&1 | FileCheck %s --check-prefix=CHECK-PIE + +!---------------- +! EXPECTED OUTPUT +!---------------- +! CHECK-NOPIE: "-fc1" +! CHECk-NOPIE-NOT: fpic +! CHECK-NOPIE: "{{.*}}ld" +! CHECK-NOPIE-NOT: "-pie" + +! CHECK-PIE: "-fc1" +! TODO: Once Flang supports `-fpie`, it //should// use -fpic when invoking `flang -fc1`. Update the following line once `-fpie` is +! available. +! CHECk-PIE-NOT: fpic +! CHECK-PIE: "{{.*}}ld" +! CHECK-PIE-NOT: "-pie" Index: clang/lib/Driver/ToolChains/Linux.cpp =================================================================== --- clang/lib/Driver/ToolChains/Linux.cpp +++ clang/lib/Driver/ToolChains/Linux.cpp @@ -699,8 +699,11 @@ } bool Linux::isPIEDefault(const llvm::opt::ArgList &Args) const { - return CLANG_DEFAULT_PIE_ON_LINUX || getTriple().isAndroid() || - getTriple().isMusl() || getSanitizerArgs(Args).requiresPIE(); + // TODO: Remove the special treatment for Flang once its frontend driver can + // generate position independent code. + return !getDriver().IsFlangMode() && + (CLANG_DEFAULT_PIE_ON_LINUX || getTriple().isAndroid() || + getTriple().isMusl() || getSanitizerArgs(Args).requiresPIE()); } bool Linux::IsAArch64OutlineAtomicsDefault(const ArgList &Args) const {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits