Return early if writeMapFile failed.

This patch adds a test for an invalid output path for -Map option,
though that test is not for verifying that we are using error()
instead of fatal() in writeMapFile.

llvm-svn: 292336
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index d93468f..acfba4e 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -237,7 +237,11 @@
   if (ErrorCount)
     return;
 
+  // Handle -Map option.
   writeMapFile<ELFT>(OutputSections);
+  if (ErrorCount)
+    return;
+
   if (auto EC = Buffer->commit())
     error("failed to write to the output file: " + EC.message());
 
diff --git a/lld/test/ELF/map-file.s b/lld/test/ELF/map-file.s
index ccf6d12..b7a4aef2 100644
--- a/lld/test/ELF/map-file.s
+++ b/lld/test/ELF/map-file.s
@@ -54,3 +54,7 @@
 // CHECK-NEXT: 0000000000000000 0000000000000039     1         .shstrtab
 // CHECK-NEXT: 0000000000000000 000000000000002f     1 .strtab
 // CHECK-NEXT: 0000000000000000 000000000000002f     1         .strtab
+
+// RUN: not ld.lld %t1.o %t2.o %t3.o %t4.a -o %t -Map=/ 2>&1 \
+// RUN:  | FileCheck -check-prefix=FAIL %s
+// FAIL: cannot open /