Skip to content

Commit 264d3b6

Browse files
committed
[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
1 parent 0cf624c commit 264d3b6

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

lld/MachO/Driver.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -659,10 +659,12 @@ static PlatformKind parsePlatformVersion(const ArgList &args) {
659659
// Has the side-effect of setting Config::target.
660660
static TargetInfo *createTargetInfo(InputArgList &args) {
661661
StringRef archName = args.getLastArgValue(OPT_arch);
662-
if (archName.empty())
663-
fatal("must specify -arch");
664-
PlatformKind platform = parsePlatformVersion(args);
662+
if (archName.empty()) {
663+
error("must specify -arch");
664+
return nullptr;
665+
}
665666

667+
PlatformKind platform = parsePlatformVersion(args);
666668
config->platformInfo.target =
667669
MachO::Target(getArchitectureFromName(archName), platform);
668670

@@ -680,7 +682,8 @@ static TargetInfo *createTargetInfo(InputArgList &args) {
680682
case CPU_TYPE_ARM:
681683
return createARMTargetInfo(cpuSubtype);
682684
default:
683-
fatal("missing or unsupported -arch " + archName);
685+
error("missing or unsupported -arch " + archName);
686+
return nullptr;
684687
}
685688
}
686689

@@ -1118,6 +1121,8 @@ bool macho::link(ArrayRef<const char *> argsArr, bool canExitEarly,
11181121
target = createTargetInfo(args);
11191122
depTracker =
11201123
make<DependencyTracker>(args.getLastArgValue(OPT_dependency_info));
1124+
if (errorCount())
1125+
return false;
11211126

11221127
config->osoPrefix = args.getLastArgValue(OPT_oso_prefix);
11231128
if (!config->osoPrefix.empty()) {

lld/test/MachO/color-diagnostics.test

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
# Windows command prompt doesn't support ANSI escape sequences.
22
# REQUIRES: shell
33

4-
# RUN: not %lld -xyz --color-diagnostics /nosuchfile 2>&1 \
4+
# RUN: not %lld --color-diagnostics /nosuchfile 2>&1 \
55
# RUN: | FileCheck -check-prefix=COLOR %s
6-
# RUN: not %lld -xyz --color-diagnostics=always /nosuchfile 2>&1 \
6+
# RUN: not %lld --color-diagnostics=always /nosuchfile 2>&1 \
77
# RUN: | FileCheck -check-prefix=COLOR %s
88

9-
# COLOR: {{lld: .\[0;31merror: .\[0munknown argument '-xyz'}}
109
# COLOR: {{lld: .\[0;31merror: .\[0mcannot open /nosuchfile}}
1110

1211
# RUN: not %lld --color-diagnostics=foobar 2>&1 | FileCheck -check-prefix=ERR %s

lld/test/MachO/driver.test

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ VERSION: LLD
33

44
# RUN: not %lld ---help 2>&1 | FileCheck -check-prefix=SPELLHELP %s
55
SPELLHELP: error: unknown argument '---help', did you mean '--help'
6-
# FIXME: This should say "no input files" instead
7-
SPELLHELP: error: undefined symbol: _main
6+
# FIXME: We should also output a "no input files" error

lld/test/MachO/search-paths-darwin.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ REQUIRES: system-darwin
33

44
RUN: mkdir -p %t1 %t2
55

6-
RUN: not ld64.lld -arch x86_64 -v -L%t1 -F%t2 2>&1 | FileCheck -DLDIR=%t1 -DFDIR=%t2 %s
6+
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
77
CHECK: Library search paths:
88
CHECK-NEXT: [[LDIR]]
99
CHECK-NEXT: /usr/lib
@@ -12,7 +12,7 @@ CHECK-NEXT: [[FDIR]]
1212
CHECK-NEXT: /Library/Frameworks
1313
CHECK-NEXT: /System/Library/Frameworks
1414

15-
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
15+
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
1616
CHECK_Z: Library search paths:
1717
CHECK_Z-NEXT: [[LDIR]]
1818
CHECK_Z-NEXT: Framework search paths:

0 commit comments

Comments
 (0)