Skip to content

Commit d156a5a

Browse files
committed
[Driver] Reject -Wa,-mrelax-relocations= for non-x86
Similar to other target-specific -Wa, options.
1 parent 6dcfc84 commit d156a5a

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2620,11 +2620,18 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
26202620
Value == "-mbig-obj")
26212621
continue; // LLVM handles bigobj automatically
26222622

2623+
auto Equal = Value.split('=');
26232624
switch (C.getDefaultToolChain().getArch()) {
26242625
default:
26252626
break;
26262627
case llvm::Triple::x86:
26272628
case llvm::Triple::x86_64:
2629+
if (Equal.first == "-mrelax-relocations" ||
2630+
Equal.first == "--mrelax-relocations") {
2631+
UseRelaxRelocations = Equal.second == "yes";
2632+
if (llvm::is_contained({"yes", "no"}, Equal.second))
2633+
continue;
2634+
}
26282635
if (Value == "-msse2avx") {
26292636
CmdArgs.push_back("-msse2avx");
26302637
continue;
@@ -2641,10 +2648,10 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
26412648
case llvm::Triple::thumbeb:
26422649
case llvm::Triple::arm:
26432650
case llvm::Triple::armeb:
2644-
if (Value.starts_with("-mimplicit-it=")) {
2651+
if (Equal.first == "-mimplicit-it") {
26452652
// Only store the value; the last value set takes effect.
2646-
ImplicitIt = Value.split("=").second;
2647-
if (CheckARMImplicitITArg(ImplicitIt))
2653+
ImplicitIt = Equal.second;
2654+
if (CheckARMImplicitITArg(Equal.second))
26482655
continue;
26492656
}
26502657
if (Value == "-mthumb")
@@ -2719,12 +2726,6 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
27192726
Crel = false;
27202727
} else if (Value == "--allow-experimental-crel") {
27212728
ExperimentalCrel = true;
2722-
} else if (Value == "-mrelax-relocations=yes" ||
2723-
Value == "--mrelax-relocations=yes") {
2724-
UseRelaxRelocations = true;
2725-
} else if (Value == "-mrelax-relocations=no" ||
2726-
Value == "--mrelax-relocations=no") {
2727-
UseRelaxRelocations = false;
27282729
} else if (Value.starts_with("-I")) {
27292730
CmdArgs.push_back(Value.data());
27302731
// We need to consume the next argument if the current arg is a plain

clang/test/Driver/ohos.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// RUN: --sysroot=%S/Inputs/ohos_native_tree/sysroot -fuse-ld=ld -march=armv7-a -mcpu=cortex-a7 -mfloat-abi=soft 2>&1 \
88
// RUN: | FileCheck -check-prefixes=CHECK,CHECK-ARM-A7-SOFT %s
99
// CHECK: {{.*}}clang{{.*}}" "-cc1"
10-
// CHECK-NOT: "--mrelax-relocations"
1110
// CHECK-NOT: "-munwind-tables"
1211
// CHECK: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
1312
// CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"

clang/test/Driver/relax.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
// RUN: %clang -### -c -integrated-as -Wa,--mrelax-relocations=no %s 2>&1 | FileCheck %s
1+
// RUN: %clang -### --target=x86_64 -c -Wa,--mrelax-relocations=no %s 2>&1 | FileCheck %s
22

33
// CHECK: "-cc1"
44
// CHECK: "-mrelax-relocations=no"
5+
6+
// RUN: not %clang -### --target=x86_64 -c -Wa,-mrelax-relocations=x %s 2>&1 | FileCheck %s --check-prefix=ERR
7+
// ERR: error: unsupported argument '-mrelax-relocations=x' to option '-Wa,'
8+
9+
// RUN: not %clang -### --target=aarch64 -c -Wa,-mrelax-relocations=no %s 2>&1 | FileCheck %s --check-prefix=ERR2
10+
// ERR2: error: unsupported argument '-mrelax-relocations=no' to option '-Wa,'

0 commit comments

Comments
 (0)