-
Couldn't load subscription status.
- Fork 15k
[flang][Driver] Enable -pie and -no-pie in flang's driver #164890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@llvm/pr-subscribers-clang @llvm/pr-subscribers-flang-driver Author: Tarun Prabhu (tarunprabhu) ChangesPassing -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:
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
|
| 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">; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add Group<Link_Group>
|
Per @MaskRay's comment, I have changed the name of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG.
c3dd32a to
feca43d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG
e08bcf1 to
5c0ff19
Compare
|
Following investigation of the failure of pre-merge CI, I found that the tests were likely to fail on certain platforms. A number of tests have been added that check the behavior of -pie on various platforms. @DavidTruby, could you take a look at the Windows tests and see if they look reasonable? They pass for me, but I want to be certain that I have not made any bad assumptions. @DanielCChen, @kkwli, could you do the same for AIX? |
I got error when applying the patch as Even though 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!"
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test passed on Both AIX and LoP.
Thanks.
Thanks for checking Daniel. And apologies for not responding to your first question about the patch not applying. I got tangled up with other things. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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 llvm#159970
5c0ff19 to
4a25df1
Compare
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