mirror of
https://github.com/intel/llvm.git
synced 2026-01-25 19:44:38 +08:00
[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
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user