[lld] 6629ec3 - [lld-macho] Implement -arch_errors_fatal
Keith Smiley via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 3 22:02:19 PDT 2021
Author: Keith Smiley
Date: 2021-11-03T22:01:53-07:00
New Revision: 6629ec3ecc16ec6e62944085317934ccbc8ff645
URL: https://github.com/llvm/llvm-project/commit/6629ec3ecc16ec6e62944085317934ccbc8ff645
DIFF: https://github.com/llvm/llvm-project/commit/6629ec3ecc16ec6e62944085317934ccbc8ff645.diff
LOG: [lld-macho] Implement -arch_errors_fatal
By default with ld64, architecture mismatches are just warnings, then
this flag can be passed to make these fail. This matches that behavior.
Reviewed By: int3, #lld-macho
Differential Revision: https://reviews.llvm.org/D113082
Added:
Modified:
lld/MachO/Config.h
lld/MachO/Driver.cpp
lld/MachO/InputFiles.cpp
lld/MachO/Options.td
lld/test/MachO/invalid/incompatible-arch.s
Removed:
################################################################################
diff --git a/lld/MachO/Config.h b/lld/MachO/Config.h
index 698839895ba61..090eb7a28cf9a 100644
--- a/lld/MachO/Config.h
+++ b/lld/MachO/Config.h
@@ -148,6 +148,7 @@ struct Configuration {
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
index adfe7166eb59d..d811ba28197a2 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -1226,6 +1226,7 @@ bool macho::link(ArrayRef<const char *> argsArr, bool canExitEarly,
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
index d406920620f6f..d5dacf5a3a7ec 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -789,9 +789,12 @@ template <class LP> void ObjFile::parse() {
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 msg = config->errorForArchMismatch
+ ? static_cast<void (*)(const Twine &)>(error)
+ : warn;
+ msg(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
index 004fb369066b4..8067a69f0dfda 100644
--- a/lld/MachO/Options.td
+++ b/lld/MachO/Options.td
@@ -862,7 +862,6 @@ def no_arch_warnings : Flag<["-"], "no_arch_warnings">,
Group<grp_rare>;
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<grp_rare>;
def e : Separate<["-"], "e">,
MetaVarName<"<symbol>">,
diff --git a/lld/test/MachO/invalid/incompatible-arch.s b/lld/test/MachO/invalid/incompatible-arch.s
index 4984c178ec7bc..27fc1c83d04be 100644
--- 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
diff erent from target platform watchOS Simulator
-
.globl _main
_main:
More information about the llvm-commits
mailing list