[PATCH] D114677: [AArch64] Avoid crashing on invalid -Wa,-march= values

Dimitry Andric via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 28 10:13:36 PST 2021


dim created this revision.
dim added reviewers: jcai19, ostannard, DavidSpickett, nickdesaulniers.
Herald added subscribers: kristof.beyls, krytarowski, arichardson.
dim requested review of this revision.
Herald added a project: clang.

As reported in https://bugs.freebsd.org/260078, the gnutls Makefiles
pass -Wa,-march=all to compile a number of assembly files. Clang does
not support this -march value, but because of a mistake in handling
the arguments, an unitialized Arg pointer is dereferenced, which can
cause a segfault.

Work around this by adding a check if the local WaMArch variable is
initialized, and if so, using its value in the diagnostic message.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114677

Files:
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  clang/test/Driver/aarch64-target-as-march.s


Index: clang/test/Driver/aarch64-target-as-march.s
===================================================================
--- clang/test/Driver/aarch64-target-as-march.s
+++ clang/test/Driver/aarch64-target-as-march.s
@@ -44,3 +44,12 @@
 // TARGET-FEATURE-3-NOT: "-target-feature" "+v8.4a"
 // TARGET-FEATURE-4: "-target-feature" "+v8.4a"
 // TARGET-FEATURE-4-NOT: "-target-feature" "+v8.3a"
+
+// Invalid -march settings
+// RUN: %clang --target=aarch64-linux-gnueabi -### -c -Wa,-march=all %s 2>&1 | \
+// RUN: FileCheck --check-prefix=INVALID-ARCH-1 %s
+// RUN: %clang --target=aarch64-linux-gnueabi -### -c -Wa,-march=foobar %s 2>&1 | \
+// RUN: FileCheck --check-prefix=INVALID-ARCH-2 %s
+
+// INVALID-ARCH-1: error: the clang compiler does not support '-march=all'
+// INVALID-ARCH-2: error: the clang compiler does not support '-march=foobar'
Index: clang/lib/Driver/ToolChains/Arch/AArch64.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -260,7 +260,8 @@
         D, getAArch64TargetCPU(Args, Triple, A), Args, Features);
 
   if (!success)
-    D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args);
+    D.Diag(diag::err_drv_clang_unsupported)
+        << (WaMArch.size() ? "-march=" + WaMArch.str() : A->getAsString(Args));
 
   if (Args.getLastArg(options::OPT_mgeneral_regs_only)) {
     Features.push_back("-fp-armv8");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114677.390214.patch
Type: text/x-patch
Size: 1466 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211128/239f09b5/attachment.bin>


More information about the cfe-commits mailing list