Author: Fangrui Song
Date: 2025-01-23T11:59:57-05:00
New Revision: 2f76e2b27d9ddd4fa0a1098f77b96fa51905bdb1

URL: 
https://github.com/llvm/llvm-project/commit/2f76e2b27d9ddd4fa0a1098f77b96fa51905bdb1
DIFF: 
https://github.com/llvm/llvm-project/commit/2f76e2b27d9ddd4fa0a1098f77b96fa51905bdb1.diff

LOG: [Driver] -fno-plt: warn for unsupported targets

-fno-plt is an ELF specific option that is only implemented for x86 (for
a long time) and AArch64 (#78890). GCC doesn't bother to give a
diagnostic on Windows. -fno-plt is somewhat popular and we've been
ignoring it for unsupported targets for a while, so just report a
warning for unsupported targets.

Pull Request: https://github.com/llvm/llvm-project/pull/124081

Added: 
    clang/test/Driver/fno-plt.c

Modified: 
    clang/lib/Driver/ToolChains/Clang.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 33f08cf28feca1..518113e20cb063 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() && (Triple.isAArch64() || Triple.isX86()))
+    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..c7bd7130593be0
--- /dev/null
+++ b/clang/test/Driver/fno-plt.c
@@ -0,0 +1,10 @@
+// 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]
+// NOPLT: "-fno-plt"
+// DEFAULT-NOT: "-fno-plt"


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to