[PATCH] D128333: [clang][flang] Disable defaulting to `-fpie` for LLVM Flang
Andrzej Warzynski via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 29 00:54:02 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb405407a4899: [clang][flang] Disable defaulting to `-fpie` for LLVM Flang (authored by awarzynski).
Changed prior to commit:
https://reviews.llvm.org/D128333?vs=440874&id=440884#toc
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/docs/ReleaseNotes.md
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: flang/docs/ReleaseNotes.md
===================================================================
--- flang/docs/ReleaseNotes.md
+++ flang/docs/ReleaseNotes.md
@@ -28,6 +28,13 @@
## Non-comprehensive list of changes in this release
* The bash wrapper script, `flang`, is renamed as `flang-to-external-fc`.
+* In contrast to Clang, Flang will not default to using `-fpie` when linking
+ executables. This is only a temporary solution and the goal is to align with
+ Clang in the near future. First, however, the frontend driver needs to be
+ extended so that it can generate position independent code (that requires
+ adding support for e.g. `-fpic` and `-mrelocation-model` in `flang-new
+ -fc1`). Once that is available, support for the `-fpie` can officially be
+ added and the default behaviour updated.
## New Compiler Flags
* Refined how `-f{no-}color-diagnostics` is treated to better align with Clang.
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 {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128333.440884.patch
Type: text/x-patch
Size: 2788 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220629/85253138/attachment.bin>
More information about the cfe-commits
mailing list