[llvm-branch-commits] [clang] [flang] [clang] Switch to Default PIE on FreeBSD (PR #206139)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Jun 30 18:31:41 PDT 2026


https://github.com/aokblast updated https://github.com/llvm/llvm-project/pull/206139

>From e7ecd4652263bd5e22a9ca2fbb1563e1d4d986b8 Mon Sep 17 00:00:00 2001
From: ShengYi Hung <aokblast at FreeBSD.org>
Date: Mon, 29 Jun 2026 13:54:54 -0500
Subject: [PATCH 1/3] [Clang] Switch to Default PIE on FreeBSD

We have started to compile the binary in our base as PIE by defualt. It
makes sense to compile the binary to PIE by default in toolchain as
Linux now. Also, extended testcases to support default PIE and no-pie
parameter in freebsd.c and hip-fpie-option.hip.
---
 clang/lib/Driver/ToolChains/FreeBSD.cpp |  7 ++-
 clang/test/Driver/freebsd-mips-as.c     |  4 +-
 clang/test/Driver/freebsd.c             | 56 +++++++++++++++++++++---
 clang/test/Driver/hip-fpie-option.hip   | 58 +++++++++++++++++++++----
 4 files changed, 103 insertions(+), 22 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index 1218868ac3bda..4e4388ee5bbed 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -134,9 +134,8 @@ void freebsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
   const Driver &D = ToolChain.getDriver();
   const llvm::Triple &Triple = ToolChain.getTriple();
   const llvm::Triple::ArchType Arch = ToolChain.getArch();
-  const bool IsPIE =
-      !Args.hasArg(options::OPT_shared) &&
-      (Args.hasArg(options::OPT_pie) || ToolChain.isPIEDefault(Args));
+  const bool IsPIE = Args.hasFlag(options::OPT_pie, options::OPT_no_pie,
+                                  ToolChain.isPIEDefault(Args));
   ArgStringList CmdArgs;
 
   // Silence warning for "clang -g foo.o -o foo"
@@ -473,7 +472,7 @@ FreeBSD::getDefaultUnwindTableLevel(const ArgList &Args) const {
 }
 
 bool FreeBSD::isPIEDefault(const llvm::opt::ArgList &Args) const {
-  return getSanitizerArgs(Args).requiresPIE();
+  return CLANG_DEFAULT_PIE || getSanitizerArgs(Args).requiresPIE();
 }
 
 SanitizerMask
diff --git a/clang/test/Driver/freebsd-mips-as.c b/clang/test/Driver/freebsd-mips-as.c
index 428644ab78a9f..8585d791460c9 100644
--- a/clang/test/Driver/freebsd-mips-as.c
+++ b/clang/test/Driver/freebsd-mips-as.c
@@ -1,7 +1,7 @@
 // Check passing options to the assembler for MIPS targets.
 //
 // RUN: %clang --target=mips-unknown-freebsd -### \
-// RUN:   -no-integrated-as -c %s 2>&1 \
+// RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS32-EB-AS %s
 // MIPS32-EB-AS: as{{(.exe)?}}" "-march" "mips2" "-mabi" "32" "-EB"
 // MIPS32-EB-AS-NOT: "-KPIC"
@@ -86,7 +86,7 @@
 // MIPS-ALIAS-64R2: as{{(.exe)?}}" "-march" "mips64r2" "-mabi" "64" "-EB"
 //
 // RUN: %clang --target=mips-unknown-freebsd -### \
-// RUN:   -no-integrated-as -G0 -c %s 2>&1 \
+// RUN:   -no-integrated-as -fno-pic -G0 -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS32-EB-AS-G0 %s
 // MIPS32-EB-AS-G0: as{{(.exe)?}}" "-march" "mips2" "-mabi" "32" "-EB" "-G0"
 // MIPS32-EB-AS-G0-NOT: "-KPIC"
diff --git a/clang/test/Driver/freebsd.c b/clang/test/Driver/freebsd.c
index bb0558b9ceb3e..7e6e41f5ccca2 100644
--- a/clang/test/Driver/freebsd.c
+++ b/clang/test/Driver/freebsd.c
@@ -3,8 +3,17 @@
 // RUN:   --sysroot=%S/Inputs/basic_freebsd64_tree -### 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-ARM64 %s
 // CHECK-ARM64: "-cc1" "-triple" "aarch64-pc-freebsd11"
-// CHECK-ARM64: ld{{.*}}" "--sysroot=[[SYSROOT:[^"]+]]"
-// CHECK-ARM64: "--eh-frame-hdr" "-dynamic-linker" "{{.*}}ld-elf{{.*}}" "-o" "a.out" "{{.*}}crt1.o" "{{.*}}crti.o" "{{.*}}crtbegin.o" "-L[[SYSROOT]]/usr/lib" "{{.*}}.o" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "{{.*}}crtend.o" "{{.*}}crtn.o"
+// CHECK-ARM64: ld{{.*}}" "--sysroot=[[SYSROOT:[^"]+]]" "-pie"
+// CHECK-ARM64: "--eh-frame-hdr" "-dynamic-linker" "{{.*}}ld-elf{{.*}}"  "--enable-new-dtags" "-o" "a.out" "{{.*}}crt1.o" "{{.*}}crti.o" "{{.*}}crtbeginS.o" "-L[[SYSROOT]]/usr/lib" "{{.*}}.o" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "{{.*}}crtendS.o" "{{.*}}crtn.o"
+
+// RUN: %clang -no-pie \
+// RUN:   --target=aarch64-pc-freebsd11 %s                              \
+// RUN:   --sysroot=%S/Inputs/basic_freebsd64_tree -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-ARM64-NOPIE %s
+// CHECK-ARM64-NOPIE: "-cc1" "-triple" "aarch64-pc-freebsd11"
+// CHECK-ARM64-NOPIE: ld{{.*}}" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-ARM64-NOPIE: "--eh-frame-hdr" "-dynamic-linker" "{{.*}}ld-elf{{.*}}" "-o" "a.out" "{{.*}}crt1.o" "{{.*}}crti.o" "{{.*}}crtbegin.o" "-L[[SYSROOT]]/usr/lib" "{{.*}}.o" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "{{.*}}crtend.o" "{{.*}}crtn.o"
+
 //
 // RUN: %clang \
 // RUN:   --target=powerpc-pc-freebsd %s    \
@@ -12,7 +21,17 @@
 // RUN:   | FileCheck --check-prefix=CHECK-PPC %s
 // CHECK-PPC: "-cc1" "-triple" "powerpc-pc-freebsd"
 // CHECK-PPC: ld{{.*}}" "--sysroot=[[SYSROOT:[^"]+]]"
-// CHECK-PPC: "--eh-frame-hdr" "-dynamic-linker" "{{.*}}ld-elf{{.*}}" "-o" "a.out" "{{.*}}crt1.o" "{{.*}}crti.o" "{{.*}}crtbegin.o" "-L[[SYSROOT]]/usr/lib" "{{.*}}.o" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "{{.*}}crtend.o" "{{.*}}crtn.o"
+// CHECK-PPC: "--eh-frame-hdr" "-dynamic-linker" "{{.*}}ld-elf{{.*}}" "--enable-new-dtags" "-m" "elf32ppc_fbsd" "-o" "a.out" "{{.*}}crt1.o" "{{.*}}crti.o" "{{.*}}crtbeginS.o" "-L[[SYSROOT]]/usr/lib" "{{.*}}.o" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "{{.*}}crtendS.o" "{{.*}}crtn.o"
+
+//
+// RUN: %clang -no-pie \
+// RUN:   --target=powerpc-pc-freebsd %s    \
+// RUN:   --sysroot=%S/Inputs/basic_freebsd_tree -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-PPC-NOPIE %s
+// CHECK-PPC-NOPIE: "-cc1" "-triple" "powerpc-pc-freebsd"
+// CHECK-PPC-NOPIE: ld{{.*}}" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-PPC-NOPIE: "--eh-frame-hdr" "-dynamic-linker" "{{.*}}ld-elf{{.*}}" "-o" "a.out" "{{.*}}crt1.o" "{{.*}}crti.o" "{{.*}}crtbegin.o" "-L[[SYSROOT]]/usr/lib" "{{.*}}.o" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "{{.*}}crtend.o" "{{.*}}crtn.o"
+
 //
 // RUN: %clang \
 // RUN:   --target=powerpc64-pc-freebsd %s                              \
@@ -20,7 +39,15 @@
 // RUN:   | FileCheck --check-prefix=CHECK-PPC64 %s
 // CHECK-PPC64: "-cc1" "-triple" "powerpc64-pc-freebsd"
 // CHECK-PPC64: ld{{.*}}" "--sysroot=[[SYSROOT:[^"]+]]"
-// CHECK-PPC64: "--eh-frame-hdr" "-dynamic-linker" "{{.*}}ld-elf{{.*}}" "-o" "a.out" "{{.*}}crt1.o" "{{.*}}crti.o" "{{.*}}crtbegin.o" "-L[[SYSROOT]]/usr/lib" "{{.*}}.o" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "{{.*}}crtend.o" "{{.*}}crtn.o"
+// CHECK-PPC64: "--eh-frame-hdr" "-dynamic-linker" "{{.*}}ld-elf{{.*}}" "--enable-new-dtags" "-o" "a.out" "{{.*}}crt1.o" "{{.*}}crti.o" "{{.*}}crtbeginS.o" "-L[[SYSROOT]]/usr/lib" "{{.*}}.o" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "{{.*}}crtendS.o" "{{.*}}crtn.o"
+
+// RUN: %clang -no-pie \
+// RUN:   --target=powerpc64-pc-freebsd %s                              \
+// RUN:   --sysroot=%S/Inputs/basic_freebsd64_tree -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-PPC64-NOPIE %s
+// CHECK-PPC64-NOPIE: "-cc1" "-triple" "powerpc64-pc-freebsd"
+// CHECK-PPC64-NOPIE: ld{{.*}}" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-PPC64-NOPIE: "--eh-frame-hdr" "-dynamic-linker" "{{.*}}ld-elf{{.*}}" "-o" "a.out" "{{.*}}crt1.o" "{{.*}}crti.o" "{{.*}}crtbegin.o" "-L[[SYSROOT]]/usr/lib" "{{.*}}.o" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "{{.*}}crtend.o" "{{.*}}crtn.o"
 
 // RUN: %clang \
 // RUN:   --target=powerpc64le-unknown-freebsd13 %s \
@@ -28,7 +55,16 @@
 // RUN:   | FileCheck --check-prefix=CHECK-PPC64LE %s
 // CHECK-PPC64LE: "-cc1" "-triple" "powerpc64le-unknown-freebsd13"
 // CHECK-PPC64LE: ld{{.*}}" "--sysroot=[[SYSROOT:[^"]+]]"
-// CHECK-PPC64LE: "--eh-frame-hdr" "-dynamic-linker" "{{.*}}ld-elf{{.*}}" "-o" "a.out" "{{.*}}crt1.o" "{{.*}}crti.o" "{{.*}}crtbegin.o" "-L[[SYSROOT]]/usr/lib" "{{.*}}.o" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "{{.*}}crtend.o" "{{.*}}crtn.o"
+// CHECK-PPC64LE: "--eh-frame-hdr" "-dynamic-linker" "{{.*}}ld-elf{{.*}}" "--enable-new-dtags" "-o" "a.out" "{{.*}}crt1.o" "{{.*}}crti.o" "{{.*}}crtbeginS.o" "-L[[SYSROOT]]/usr/lib" "{{.*}}.o" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "{{.*}}crtendS.o" "{{.*}}crtn.o"
+
+// RUN: %clang -no-pie \
+// RUN:   --target=powerpc64le-unknown-freebsd13 %s \
+// RUN:   --sysroot=%S/Inputs/basic_freebsd64_tree -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-PPC64LE-NOPIE %s
+// CHECK-PPC64LE-NOPIE: "-cc1" "-triple" "powerpc64le-unknown-freebsd13"
+// CHECK-PPC64LE-NOPIE: ld{{.*}}" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-PPC64LE-NOPIE: "--eh-frame-hdr" "-dynamic-linker" "{{.*}}ld-elf{{.*}}" "-o" "a.out" "{{.*}}crt1.o" "{{.*}}crti.o" "{{.*}}crtbegin.o" "-L[[SYSROOT]]/usr/lib" "{{.*}}.o" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "{{.*}}crtend.o" "{{.*}}crtn.o"
+
 
 //
 // Check that -m32 properly adjusts the toolchain flags.
@@ -151,8 +187,14 @@
 // RUN: %clang --target=x86_64-pc-freebsd %s \
 // RUN:   --sysroot=%S/Inputs/multiarch_freebsd64_tree -### 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NORMAL %s
-// CHECK-NORMAL: crt1.o
-// CHECK-NORMAL: crtbegin.o
+// CHECK-NORMAL: Scrt1.o
+// CHECK-NORMAL: crtbeginS.o
+
+// RUN: %clang --target=x86_64-pc-freebsd -no-pie %s \
+// RUN:   --sysroot=%S/Inputs/multiarch_freebsd64_tree -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NORMAL-NOPIE %s
+// CHECK-NORMAL-NOPIE: crt1.o
+// CHECK-NORMAL-NOPIE: crtbegin.o
 
 // RUN: %clang -### %s --target=arm-unknown-freebsd10.0 -no-integrated-as 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-ARM %s
diff --git a/clang/test/Driver/hip-fpie-option.hip b/clang/test/Driver/hip-fpie-option.hip
index de2cd7fc343ed..4a6bbe65140a7 100644
--- a/clang/test/Driver/hip-fpie-option.hip
+++ b/clang/test/Driver/hip-fpie-option.hip
@@ -1,38 +1,78 @@
 // REQUIRES: default-pie
 
 // -fPIC and -fPIE only affects host relocation model.
-// device compilation always uses PIC. 
+// device compilation always uses PIC.
 
 // RUN: %clang -### --target=x86_64-unknown-linux-gnu \
 // RUN:   --offload-arch=gfx906 %s -nogpulib -nogpuinc \
-// RUN:   2>&1 | FileCheck -check-prefixes=DEV,HOST-PIE %s
+// RUN:   2>&1 | FileCheck -check-prefixes=DEV,HOST-PIE \
+// RUN:   -DHOST_TRIPLE=x86_64-unknown-linux-gnu %s
 
 // RUN: %clang -### --target=x86_64-unknown-linux-gnu \
 // RUN:   -fgpu-rdc --offload-arch=gfx906 %s -nogpulib -nogpuinc \
-// RUN:   2>&1 | FileCheck -check-prefixes=DEV,HOST-PIE %s
+// RUN:   2>&1 | FileCheck -check-prefixes=DEV,HOST-PIE \
+// RUN:   -DHOST_TRIPLE=x86_64-unknown-linux-gnu %s
 
 // RUN: %clang -### --target=x86_64-unknown-linux-gnu \
 // RUN:   --offload-arch=gfx906 %s -nogpulib -nogpuinc \
 // RUN:   -fPIC \
-// RUN:   2>&1 | FileCheck -check-prefixes=DEV,HOST-PIC %s
+// RUN:   2>&1 | FileCheck -check-prefixes=DEV,HOST-PIC \
+// RUN:   -DHOST_TRIPLE=x86_64-unknown-linux-gnu %s
 
 // RUN: %clang -### --target=x86_64-unknown-linux-gnu \
 // RUN:   -fgpu-rdc --offload-arch=gfx906 %s -nogpulib -nogpuinc \
 // RUN:   -fPIC \
-// RUN:   2>&1 | FileCheck -check-prefixes=DEV,HOST-PIC %s
+// RUN:   2>&1 | FileCheck -check-prefixes=DEV,HOST-PIC \
+// RUN:   -DHOST_TRIPLE=x86_64-unknown-linux-gnu %s
 
 // RUN: %clang -### --target=x86_64-unknown-linux-gnu \
 // RUN:   --offload-arch=gfx906 %s -nogpulib -nogpuinc \
 // RUN:   -fPIE \
-// RUN:   2>&1 | FileCheck -check-prefixes=DEV,HOST-PIE %s
+// RUN:   2>&1 | FileCheck -check-prefixes=DEV,HOST-PIE \
+// RUN:   -DHOST_TRIPLE=x86_64-unknown-linux-gnu %s
 
 // RUN: %clang -### --target=x86_64-unknown-linux-gnu \
 // RUN:   -fgpu-rdc --offload-arch=gfx906 %s -nogpulib -nogpuinc \
 // RUN:   -fPIE \
-// RUN:   2>&1 | FileCheck -check-prefixes=DEV,HOST-PIE %s
+// RUN:   2>&1 | FileCheck -check-prefixes=DEV,HOST-PIE \
+// RUN:   -DHOST_TRIPLE=x86_64-unknown-linux-gnu %s
+
+// RUN: %clang -### --target=x86_64-unknown-unknown-freebsd \
+// RUN:   --offload-arch=gfx906 %s -nogpulib -nogpuinc \
+// RUN:   2>&1 | FileCheck -check-prefixes=DEV,HOST-PIE \
+// RUN:   -DHOST_TRIPLE=x86_64-unknown-freebsd-unknown %s
+
+// RUN: %clang -### --target=x86_64-unknown-unknown-freebsd \
+// RUN:   -fgpu-rdc --offload-arch=gfx906 %s -nogpulib -nogpuinc \
+// RUN:   2>&1 | FileCheck -check-prefixes=DEV,HOST-PIE \
+// RUN:   -DHOST_TRIPLE=x86_64-unknown-freebsd-unknown %s
+
+// RUN: %clang -### --target=x86_64-unknown-unknown-freebsd \
+// RUN:   --offload-arch=gfx906 %s -nogpulib -nogpuinc \
+// RUN:   -fPIC \
+// RUN:   2>&1 | FileCheck -check-prefixes=DEV,HOST-PIC \
+// RUN:   -DHOST_TRIPLE=x86_64-unknown-freebsd-unknown %s
+
+// RUN: %clang -### --target=x86_64-unknown-unknown-freebsd \
+// RUN:   -fgpu-rdc --offload-arch=gfx906 %s -nogpulib -nogpuinc \
+// RUN:   -fPIC \
+// RUN:   2>&1 | FileCheck -check-prefixes=DEV,HOST-PIC \
+// RUN:   -DHOST_TRIPLE=x86_64-unknown-freebsd-unknown %s
+
+// RUN: %clang -### --target=x86_64-unknown-unknown-freebsd \
+// RUN:   --offload-arch=gfx906 %s -nogpulib -nogpuinc \
+// RUN:   -fPIE \
+// RUN:   2>&1 | FileCheck -check-prefixes=DEV,HOST-PIE \
+// RUN:   -DHOST_TRIPLE=x86_64-unknown-freebsd-unknown %s
+
+// RUN: %clang -### --target=x86_64-unknown-unknown-freebsd \
+// RUN:   -fgpu-rdc --offload-arch=gfx906 %s -nogpulib -nogpuinc \
+// RUN:   -fPIE \
+// RUN:   2>&1 | FileCheck -check-prefixes=DEV,HOST-PIE \
+// RUN:   -DHOST_TRIPLE=x86_64-unknown-freebsd-unknown %s
 
 // DEV-DAG: {{".*clang.*".* "-triple" "amdgcn-amd-amdhsa".* "-mrelocation-model" "pic" "-pic-level" "[1|2]".* "-mframe-pointer=all"}}
-// HOST-PIC-DAG: {{".*clang.*".* "-triple" "x86_64-unknown-linux-gnu".* "-mrelocation-model" "pic" "-pic-level" "2"}}
+// HOST-PIC-DAG: {{".*clang.*".* "-triple" "}}[[HOST_TRIPLE]]{{".* "-mrelocation-model" "pic" "-pic-level" "2"}}
 // HOST-PIC-NOT: "-pic-is-pie"
-// HOST-PIE-DAG: {{".*clang.*".* "-triple" "x86_64-unknown-linux-gnu".* "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie"}}
+// HOST-PIE-DAG: {{".*clang.*".* "-triple" "}}[[HOST_TRIPLE]]{{".* "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie"}}
 // DEV-NOT: {{".*clang.*".* "-triple" "amdgcn-amd-amdhsa".* "-pic-is-pie"}}

>From 6df6a330d42008e01824d78a512a967139836170 Mon Sep 17 00:00:00 2001
From: ShengYi Hung <aokblast at FreeBSD.org>
Date: Tue, 30 Jun 2026 20:28:07 -0500
Subject: [PATCH 2/3] fixup! [clang] Rename CLANG_DEFAULT_PIE_ON_LINUX to
 CLANG_DEFAULT_PIE

---
 flang/test/Driver/linker-options.f90 | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/flang/test/Driver/linker-options.f90 b/flang/test/Driver/linker-options.f90
index 5de7d8c23aacb..07f967b4bac5d 100644
--- a/flang/test/Driver/linker-options.f90
+++ b/flang/test/Driver/linker-options.f90
@@ -58,20 +58,20 @@
 ! RUN: %flang -target i386-pc-openbsd -pie -### %s 2>&1 \
 ! RUN:   | FileCheck %s --check-prefix=PIE
 !
-! On FreeBSD, pie is passed to the linker, but can be forced cancelled.
-! RUN: %flang -no-pie -target amd64-pc-freebsd -### %s 2>&1 \
+! On FreeBSD, -pie is not passed to the linker, but can be forced.
+! RUN: %flang -target amd64-pc-freebsd -### %s 2>&1 \
 ! RUN:   | FileCheck %s --check-prefix=NO-PIE
-! RUN: %flang -no-pie -target i386-pc-freebsd -### %s 2>&1 \
+! RUN: %flang -target i386-pc-freebsd -### %s 2>&1 \
 ! RUN:   | FileCheck %s --check-prefix=NO-PIE
-! RUN: %flang -no-pie -target aarch64-unknown-freebsd -### %s 2>&1 \
+! RUN: %flang -target aarch64-unknown-freebsd -### %s 2>&1 \
 ! RUN:   | FileCheck %s --check-prefix=NO-PIE
-! RUN: %flang -no-pie -target arm-unknown-freebsd -### %s 2>&1 \
+! RUN: %flang -target arm-unknown-freebsd -### %s 2>&1 \
 ! RUN:   | FileCheck %s --check-prefix=NO-PIE
-! RUN: %flang -no-pie -target powerpc-unknown-freebsd -### %s 2>&1 \
+! RUN: %flang -target powerpc-unknown-freebsd -### %s 2>&1 \
 ! RUN:   | FileCheck %s --check-prefix=NO-PIE
-! RUN: %flang -no-pie -target sparc64-unknown-freebsd -### %s 2>&1 \
+! RUN: %flang -target sparc64-unknown-freebsd -### %s 2>&1 \
 ! RUN:   | FileCheck %s --check-prefix=NO-PIE
-! RUN: %flang -no-pie -target i386-pc-freebsd -pie -### %s 2>&1 \
+! RUN: %flang -target i386-pc-freebsd -pie -### %s 2>&1 \
 ! RUN:   | FileCheck %s --check-prefix=PIE
 !
 ! On AIX, -pie is never passed to the linker.

>From a282899bb78fd21fabcc5b9cb5dd705c6ace96b4 Mon Sep 17 00:00:00 2001
From: ShengYi Hung <aokblast at FreeBSD.org>
Date: Tue, 30 Jun 2026 20:31:15 -0500
Subject: [PATCH 3/3] fixup! [Clang] Switch to Default PIE on FreeBSD

---
 flang/test/Driver/linker-options.f90 | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/flang/test/Driver/linker-options.f90 b/flang/test/Driver/linker-options.f90
index 07f967b4bac5d..5de7d8c23aacb 100644
--- a/flang/test/Driver/linker-options.f90
+++ b/flang/test/Driver/linker-options.f90
@@ -58,20 +58,20 @@
 ! RUN: %flang -target i386-pc-openbsd -pie -### %s 2>&1 \
 ! RUN:   | FileCheck %s --check-prefix=PIE
 !
-! On FreeBSD, -pie is not passed to the linker, but can be forced.
-! RUN: %flang -target amd64-pc-freebsd -### %s 2>&1 \
+! On FreeBSD, pie is passed to the linker, but can be forced cancelled.
+! RUN: %flang -no-pie -target amd64-pc-freebsd -### %s 2>&1 \
 ! RUN:   | FileCheck %s --check-prefix=NO-PIE
-! RUN: %flang -target i386-pc-freebsd -### %s 2>&1 \
+! RUN: %flang -no-pie -target i386-pc-freebsd -### %s 2>&1 \
 ! RUN:   | FileCheck %s --check-prefix=NO-PIE
-! RUN: %flang -target aarch64-unknown-freebsd -### %s 2>&1 \
+! RUN: %flang -no-pie -target aarch64-unknown-freebsd -### %s 2>&1 \
 ! RUN:   | FileCheck %s --check-prefix=NO-PIE
-! RUN: %flang -target arm-unknown-freebsd -### %s 2>&1 \
+! RUN: %flang -no-pie -target arm-unknown-freebsd -### %s 2>&1 \
 ! RUN:   | FileCheck %s --check-prefix=NO-PIE
-! RUN: %flang -target powerpc-unknown-freebsd -### %s 2>&1 \
+! RUN: %flang -no-pie -target powerpc-unknown-freebsd -### %s 2>&1 \
 ! RUN:   | FileCheck %s --check-prefix=NO-PIE
-! RUN: %flang -target sparc64-unknown-freebsd -### %s 2>&1 \
+! RUN: %flang -no-pie -target sparc64-unknown-freebsd -### %s 2>&1 \
 ! RUN:   | FileCheck %s --check-prefix=NO-PIE
-! RUN: %flang -target i386-pc-freebsd -pie -### %s 2>&1 \
+! RUN: %flang -no-pie -target i386-pc-freebsd -pie -### %s 2>&1 \
 ! RUN:   | FileCheck %s --check-prefix=PIE
 !
 ! On AIX, -pie is never passed to the linker.



More information about the llvm-branch-commits mailing list