diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp --- a/clang/lib/Driver/ToolChains/Linux.cpp +++ b/clang/lib/Driver/ToolChains/Linux.cpp @@ -699,8 +699,9 @@ } bool Linux::isPIEDefault(const llvm::opt::ArgList &Args) const { - return CLANG_DEFAULT_PIE_ON_LINUX || getTriple().isAndroid() || - getTriple().isMusl() || getSanitizerArgs(Args).requiresPIE(); + return !getDriver().IsFlangMode() && + (CLANG_DEFAULT_PIE_ON_LINUX || getTriple().isAndroid() || + getTriple().isMusl() || getSanitizerArgs(Args).requiresPIE()); } bool Linux::IsAArch64OutlineAtomicsDefault(const ArgList &Args) const { diff --git a/flang/test/Driver/no-pie.f90 b/flang/test/Driver/no-pie.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Driver/no-pie.f90 @@ -0,0 +1,12 @@ +! Verify that in contrast to Clang, Flang does not default to generating position independent executables/code + +!------------- +! RUN COMMANDS +!------------- +! RUN: %flang -### -flang-experimental-exec %S/Inputs/hello.f90 2>&1 | FileCheck %s + +!---------------- +! EXPECTED OUTPUT +!---------------- +! CHECK-NOT: fpie +! CHECK-NOT: fpic