Skip to content

Commit 98fd3b3

Browse files
committed
Driver: Don't warn on -mbranch-protection when linking
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
1 parent 5143366 commit 98fd3b3

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3442,6 +3442,7 @@ def msign_return_address_EQ : Joined<["-"], "msign-return-address=">,
34423442
Flags<[CC1Option]>, Group<m_Group>, Values<"none,all,non-leaf">,
34433443
HelpText<"Select return address signing scope">;
34443444
def mbranch_protection_EQ : Joined<["-"], "mbranch-protection=">,
3445+
Group<m_Group>,
34453446
HelpText<"Enforce targets of indirect branches and function returns">;
34463447

34473448
def mharden_sls_EQ : Joined<["-"], "mharden-sls=">,

clang/test/Driver/Inputs/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
int main(int argc, char **argv) {
2+
return 0;
3+
}

clang/test/Driver/aarch64-security-options.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
// RUN: %clang -target aarch64--none-eabi -c %s -### -mbranch-protection=bar 2>&1 | \
2828
// RUN: FileCheck %s --check-prefix=BAD-BP-PROTECTION --check-prefix=WARN
2929

30+
// RUN: %clang -target aarch64--none-eabi -o %t-main.o -mbranch-protection=standard -c %S/Inputs/main.c
31+
// RUN: %clang -target aarch64--none-eabi -o %t-main -mbranch-protection=standard %t-main.o 2>&1 | \
32+
// RUN: FileCheck --allow-empty %s --check-prefix=LINKER-DRIVER
33+
3034
// WARN-NOT: warning: ignoring '-mbranch-protection=' option because the 'aarch64' architecture does not support it [-Wbranch-protection]
3135

3236
// RA-OFF: "-msign-return-address=none"
@@ -46,3 +50,7 @@
4650

4751
// BAD-B-KEY-COMBINATION: invalid branch protection option 'b-key' in '-mbranch-protection={{.*}}'
4852
// BAD-LEAF-COMBINATION: invalid branch protection option 'leaf' in '-mbranch-protection={{.*}}'
53+
54+
// Check that the linker driver doesn't warn about -mbranch-protection=standard
55+
// as an unused option.
56+
// LINKER-DRIVER-NOT: warning:

0 commit comments

Comments
 (0)