[lld] r348153 - Show a proper error message if output file is too large.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 3 09:42:57 PST 2018
Author: ruiu
Date: Mon Dec 3 09:42:57 2018
New Revision: 348153
URL: http://llvm.org/viewvc/llvm-project?rev=348153&view=rev
Log:
Show a proper error message if output file is too large.
At least on Linux, if a file size given to FileOutputBuffer is greater
than 2^63, it fails with "Invalid argument" error, which is not a
user-friendly error message. With this patch, lld prints out "output
file too large" instead.
Modified:
lld/trunk/ELF/Writer.cpp
lld/trunk/test/ELF/linkerscript/output-too-large.s
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=348153&r1=348152&r2=348153&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Mon Dec 3 09:42:57 2018
@@ -2402,7 +2402,8 @@ template <class ELFT> void Writer<ELFT>:
// Open a result file.
template <class ELFT> void Writer<ELFT>::openFile() {
- if (!Config->Is64 && FileSize > UINT32_MAX) {
+ uint64_t MaxSize = Config->Is64 ? INT64_MAX : UINT32_MAX;
+ if (MaxSize < FileSize) {
error("output file too large: " + Twine(FileSize) + " bytes");
return;
}
Modified: lld/trunk/test/ELF/linkerscript/output-too-large.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/output-too-large.s?rev=348153&r1=348152&r2=348153&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/output-too-large.s (original)
+++ lld/trunk/test/ELF/linkerscript/output-too-large.s Mon Dec 3 09:42:57 2018
@@ -1,7 +1,13 @@
# REQUIRES: x86
+
# RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %s -o %t.o
# RUN: echo "SECTIONS { .text : { . = 0xffffffff; *(.text*); } }" > %t.script
# RUN: not ld.lld --no-check-sections --script %t.script %t.o -o /dev/null 2>&1 | FileCheck %s
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: echo "SECTIONS { .text : { . = 0x8fffffffffffffff; *(.text*); } }" > %t.script
+# RUN: not ld.lld --no-check-sections --script %t.script %t.o -o /dev/null 2>&1 | FileCheck %s
+
# CHECK: error: output file too large
.global _start
More information about the llvm-commits
mailing list