From 40eaa9968dd747a232055b6a9fb60f674ad64f8f Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Wed, 18 Jan 2017 03:34:38 +0000 Subject: [PATCH] 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 --- lld/ELF/Writer.cpp | 4 ++++ lld/test/ELF/map-file.s | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index d93468fef34f..acfba4e09217 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -237,7 +237,11 @@ template void Writer::run() { if (ErrorCount) return; + // Handle -Map option. writeMapFile(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 ccf6d12f6d51..b7a4aef2f290 100644 --- a/lld/test/ELF/map-file.s +++ b/lld/test/ELF/map-file.s @@ -54,3 +54,7 @@ local: // 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 /