[flang-commits] [clang] [flang] [flang][Driver] Enable -pie and -no-pie in flang's driver (PR #164890)
Tarun Prabhu via flang-commits
flang-commits at lists.llvm.org
Sun Oct 26 11:09:49 PDT 2025
https://github.com/tarunprabhu updated https://github.com/llvm/llvm-project/pull/164890
>From 3189a023e52154c37e72ed112c0fe2664a16cd69 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu <tarun at lanl.gov>
Date: Thu, 23 Oct 2025 14:41:02 -0600
Subject: [PATCH 1/2] [flang][Driver] Enable -pie and -no-pie in flang's driver
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
---
clang/include/clang/Driver/Options.td | 4 ++--
flang/test/Driver/misc-flags.f90 | 10 ++++++++++
2 files changed, 12 insertions(+), 2 deletions(-)
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
>From c3dd32a7739e607d9cb3ad3fe30cc26157b8767f Mon Sep 17 00:00:00 2001
From: Tarun Prabhu <tarun.prabhu at gmail.com>
Date: Sun, 26 Oct 2025 12:09:18 -0600
Subject: [PATCH 2/2] Address reviewer comments
---
clang/include/clang/Driver/Options.td | 6 +++---
flang/test/Driver/{misc-flags.f90 => linker-options.f90} | 0
2 files changed, 3 insertions(+), 3 deletions(-)
rename flang/test/Driver/{misc-flags.f90 => linker-options.f90} (100%)
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 40ca2f9717d55..880a62264699d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4372,7 +4372,7 @@ def fno_trigraphs : Flag<["-"], "fno-trigraphs">, Group<f_Group>,
HelpText<"Do not process trigraph sequences">,
Visibility<[ClangOption, CC1Option]>;
def funique_source_file_names: Flag<["-"], "funique-source-file-names">, Group<f_Group>,
- HelpText<"Allow the compiler to assume that each translation unit has a unique "
+ HelpText<"Allow the compiler to assume that each translation unit has a unique "
"source file identifier (see -funique-source-file-identifier) at link time">;
def fno_unique_source_file_names: Flag<["-"], "fno-unique-source-file-names">;
def unique_source_file_identifier_EQ: Joined<["-"], "funique-source-file-identifier=">, Group<f_Group>,
@@ -6507,7 +6507,7 @@ 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">;
+def no_pie : Flag<["-"], "no-pie">, Group<Link_Group>;
} // let Vis = [Default, FlangOption]
@@ -7189,7 +7189,7 @@ defm android_pad_segment : BooleanFFlag<"android-pad-segment">, Group<f_Group>;
def shared_libflangrt : Flag<["-"], "shared-libflangrt">,
HelpText<"Link the flang-rt shared library">, Group<Link_Group>,
Visibility<[FlangOption]>, Flags<[NoArgumentUnused]>;
-def static_libflangrt : Flag<["-"], "static-libflangrt">,
+def static_libflangrt : Flag<["-"], "static-libflangrt">,
HelpText<"Link the flang-rt static library">, Group<Link_Group>,
Visibility<[FlangOption]>, Flags<[NoArgumentUnused]>;
diff --git a/flang/test/Driver/misc-flags.f90 b/flang/test/Driver/linker-options.f90
similarity index 100%
rename from flang/test/Driver/misc-flags.f90
rename to flang/test/Driver/linker-options.f90
More information about the flang-commits
mailing list