[PATCH] D113082: [lld-macho] Implement -arch_errors_fatal
Keith Smiley via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 3 11:52:24 PDT 2021
keith updated this revision to Diff 384548.
keith marked 3 inline comments as done.
keith added a comment.
Improve test, deduplicate string
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D113082/new/
https://reviews.llvm.org/D113082
Files:
lld/MachO/Config.h
lld/MachO/Driver.cpp
lld/MachO/InputFiles.cpp
lld/MachO/Options.td
lld/test/MachO/invalid/incompatible-arch.s
Index: lld/test/MachO/invalid/incompatible-arch.s
===================================================================
--- lld/test/MachO/invalid/incompatible-arch.s
+++ 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:
Index: lld/MachO/Options.td
===================================================================
--- lld/MachO/Options.td
+++ lld/MachO/Options.td
@@ -862,7 +862,6 @@
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>">,
Index: lld/MachO/InputFiles.cpp
===================================================================
--- lld/MachO/InputFiles.cpp
+++ 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;
}
Index: lld/MachO/Driver.cpp
===================================================================
--- lld/MachO/Driver.cpp
+++ 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");
Index: lld/MachO/Config.h
===================================================================
--- lld/MachO/Config.h
+++ 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 =
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113082.384548.patch
Type: text/x-patch
Size: 4560 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211103/8a38c822/attachment.bin>
More information about the llvm-commits
mailing list