Skip to content

Commit 9f50e24

Browse files
authored
[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
1 parent aa5fe56 commit 9f50e24

File tree

3 files changed

+108
-17
lines changed

3 files changed

+108
-17
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5999,7 +5999,6 @@ def nofixprebinding : Flag<["-"], "nofixprebinding">;
59995999
def nolibc : Flag<["-"], "nolibc">;
60006000
def nomultidefs : Flag<["-"], "nomultidefs">;
60016001
def nopie : Flag<["-"], "nopie">, Visibility<[ClangOption, FlangOption]>, Flags<[TargetSpecific]>; // OpenBSD
6002-
def no_pie : Flag<["-"], "no-pie">, Visibility<[ClangOption, FlangOption]>;
60036002
def noprebind : Flag<["-"], "noprebind">;
60046003
def noprofilelib : Flag<["-"], "noprofilelib">;
60056004
def noseglinkedit : Flag<["-"], "noseglinkedit">;
@@ -6113,7 +6112,6 @@ defm pthread : BoolOption<"", "pthread",
61136112
PosFlag<SetTrue, [], [ClangOption], "Support POSIX threads in generated code">,
61146113
NegFlag<SetFalse>,
61156114
BothFlags<[], [ClangOption, CC1Option, FlangOption, FC1Option]>>;
6116-
def pie : Flag<["-"], "pie">, Group<Link_Group>;
61176115
def static_pie : Flag<["-"], "static-pie">, Group<Link_Group>;
61186116
def read__only__relocs : Separate<["-"], "read_only_relocs">;
61196117
def remap : Flag<["-"], "remap">;
@@ -6508,6 +6506,8 @@ def fpic : Flag<["-"], "fpic">, Group<f_Group>;
65086506
def fno_pic : Flag<["-"], "fno-pic">, Group<f_Group>;
65096507
def fpie : Flag<["-"], "fpie">, Group<f_Group>;
65106508
def fno_pie : Flag<["-"], "fno-pie">, Group<f_Group>;
6509+
def pie : Flag<["-"], "pie">, Group<Link_Group>;
6510+
def no_pie : Flag<["-"], "no-pie">, Group<Link_Group>;
65116511

65126512
} // let Vis = [Default, FlangOption]
65136513

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
! Make sure that `-l` is "visible" to Flang's driver
2+
! RUN: %flang -lpgmath -### %s
3+
4+
! Make sure that `-Wl` is "visible" to Flang's driver
5+
! RUN: %flang -Wl,abs -### %s
6+
7+
! Make sure that `-fuse-ld' is "visible" to Flang's driver
8+
! RUN: %flang -fuse-ld= -### %s
9+
10+
! Make sure that `-L' is "visible" to Flang's driver
11+
! RUN: %flang -L/ -### %s
12+
13+
! ------------------------------------------------------------------------------
14+
! Check that '-pie' and '-no-pie' are "visible" to Flang's driver. Check that
15+
! the correct option is added to the link line.
16+
!
17+
! Last match "wins"
18+
! RUN: %flang -target x86_64-pc-linux-gnu -pie -no-pie -### %s 2>&1 \
19+
! RUN: | FileCheck %s --check-prefix=NO-PIE
20+
! RUN: %flang -target x86_64-pc-linux-gnu -no-pie -pie -### %s 2>&1 \
21+
! RUN: | FileCheck %s --check-prefix=PIE
22+
! RUN: %flang -target x86_64-pc-linux-gnu -pie -### %s 2>&1 \
23+
! RUN: | FileCheck %s --check-prefix=PIE
24+
! RUN: %flang -target x86_64-pc-linux-gnu -no-pie -### %s 2>&1 \
25+
! RUN: | FileCheck %s --check-prefix=NO-PIE
26+
!
27+
! Ensure that "-pie" is passed to the linker.
28+
! RUN: %flang -target i386-unknown-freebsd -pie -### %s 2>&1 \
29+
! RUN: | FileCheck %s --check-prefix=PIE
30+
! RUN: %flang -target aarch64-pc-linux-gnu -pie -### %s 2>&1 \
31+
! RUN: | FileCheck %s --check-prefix=PIE
32+
!
33+
! On Musl Linux, PIE is enabled by default, but can be disabled.
34+
! RUN: %flang -target x86_64-linux-musl -### %s 2>&1 \
35+
! RUN: | FileCheck %s --check-prefix=PIE
36+
! RUN: %flang -target i686-linux-musl -### %s 2>&1 \
37+
! RUN: | FileCheck %s --check-prefix=PIE
38+
! RUN: %flang -target armv6-linux-musleabihf %s -### 2>&1 \
39+
! RUN: | FileCheck %s --check-prefix=PIE
40+
! RUN: %flang -target armv7-linux-musleabihf %s -### 2>&1 \
41+
! RUN: | FileCheck %s --check-prefix=PIE
42+
! RUN: %flang --target=x86_64-linux-musl -no-pie -### 2>&1 \
43+
! RUN: | FileCheck %s --check-prefix=NO-PIE
44+
!
45+
! On OpenBSD, -pie is not passed to the linker, but can be forced.
46+
! RUN: %flang -target amd64-pc-openbsd -### %s 2>&1 \
47+
! RUN: | FileCheck %s --check-prefix=NO-PIE
48+
! RUN: %flang -target i386-pc-openbsd -### %s 2>&1 \
49+
! RUN: | FileCheck %s --check-prefix=NO-PIE
50+
! RUN: %flang -target aarch64-unknown-openbsd -### %s 2>&1 \
51+
! RUN: | FileCheck %s --check-prefix=NO-PIE
52+
! RUN: %flang -target arm-unknown-openbsd -### %s 2>&1 \
53+
! RUN: | FileCheck %s --check-prefix=NO-PIE
54+
! RUN: %flang -target powerpc-unknown-openbsd -### %s 2>&1 \
55+
! RUN: | FileCheck %s --check-prefix=NO-PIE
56+
! RUN: %flang -target sparc64-unknown-openbsd -### %s 2>&1 \
57+
! RUN: | FileCheck %s --check-prefix=NO-PIE
58+
! RUN: %flang -target i386-pc-openbsd -pie -### %s 2>&1 \
59+
! RUN: | FileCheck %s --check-prefix=PIE
60+
!
61+
! On FreeBSD, -pie is not passed to the linker, but can be forced.
62+
! RUN: %flang -target amd64-pc-freebsd -### %s 2>&1 \
63+
! RUN: | FileCheck %s --check-prefix=NO-PIE
64+
! RUN: %flang -target i386-pc-freebsd -### %s 2>&1 \
65+
! RUN: | FileCheck %s --check-prefix=NO-PIE
66+
! RUN: %flang -target aarch64-unknown-freebsd -### %s 2>&1 \
67+
! RUN: | FileCheck %s --check-prefix=NO-PIE
68+
! RUN: %flang -target arm-unknown-freebsd -### %s 2>&1 \
69+
! RUN: | FileCheck %s --check-prefix=NO-PIE
70+
! RUN: %flang -target powerpc-unknown-freebsd -### %s 2>&1 \
71+
! RUN: | FileCheck %s --check-prefix=NO-PIE
72+
! RUN: %flang -target sparc64-unknown-freebsd -### %s 2>&1 \
73+
! RUN: | FileCheck %s --check-prefix=NO-PIE
74+
! RUN: %flang -target i386-pc-freebsd -pie -### %s 2>&1 \
75+
! RUN: | FileCheck %s --check-prefix=PIE
76+
!
77+
! On AIX, -pie is never passed to the linker.
78+
! RUN: %flang -target powerpc64-unknown-aix -### %s 2>&1 \
79+
! RUN: | FileCheck %s --check-prefixes=NO-PIE
80+
! RUN: %flang -target powerpc64-unknown-aix -pie -### %s 2>&1 \
81+
! RUN: | FileCheck %s --check-prefixes=NO-PIE,UNUSED
82+
! RUN: %flang -target powerpc64-unknown-aix -no-pie -### %s 2>&1 \
83+
! RUN: | FileCheck %s --check-prefixes=NO-PIE,UNUSED
84+
!
85+
! On MinGW and Windows, -pie may be specified, but it is ignored.
86+
! RUN: %flang -target aarch64-pc-windows-gnu -### %s 2>&1 \
87+
! RUN: | FileCheck %s --check-prefixes=NO-PIE
88+
! RUN: %flang -target x86_64-pc-windows-gnu -pie -### %s 2>&1 \
89+
! RUN: | FileCheck %s --check-prefixes=NO-PIE,UNUSED
90+
! RUN: %flang -target i686-pc-windows-gnu -no-pie -### %s 2>&1 \
91+
! RUN: | FileCheck %s --check-prefixes=NO-PIE,UNUSED
92+
! RUN: %flang -target aarch64-windows-msvc -### %s 2>&1 \
93+
! RUN: | FileCheck %s --check-prefixes=NO-PIE
94+
! RUN: %flang -target aarch64-windows-msvc -pie -### %s 2>&1 \
95+
! RUN: | FileCheck %s --check-prefixes=NO-PIE,UNUSED
96+
! RUN: %flang -target aarch64-windows-msvc -no-pie -### %s 2>&1 \
97+
! RUN: | FileCheck %s --check-prefixes=NO-PIE,UNUSED
98+
!
99+
! PIE: "-pie"
100+
! NO-PIE-NOT: "-pie"
101+
! UNUSED: warning: argument unused during compilation: '{{(-no)?}}-pie'
102+
! ------------------------------------------------------------------------------
103+
104+
program hello
105+
write(*,*), "Hello world!"
106+
end program hello

flang/test/Driver/misc-flags.f90

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)