Author: Fangrui Song Date: 2024-08-15T16:28:42-07:00 New Revision: d156a5a1cb3b3405a6c1e941d112f262c29e15cf
URL: https://github.com/llvm/llvm-project/commit/d156a5a1cb3b3405a6c1e941d112f262c29e15cf DIFF: https://github.com/llvm/llvm-project/commit/d156a5a1cb3b3405a6c1e941d112f262c29e15cf.diff LOG: [Driver] Reject -Wa,-mrelax-relocations= for non-x86 Similar to other target-specific -Wa, options. Added: Modified: clang/lib/Driver/ToolChains/Clang.cpp clang/test/Driver/ohos.c clang/test/Driver/relax.c Removed: ################################################################################ diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 96aa930ea28612..c26ebd1ba56bab 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -2620,11 +2620,18 @@ static void CollectArgsForIntegratedAssembler(Compilation &C, Value == "-mbig-obj") continue; // LLVM handles bigobj automatically + auto Equal = Value.split('='); switch (C.getDefaultToolChain().getArch()) { default: break; case llvm::Triple::x86: case llvm::Triple::x86_64: + if (Equal.first == "-mrelax-relocations" || + Equal.first == "--mrelax-relocations") { + UseRelaxRelocations = Equal.second == "yes"; + if (llvm::is_contained({"yes", "no"}, Equal.second)) + continue; + } if (Value == "-msse2avx") { CmdArgs.push_back("-msse2avx"); continue; @@ -2641,10 +2648,10 @@ static void CollectArgsForIntegratedAssembler(Compilation &C, case llvm::Triple::thumbeb: case llvm::Triple::arm: case llvm::Triple::armeb: - if (Value.starts_with("-mimplicit-it=")) { + if (Equal.first == "-mimplicit-it") { // Only store the value; the last value set takes effect. - ImplicitIt = Value.split("=").second; - if (CheckARMImplicitITArg(ImplicitIt)) + ImplicitIt = Equal.second; + if (CheckARMImplicitITArg(Equal.second)) continue; } if (Value == "-mthumb") @@ -2719,12 +2726,6 @@ static void CollectArgsForIntegratedAssembler(Compilation &C, Crel = false; } else if (Value == "--allow-experimental-crel") { ExperimentalCrel = true; - } else if (Value == "-mrelax-relocations=yes" || - Value == "--mrelax-relocations=yes") { - UseRelaxRelocations = true; - } else if (Value == "-mrelax-relocations=no" || - Value == "--mrelax-relocations=no") { - UseRelaxRelocations = false; } else if (Value.starts_with("-I")) { CmdArgs.push_back(Value.data()); // We need to consume the next argument if the current arg is a plain diff --git a/clang/test/Driver/ohos.c b/clang/test/Driver/ohos.c index 8de4e6de57f7ff..af8218fb232e60 100644 --- a/clang/test/Driver/ohos.c +++ b/clang/test/Driver/ohos.c @@ -7,7 +7,6 @@ // RUN: --sysroot=%S/Inputs/ohos_native_tree/sysroot -fuse-ld=ld -march=armv7-a -mcpu=cortex-a7 -mfloat-abi=soft 2>&1 \ // RUN: | FileCheck -check-prefixes=CHECK,CHECK-ARM-A7-SOFT %s // CHECK: {{.*}}clang{{.*}}" "-cc1" -// CHECK-NOT: "--mrelax-relocations" // CHECK-NOT: "-munwind-tables" // CHECK: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]" // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]" diff --git a/clang/test/Driver/relax.c b/clang/test/Driver/relax.c index 48d22fede12d76..4771b9e3af1116 100644 --- a/clang/test/Driver/relax.c +++ b/clang/test/Driver/relax.c @@ -1,4 +1,10 @@ -// RUN: %clang -### -c -integrated-as -Wa,--mrelax-relocations=no %s 2>&1 | FileCheck %s +// RUN: %clang -### --target=x86_64 -c -Wa,--mrelax-relocations=no %s 2>&1 | FileCheck %s // CHECK: "-cc1" // CHECK: "-mrelax-relocations=no" + +// RUN: not %clang -### --target=x86_64 -c -Wa,-mrelax-relocations=x %s 2>&1 | FileCheck %s --check-prefix=ERR +// ERR: error: unsupported argument '-mrelax-relocations=x' to option '-Wa,' + +// RUN: not %clang -### --target=aarch64 -c -Wa,-mrelax-relocations=no %s 2>&1 | FileCheck %s --check-prefix=ERR2 +// ERR2: error: unsupported argument '-mrelax-relocations=no' to option '-Wa,' _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits