[flang-commits] [clang] [flang] [flang][Driver] Enable -pie and -no-pie in flang's driver (PR #164890)

via flang-commits flang-commits at lists.llvm.org
Thu Oct 23 13:45:58 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-driver

Author: Tarun Prabhu (tarunprabhu)

<details>
<summary>Changes</summary>

Passing -pie to flang will pass the flag on to the linker. Passing -no-pie will ensure that -pie is *not* passed to the linker. This behavior is consistent with both clang and gfortran.

Fixes #<!-- -->159970

---
Full diff: https://github.com/llvm/llvm-project/pull/164890.diff


2 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+2-2) 
- (modified) flang/test/Driver/misc-flags.f90 (+10) 


``````````diff
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 0c9584f1b479f..40ca2f9717d55 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5999,7 +5999,6 @@ def nofixprebinding : Flag<["-"], "nofixprebinding">;
 def nolibc : Flag<["-"], "nolibc">;
 def nomultidefs : Flag<["-"], "nomultidefs">;
 def nopie : Flag<["-"], "nopie">, Visibility<[ClangOption, FlangOption]>, Flags<[TargetSpecific]>; // OpenBSD
-def no_pie : Flag<["-"], "no-pie">, Visibility<[ClangOption, FlangOption]>;
 def noprebind : Flag<["-"], "noprebind">;
 def noprofilelib : Flag<["-"], "noprofilelib">;
 def noseglinkedit : Flag<["-"], "noseglinkedit">;
@@ -6113,7 +6112,6 @@ defm pthread : BoolOption<"", "pthread",
   PosFlag<SetTrue, [], [ClangOption], "Support POSIX threads in generated code">,
   NegFlag<SetFalse>,
   BothFlags<[], [ClangOption, CC1Option, FlangOption, FC1Option]>>;
-def pie : Flag<["-"], "pie">, Group<Link_Group>;
 def static_pie : Flag<["-"], "static-pie">, Group<Link_Group>;
 def read__only__relocs : Separate<["-"], "read_only_relocs">;
 def remap : Flag<["-"], "remap">;
@@ -6508,6 +6506,8 @@ def fpic : Flag<["-"], "fpic">, Group<f_Group>;
 def fno_pic : Flag<["-"], "fno-pic">, Group<f_Group>;
 def fpie : Flag<["-"], "fpie">, Group<f_Group>;
 def fno_pie : Flag<["-"], "fno-pie">, Group<f_Group>;
+def pie : Flag<["-"], "pie">, Group<Link_Group>;
+def no_pie : Flag<["-"], "no-pie">;
 
 } // let Vis = [Default, FlangOption]
 
diff --git a/flang/test/Driver/misc-flags.f90 b/flang/test/Driver/misc-flags.f90
index 61d763c5b64dd..e594c9cb50517 100644
--- a/flang/test/Driver/misc-flags.f90
+++ b/flang/test/Driver/misc-flags.f90
@@ -10,6 +10,16 @@
 ! Make sure that `-L' is "visible" to Flang's driver
 ! RUN: %flang -L/ -### %s
 
+! Check that '-pie' is "visible" to Flang's driver and is passed on to the
+! linker.
+! RUN: %flang -pie -### %s 2>&1 | FileCheck %s --check-prefix=PIE
+! PIE: "-pie"
+
+! Check that '-no-pie' is "visible" to Flang's driver and that "-pie" is *not*
+! passed to the linker.
+! RUN: %flang -no-pie -### %s 2>&1 | FileCheck %s --check-prefix=NO-PIE
+! NO-PIE-NOT: "-pie"
+
 program hello
   write(*,*), "Hello world!"
 end program hello

``````````

</details>


https://github.com/llvm/llvm-project/pull/164890


More information about the flang-commits mailing list