[clang] [Driver] -fno-plt: warn for unsupported targets (PR #124081)
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 23 08:59:49 PST 2025
https://github.com/MaskRay updated https://github.com/llvm/llvm-project/pull/124081
>From a38b6aecebba895f11c967cc83f9e98bda359ffe Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Wed, 22 Jan 2025 23:03:41 -0800
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
=?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.5-bogner
---
clang/lib/Driver/ToolChains/Clang.cpp | 5 ++---
clang/test/Driver/fno-plt.c | 7 +++++++
2 files changed, 9 insertions(+), 3 deletions(-)
create mode 100644 clang/test/Driver/fno-plt.c
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 33f08cf28feca1..5df58005a52373 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6141,9 +6141,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-fno-direct-access-external-data");
}
- if (Args.hasFlag(options::OPT_fno_plt, options::OPT_fplt, false)) {
- CmdArgs.push_back("-fno-plt");
- }
+ if (Triple.isOSBinFormatELF())
+ Args.addOptOutFlag(CmdArgs, options::OPT_fplt, options::OPT_fno_plt);
// -fhosted is default.
// TODO: Audit uses of KernelOrKext and see where it'd be more appropriate to
diff --git a/clang/test/Driver/fno-plt.c b/clang/test/Driver/fno-plt.c
new file mode 100644
index 00000000000000..d5189e2b508b2a
--- /dev/null
+++ b/clang/test/Driver/fno-plt.c
@@ -0,0 +1,7 @@
+// RUN: %clang -### -c --target=aarch64 -fno-plt -Werror %s 2>&1 | FileCheck %s
+// RUN: %clang -### -c --target=aarch64 -fno-plt -fplt -Werror %s 2>&1 | FileCheck %s --check-prefix=NO
+// RUN: %clang -### -c --target=aarch64-windows -fno-plt %s 2>&1 | FileCheck %s --check-prefixes=WARN,NO
+
+// WARN: warning: argument unused during compilation: '-fno-plt' [-Wunused-command-line-argument]
+// CHECK: "-fno-plt"
+// NO-NOT: "-fno-plt"
>From e0b459cf8fa0b2cec966f506d579a7dd658ec744 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Thu, 23 Jan 2025 08:59:30 -0800
Subject: [PATCH 2/2] update test
Created using spr 1.3.5-bogner
---
clang/test/Driver/fno-plt.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/clang/test/Driver/fno-plt.c b/clang/test/Driver/fno-plt.c
index 3b928246059827..c7bd7130593be0 100644
--- a/clang/test/Driver/fno-plt.c
+++ b/clang/test/Driver/fno-plt.c
@@ -1,9 +1,10 @@
-// RUN: %clang -### -c --target=aarch64 -fno-plt -Werror %s 2>&1 | FileCheck %s
-// RUN: %clang -### -c --target=x86_64 -fno-plt -Werror %s 2>&1 | FileCheck %s
-// RUN: %clang -### -c --target=aarch64 -fno-plt -fplt -Werror %s 2>&1 | FileCheck %s --check-prefix=NO
-// RUN: %clang -### -c --target=powerpc64 -fno-plt %s 2>&1 | FileCheck %s --check-prefixes=WARN,NO
-// RUN: %clang -### -c --target=aarch64-windows -fno-plt %s 2>&1 | FileCheck %s --check-prefixes=WARN,NO
+// RUN: %clang -### -c --target=aarch64 -fno-plt -Werror %s 2>&1 | FileCheck %s --check-prefix=NOPLT
+// RUN: %clang -### -c --target=x86_64 -fno-plt -Werror %s 2>&1 | FileCheck %s --check-prefix=NOPLT
+
+// RUN: %clang -### -c --target=aarch64 -fno-plt -fplt -Werror %s 2>&1 | FileCheck %s --check-prefix=DEFAULT
+// RUN: %clang -### -c --target=powerpc64 -fno-plt %s 2>&1 | FileCheck %s --check-prefixes=WARN,DEFAULT
+// RUN: %clang -### -c --target=aarch64-windows -fno-plt %s 2>&1 | FileCheck %s --check-prefixes=WARN,DEFAULT
// WARN: warning: argument unused during compilation: '-fno-plt' [-Wunused-command-line-argument]
-// CHECK: "-fno-plt"
-// NO-NOT: "-fno-plt"
+// NOPLT: "-fno-plt"
+// DEFAULT-NOT: "-fno-plt"
More information about the cfe-commits
mailing list