Driver: Don't warn on -mbranch-protection when linking
authorTom Stellard <tstellar@redhat.com>
Wed, 23 Mar 2022 06:17:39 +0000 (23:17 -0700)
committerTom Stellard <tstellar@redhat.com>
Wed, 23 Mar 2022 06:17:42 +0000 (23:17 -0700)
The -mbranch-protection definition in Options.td was not given a Group,
so this was causing clang to emit a -Wunused-command-line-argument
warning when this flag was passed to the linker driver.  This was a
problem, because some build systems, like cmake, automatically pass the
C flags to the linker.  Therefore, any program that was compiled with
-Werror and -mbranch-protection would fail to link with the error:

argument unused during compilation: '-mbranch-protection=standard' [-Werror,-Wunused-command-line-argument]

Reviewed By: vhscampos

Differential Revision: https://reviews.llvm.org/D121983

clang/include/clang/Driver/Options.td
clang/test/Driver/Inputs/main.c [new file with mode: 0644]
clang/test/Driver/aarch64-security-options.c

index 2a23695c149fa7031e1d861c403202e6099fcaff..e35b36af91c334c1044c5c98f0102bea08255b2f 100644 (file)
@@ -3442,6 +3442,7 @@ def msign_return_address_EQ : Joined<["-"], "msign-return-address=">,
   Flags<[CC1Option]>, Group<m_Group>, Values<"none,all,non-leaf">,
   HelpText<"Select return address signing scope">;
 def mbranch_protection_EQ : Joined<["-"], "mbranch-protection=">,
+  Group<m_Group>,
   HelpText<"Enforce targets of indirect branches and function returns">;
 
 def mharden_sls_EQ : Joined<["-"], "mharden-sls=">,
diff --git a/clang/test/Driver/Inputs/main.c b/clang/test/Driver/Inputs/main.c
new file mode 100644 (file)
index 0000000..5c2fa9b
--- /dev/null
@@ -0,0 +1,3 @@
+int main(int argc, char **argv) {
+  return 0;
+}
index 6ea4b8ae5838522229a14d0898887ac127258708..e9db540d53edec58eca97d9bd3003b2be1412c05 100644 (file)
 // RUN: %clang -target aarch64--none-eabi -c %s -### -mbranch-protection=bar     2>&1 | \
 // RUN: FileCheck %s --check-prefix=BAD-BP-PROTECTION --check-prefix=WARN
 
+// RUN: %clang -target aarch64--none-eabi -o %t-main.o -mbranch-protection=standard -c %S/Inputs/main.c
+// RUN: %clang -target aarch64--none-eabi -o %t-main -mbranch-protection=standard %t-main.o 2>&1 | \
+// RUN: FileCheck --allow-empty %s --check-prefix=LINKER-DRIVER
+
 // WARN-NOT: warning: ignoring '-mbranch-protection=' option because the 'aarch64' architecture does not support it [-Wbranch-protection]
 
 // RA-OFF: "-msign-return-address=none"
@@ -46,3 +50,7 @@
 
 // BAD-B-KEY-COMBINATION: invalid branch protection option 'b-key' in '-mbranch-protection={{.*}}'
 // BAD-LEAF-COMBINATION: invalid branch protection option 'leaf' in '-mbranch-protection={{.*}}'
+
+// Check that the linker driver doesn't warn about -mbranch-protection=standard
+// as an unused option.
+// LINKER-DRIVER-NOT: warning: