[clang] 89d71c1 - [Driver] Reject AIX-specific link options on non-AIX targets
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Fri May 26 15:30:29 PDT 2023
Author: Fangrui Song
Date: 2023-05-26T15:30:23-07:00
New Revision: 89d71c1efa85656b54bcd79b4278bc67690480e1
URL: https://github.com/llvm/llvm-project/commit/89d71c1efa85656b54bcd79b4278bc67690480e1
DIFF: https://github.com/llvm/llvm-project/commit/89d71c1efa85656b54bcd79b4278bc67690480e1.diff
LOG: [Driver] Reject AIX-specific link options on non-AIX targets
Follow-up to D106688 and D146431.
-b leads to a -Wunused-command-line-argument warning instead of an error
without linking phase.
-mxcoff-build-id= leads to a -Wunused-command-line-argument warning instead of
an error.
Added:
clang/test/Driver/aix-link-options-on-non-aix.c
Modified:
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/Xlinker-args.c
Removed:
clang/test/Driver/unsupported-target-K.c
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index e1adff4e0751c..2fd07b3864a38 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6370,10 +6370,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
}
}
- if (Arg *A = Args.getLastArgNoClaim(options::OPT_K);
- A && !TC.getTriple().isOSAIX())
- D.Diag(diag::err_drv_unsupported_opt_for_target)
- << A->getAsString(Args) << TripleStr;
+ // Reject AIX-specific link options on other targets.
+ if (!TC.getTriple().isOSAIX()) {
+ for (const Arg *A : Args.filtered(options::OPT_b, options::OPT_K,
+ options::OPT_mxcoff_build_id_EQ)) {
+ D.Diag(diag::err_drv_unsupported_opt_for_target)
+ << A->getSpelling() << TripleStr;
+ }
+ }
if (Args.getLastArg(options::OPT_fapple_kext) ||
(Args.hasArg(options::OPT_mkernel) && types::isCXX(InputType)))
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 4a11be78f37f4..8854d13da98f3 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -303,15 +303,6 @@ void tools::AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs,
// Pass -z prefix for gcc linker compatibility.
A.claim();
A.render(Args, CmdArgs);
- } else if (A.getOption().matches(options::OPT_b)) {
- const llvm::Triple &T = TC.getTriple();
- if (!T.isOSAIX()) {
- TC.getDriver().Diag(diag::err_drv_unsupported_opt_for_target)
- << A.getSpelling() << T.str();
- }
- // Pass -b prefix for AIX linker.
- A.claim();
- A.render(Args, CmdArgs);
} else {
A.renderAsInput(Args, CmdArgs);
}
diff --git a/clang/test/Driver/Xlinker-args.c b/clang/test/Driver/Xlinker-args.c
index ad59e0beee22b..b2a913e7cef62 100644
--- a/clang/test/Driver/Xlinker-args.c
+++ b/clang/test/Driver/Xlinker-args.c
@@ -21,16 +21,11 @@
// RUN: -b one -b two %s 2> %t
// RUN: FileCheck -check-prefix=AIX < %t %s
-// RUN: %clang -target powerpc-unknown-linux -### \
-// RUN: -b one %s 2> %t
-// RUN: FileCheck -check-prefix=NOT-AIX < %t %s
-
// DARWIN-NOT: --no-demangle
// DARWIN: "one" "two" "three" "four" "-z" "five" "-r"
// LINUX: "--no-demangle" "-e" "_start" "one" "two" "three" "four" "-z" "five" "-r" {{.*}} "-T" "a.lds"
// MINGW: "--no-demangle"
// AIX: "-b" "one" "-b" "two"
-// NOT-AIX: error: unsupported option '-b' for target 'powerpc-unknown-linux'
// Check that we forward '-Xlinker' and '-Wl,' on Windows.
// RUN: %clang -target i686-pc-win32 -fuse-ld=link -### \
diff --git a/clang/test/Driver/aix-link-options-on-non-aix.c b/clang/test/Driver/aix-link-options-on-non-aix.c
new file mode 100644
index 0000000000000..d44137a8c5d64
--- /dev/null
+++ b/clang/test/Driver/aix-link-options-on-non-aix.c
@@ -0,0 +1,10 @@
+/// AIX-specific link options are rejected for other targets.
+// RUN: %clang -### --target=powerpc64-unknown-linux-gnu \
+// RUN: --sysroot %S/Inputs/aix_ppc_tree --unwindlib=libunwind --rtlib=compiler-rt \
+// RUN: -b one -K -mxcoff-build-id=a %s 2>&1 | FileCheck %s --implicit-check-not=error:
+// RUN: %clang -### --target=powerpc64-unknown-linux-gnu -c \
+// RUN: --sysroot %S/Inputs/aix_ppc_tree --unwindlib=libunwind --rtlib=compiler-rt \
+// RUN: -b one -K -mxcoff-build-id=a %s 2>&1 | FileCheck %s --implicit-check-not=error:
+// CHECK: error: unsupported option '-b' for target '{{.*}}'
+// CHECK: error: unsupported option '-K' for target '{{.*}}'
+// CHECK: error: unsupported option '-mxcoff-build-id=' for target '{{.*}}'
diff --git a/clang/test/Driver/unsupported-target-K.c b/clang/test/Driver/unsupported-target-K.c
deleted file mode 100644
index 8b9a6f529c326..0000000000000
--- a/clang/test/Driver/unsupported-target-K.c
+++ /dev/null
@@ -1,8 +0,0 @@
-// Check powerpc64-unknown-linux-gnu. -K not supported.
-// RUN: %clang %s 2>&1 -### \
-// RUN: --target=powerpc64-unknown-linux-gnu \
-// RUN: --sysroot %S/Inputs/aix_ppc_tree \
-// RUN: --unwindlib=libunwind \
-// RUN: -K \
-// RUN: | FileCheck --check-prefixes=CHECK-K-SUPPORT %s
-// CHECK-K-SUPPORT: clang: error: unsupported option '-K' for target 'powerpc64-unknown-linux-gnu'
More information about the cfe-commits
mailing list