[llvm-branch-commits] [lld] 8e0b179 - [ELF] report section sizes when output file too large
Bob Haarman via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Jan 21 11:52:07 PST 2021
Author: Bob Haarman
Date: 2021-01-21T19:47:03Z
New Revision: 8e0b17931530e84f45586e31b58b031d6d68ee6c
URL: https://github.com/llvm/llvm-project/commit/8e0b17931530e84f45586e31b58b031d6d68ee6c
DIFF: https://github.com/llvm/llvm-project/commit/8e0b17931530e84f45586e31b58b031d6d68ee6c.diff
LOG: [ELF] report section sizes when output file too large
Fixes PR48523. When the linker errors with "output file too large",
one question that comes to mind is how the section sizes differ from
what they were previously. Unfortunately, this information is lost
when the linker exits without writing the output file. This change
makes it so that the error message includes the sizes of the largest
sections.
Reviewed By: MaskRay, grimar, jhenderson
Differential Revision: https://reviews.llvm.org/D94560
Added:
Modified:
lld/ELF/Writer.cpp
lld/test/ELF/linkerscript/output-too-large.s
Removed:
################################################################################
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 0397dae8f891..f550e6a73335 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -2872,7 +2872,13 @@ template <class ELFT> void Writer<ELFT>::writeHeader() {
template <class ELFT> void Writer<ELFT>::openFile() {
uint64_t maxSize = config->is64 ? INT64_MAX : UINT32_MAX;
if (fileSize != size_t(fileSize) || maxSize < fileSize) {
- error("output file too large: " + Twine(fileSize) + " bytes");
+ std::string msg;
+ raw_string_ostream s(msg);
+ s << "output file too large: " << Twine(fileSize) << " bytes\n"
+ << "section sizes:\n";
+ for (OutputSection *os : outputSections)
+ s << os->name << ' ' << os->size << "\n";
+ error(s.str());
return;
}
diff --git a/lld/test/ELF/linkerscript/output-too-large.s b/lld/test/ELF/linkerscript/output-too-large.s
index d916a2e556bc..c496d99d3cef 100644
--- a/lld/test/ELF/linkerscript/output-too-large.s
+++ b/lld/test/ELF/linkerscript/output-too-large.s
@@ -21,14 +21,26 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t2.o
# RUN: echo "SECTIONS { .text : { . = 0x8fffffffffffffff; *(.text*); } }" > %t2.script
# RUN: not ld.lld -T %t2.script -M %t2.o -o /dev/null 2>&1 | \
-# RUN: FileCheck --check-prefixes=MAP2,CHECK %s
+# RUN: FileCheck --check-prefixes=MAP2,CHECK64 %s
# MAP2: VMA LMA Size Align Out In Symbol
# MAP2: 9000000000000000 9000000000000000 1 4 {{.*}}.o:(.text)
# MAP2-NEXT: 9000000000000000 9000000000000000 0 1 _start
# CHECK: error: output file too large
+# CHECK-NEXT: section sizes:
+# CHECK-NEXT: .text 4294967297
+# CHECK-NEXT: .data 1
+# CHECK64: error: output file too large
+# CHECK64-NEXT: section sizes:
+# CHECK64-NEXT: .text 10376293541461622785
+# CHECK64-NEXT: .data 1
+
+.data
+.byte 42
+
+.text
.global _start
_start:
nop
More information about the llvm-branch-commits
mailing list