Skip to content

Commit 2f76e2b

Browse files
authored
[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: #124081
1 parent d8cd8d5 commit 2f76e2b

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -6141,9 +6141,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
61416141
CmdArgs.push_back("-fno-direct-access-external-data");
61426142
}
61436143

6144-
if (Args.hasFlag(options::OPT_fno_plt, options::OPT_fplt, false)) {
6145-
CmdArgs.push_back("-fno-plt");
6146-
}
6144+
if (Triple.isOSBinFormatELF() && (Triple.isAArch64() || Triple.isX86()))
6145+
Args.addOptOutFlag(CmdArgs, options::OPT_fplt, options::OPT_fno_plt);
61476146

61486147
// -fhosted is default.
61496148
// TODO: Audit uses of KernelOrKext and see where it'd be more appropriate to

clang/test/Driver/fno-plt.c

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %clang -### -c --target=aarch64 -fno-plt -Werror %s 2>&1 | FileCheck %s --check-prefix=NOPLT
2+
// RUN: %clang -### -c --target=x86_64 -fno-plt -Werror %s 2>&1 | FileCheck %s --check-prefix=NOPLT
3+
4+
// RUN: %clang -### -c --target=aarch64 -fno-plt -fplt -Werror %s 2>&1 | FileCheck %s --check-prefix=DEFAULT
5+
// RUN: %clang -### -c --target=powerpc64 -fno-plt %s 2>&1 | FileCheck %s --check-prefixes=WARN,DEFAULT
6+
// RUN: %clang -### -c --target=aarch64-windows -fno-plt %s 2>&1 | FileCheck %s --check-prefixes=WARN,DEFAULT
7+
8+
// WARN: warning: argument unused during compilation: '-fno-plt' [-Wunused-command-line-argument]
9+
// NOPLT: "-fno-plt"
10+
// DEFAULT-NOT: "-fno-plt"

0 commit comments

Comments
 (0)