diff --git a/lld/MachO/Config.h b/lld/MachO/Config.h --- a/lld/MachO/Config.h +++ b/lld/MachO/Config.h @@ -148,6 +148,7 @@ bool deadStripDylibs = false; bool demangle = false; bool deadStrip = false; + bool errorForArchMismatch = false; PlatformInfo platformInfo; NamespaceKind namespaceKind = NamespaceKind::twolevel; UndefinedSymbolTreatment undefinedSymbolTreatment = diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -1226,6 +1226,7 @@ config->printWhyLoad = args.hasArg(OPT_why_load); config->omitDebugInfo = args.hasArg(OPT_S); config->outputType = getOutputType(args); + config->errorForArchMismatch = args.hasArg(OPT_arch_errors_fatal); if (const Arg *arg = args.getLastArg(OPT_bundle_loader)) { if (config->outputType != MH_BUNDLE) error("-bundle_loader can only be used with MachO bundle output"); diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -789,9 +789,18 @@ Architecture arch = getArchitectureFromCpuType(hdr->cputype, hdr->cpusubtype); if (arch != config->arch()) { - error(toString(this) + " has architecture " + getArchitectureName(arch) + - " which is incompatible with target architecture " + - getArchitectureName(config->arch())); + auto post = [&](bool fail, const Twine &message) -> void { + if (fail) + error(message); + else + warn(message); + }; + + post(config->errorForArchMismatch, + toString(this) + " has architecture " + getArchitectureName(arch) + + " which is incompatible with target architecture " + + getArchitectureName(config->arch())); + return; } diff --git a/lld/MachO/Options.td b/lld/MachO/Options.td --- a/lld/MachO/Options.td +++ b/lld/MachO/Options.td @@ -862,7 +862,6 @@ Group; def arch_errors_fatal : Flag<["-"], "arch_errors_fatal">, HelpText<"Escalate to errors any warnings about inputs whose architecture does not match the -arch option">, - Flags<[HelpHidden]>, Group; def e : Separate<["-"], "e">, MetaVarName<"">, diff --git a/lld/test/MachO/invalid/incompatible-arch.s b/lld/test/MachO/invalid/incompatible-arch.s --- a/lld/test/MachO/invalid/incompatible-arch.s +++ b/lld/test/MachO/invalid/incompatible-arch.s @@ -3,8 +3,12 @@ # RUN: rm -rf %t && mkdir -p %t # RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin %s -o %t/test.o -# RUN: not %lld -arch x86_64 -lSystem %t/test.o -o /dev/null 2>&1 | FileCheck %s -DFILE=%t/test.o -# CHECK: error: {{.*}}[[FILE]] has architecture arm64 which is incompatible with target architecture x86_64 +# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/native.o +# RUN: not %no_fatal_warnings_lld -arch x86_64 -lSystem %t/test.o -o /dev/null -arch_errors_fatal 2>&1 | FileCheck %s -DFILE=%t/test.o --check-prefix=CHECK-ERROR +# RUN: %no_fatal_warnings_lld -arch x86_64 -lSystem %t/test.o %t/native.o -o /dev/null 2>&1 | FileCheck %s -DFILE=%t/test.o --check-prefix=CHECK-WARNING +# RUN: %lld -arch arm64 -lSystem %t/test.o -arch_errors_fatal -o /dev/null +# CHECK-ERROR: error: {{.*}}[[FILE]] has architecture arm64 which is incompatible with target architecture x86_64 +# CHECK-WARNING: warning: {{.*}}[[FILE]] has architecture arm64 which is incompatible with target architecture x86_64 # RUN: %lld -dylib -arch arm64 -platform_version macOS 10.14 10.15 -o %t/out.dylib %t/test.o @@ -30,7 +34,7 @@ # RUN: -o /dev/null 2>&1 | FileCheck %s --check-prefix=OBJ-VERSION # OBJ-VERSION: warning: {{.*}}test_x86.o has version 10.15.0, which is newer than target minimum of 10.14.0 -## Test that simulators platforms are compat with their simulatees. +## Test that simulators platforms are compat with their simulatees. # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-ios14.0 %s -o %t/test_x86_ios.o # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-ios14.0-simulator %s -o %t/test_x86_ios_sim.o @@ -43,7 +47,6 @@ # RUN: not %lld -dylib -platform_version watchos-simulator 14.0.0 14.0.0 %t/test_x86_ios_sim.o \ # RUN: -o /dev/null 2>&1 | FileCheck %s --check-prefix=CROSS-SIM2 # CROSS-SIM2: {{.*}}test_x86_ios_sim.o has platform iOS Simulator, which is different from target platform watchOS Simulator - .globl _main _main: