Skip to content

Commit f861e33

Browse files
committed
[Driver] Reject -Wa,-mrelax-relocations= for non-ELF
1 parent 217f580 commit f861e33

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2582,6 +2582,7 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
25822582
bool TakeNextArg = false;
25832583

25842584
const llvm::Triple &Triple = C.getDefaultToolChain().getTriple();
2585+
bool IsELF = Triple.isOSBinFormatELF();
25852586
bool Crel = false, ExperimentalCrel = false;
25862587
bool UseRelaxRelocations = C.getDefaultToolChain().useRelaxRelocations();
25872588
bool UseNoExecStack = false;
@@ -2621,10 +2622,16 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
26212622
continue; // LLVM handles bigobj automatically
26222623

26232624
auto Equal = Value.split('=');
2624-
auto checkArg = [&](std::initializer_list<const char *> Set) {
2625-
if (!llvm::is_contained(Set, Equal.second))
2625+
auto checkArg = [&](bool ValidTarget,
2626+
std::initializer_list<const char *> Set) {
2627+
if (!ValidTarget) {
2628+
D.Diag(diag::err_drv_unsupported_opt_for_target)
2629+
<< (Twine("-Wa,") + Equal.first + "=").str()
2630+
<< Triple.getTriple();
2631+
} else if (!llvm::is_contained(Set, Equal.second)) {
26262632
D.Diag(diag::err_drv_unsupported_option_argument)
26272633
<< (Twine("-Wa,") + Equal.first + "=").str() << Equal.second;
2634+
}
26282635
};
26292636
switch (C.getDefaultToolChain().getArch()) {
26302637
default:
@@ -2634,7 +2641,7 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
26342641
if (Equal.first == "-mrelax-relocations" ||
26352642
Equal.first == "--mrelax-relocations") {
26362643
UseRelaxRelocations = Equal.second == "yes";
2637-
checkArg({"yes", "no"});
2644+
checkArg(IsELF, {"yes", "no"});
26382645
continue;
26392646
}
26402647
if (Value == "-msse2avx") {
@@ -2656,7 +2663,7 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
26562663
if (Equal.first == "-mimplicit-it") {
26572664
// Only store the value; the last value set takes effect.
26582665
ImplicitIt = Equal.second;
2659-
checkArg({"always", "never", "arm", "thumb"});
2666+
checkArg(true, {"always", "never", "arm", "thumb"});
26602667
continue;
26612668
}
26622669
if (Value == "-mthumb")

clang/test/Driver/relax.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@
88

99
// RUN: not %clang -### --target=aarch64 -c -Wa,-mrelax-relocations=no %s 2>&1 | FileCheck %s --check-prefix=ERR2
1010
// ERR2: error: unsupported argument '-mrelax-relocations=no' to option '-Wa,'
11+
12+
// RUN: not %clang -### --target=x86_64-apple-darwin -c -Wa,-mrelax-relocations=no %s 2>&1 | FileCheck %s --check-prefix=ERR3
13+
// ERR3: error: unsupported option '-Wa,-mrelax-relocations=' for target 'x86_64-apple-darwin'

0 commit comments

Comments
 (0)