[lld] 264d3b6 - [MachO] Use error instead of fatal for missing -arch
Shoaib Meenai via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 31 16:32:01 PDT 2021
Author: Shoaib Meenai
Date: 2021-10-31T16:31:21-07:00
New Revision: 264d3b6d4e08401c5b50a85bd76e80b3461d77e6
URL: https://github.com/llvm/llvm-project/commit/264d3b6d4e08401c5b50a85bd76e80b3461d77e6
DIFF: https://github.com/llvm/llvm-project/commit/264d3b6d4e08401c5b50a85bd76e80b3461d77e6.diff
LOG: [MachO] Use error instead of fatal for missing -arch
`fatal` should only be used for malformed inputs according to
ErrorHandler.h; `error` is more appropriate for missing arguments,
accompanied by a check to bail out early in case of the error. Some
tests need to be adjusted accordingly.
Makes `lld/test/MachO/arch.s` pass with `LLD_IN_TEST=2`.
Reviewed By: #lld-macho, int3
Differential Revision: https://reviews.llvm.org/D112879
Added:
Modified:
lld/MachO/Driver.cpp
lld/test/MachO/color-diagnostics.test
lld/test/MachO/driver.test
lld/test/MachO/search-paths-darwin.test
Removed:
################################################################################
diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index a06b5682d722d..528e78055728d 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -659,10 +659,12 @@ static PlatformKind parsePlatformVersion(const ArgList &args) {
// Has the side-effect of setting Config::target.
static TargetInfo *createTargetInfo(InputArgList &args) {
StringRef archName = args.getLastArgValue(OPT_arch);
- if (archName.empty())
- fatal("must specify -arch");
- PlatformKind platform = parsePlatformVersion(args);
+ if (archName.empty()) {
+ error("must specify -arch");
+ return nullptr;
+ }
+ PlatformKind platform = parsePlatformVersion(args);
config->platformInfo.target =
MachO::Target(getArchitectureFromName(archName), platform);
@@ -680,7 +682,8 @@ static TargetInfo *createTargetInfo(InputArgList &args) {
case CPU_TYPE_ARM:
return createARMTargetInfo(cpuSubtype);
default:
- fatal("missing or unsupported -arch " + archName);
+ error("missing or unsupported -arch " + archName);
+ return nullptr;
}
}
@@ -1118,6 +1121,8 @@ bool macho::link(ArrayRef<const char *> argsArr, bool canExitEarly,
target = createTargetInfo(args);
depTracker =
make<DependencyTracker>(args.getLastArgValue(OPT_dependency_info));
+ if (errorCount())
+ return false;
config->osoPrefix = args.getLastArgValue(OPT_oso_prefix);
if (!config->osoPrefix.empty()) {
diff --git a/lld/test/MachO/color-diagnostics.test b/lld/test/MachO/color-diagnostics.test
index b3c496f3b32d0..b079c82e1a43a 100644
--- a/lld/test/MachO/color-diagnostics.test
+++ b/lld/test/MachO/color-diagnostics.test
@@ -1,12 +1,11 @@
# Windows command prompt doesn't support ANSI escape sequences.
# REQUIRES: shell
-# RUN: not %lld -xyz --color-diagnostics /nosuchfile 2>&1 \
+# RUN: not %lld --color-diagnostics /nosuchfile 2>&1 \
# RUN: | FileCheck -check-prefix=COLOR %s
-# RUN: not %lld -xyz --color-diagnostics=always /nosuchfile 2>&1 \
+# RUN: not %lld --color-diagnostics=always /nosuchfile 2>&1 \
# RUN: | FileCheck -check-prefix=COLOR %s
-# COLOR: {{lld: .\[0;31merror: .\[0munknown argument '-xyz'}}
# COLOR: {{lld: .\[0;31merror: .\[0mcannot open /nosuchfile}}
# RUN: not %lld --color-diagnostics=foobar 2>&1 | FileCheck -check-prefix=ERR %s
diff --git a/lld/test/MachO/driver.test b/lld/test/MachO/driver.test
index 5a0ccac01c316..206fab3ef6a3d 100644
--- a/lld/test/MachO/driver.test
+++ b/lld/test/MachO/driver.test
@@ -3,5 +3,4 @@ VERSION: LLD
# RUN: not %lld ---help 2>&1 | FileCheck -check-prefix=SPELLHELP %s
SPELLHELP: error: unknown argument '---help', did you mean '--help'
-# FIXME: This should say "no input files" instead
-SPELLHELP: error: undefined symbol: _main
+# FIXME: We should also output a "no input files" error
diff --git a/lld/test/MachO/search-paths-darwin.test b/lld/test/MachO/search-paths-darwin.test
index eb2a27d1dcf62..42767a3e5ea5c 100644
--- a/lld/test/MachO/search-paths-darwin.test
+++ b/lld/test/MachO/search-paths-darwin.test
@@ -3,7 +3,7 @@ REQUIRES: system-darwin
RUN: mkdir -p %t1 %t2
-RUN: not ld64.lld -arch x86_64 -v -L%t1 -F%t2 2>&1 | FileCheck -DLDIR=%t1 -DFDIR=%t2 %s
+RUN: not ld64.lld -arch x86_64 -platform_version macos 10.5 11.0 -v -L%t1 -F%t2 2>&1 | FileCheck -DLDIR=%t1 -DFDIR=%t2 %s
CHECK: Library search paths:
CHECK-NEXT: [[LDIR]]
CHECK-NEXT: /usr/lib
@@ -12,7 +12,7 @@ CHECK-NEXT: [[FDIR]]
CHECK-NEXT: /Library/Frameworks
CHECK-NEXT: /System/Library/Frameworks
-RUN: not ld64.lld -arch x86_64 -v -L%t1 -F%t2 -Z 2>&1 | FileCheck -DLDIR=%t1 -DFDIR=%t2 --check-prefix=CHECK_Z %s
+RUN: not ld64.lld -arch x86_64 -platform_version macos 10.5 11.0 -v -L%t1 -F%t2 -Z 2>&1 | FileCheck -DLDIR=%t1 -DFDIR=%t2 --check-prefix=CHECK_Z %s
CHECK_Z: Library search paths:
CHECK_Z-NEXT: [[LDIR]]
CHECK_Z-NEXT: Framework search paths:
More information about the llvm-commits
mailing list