[lld] r355218 - ELF: Change FileSize back to a uint64_t.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 1 10:53:41 PST 2019
Author: pcc
Date: Fri Mar 1 10:53:41 2019
New Revision: 355218
URL: http://llvm.org/viewvc/llvm-project?rev=355218&view=rev
Log:
ELF: Change FileSize back to a uint64_t.
This lets us detect file size overflows when creating a 64-bit binary on
a 32-bit machine.
Differential Revision: https://reviews.llvm.org/D58840
Added:
lld/trunk/test/ELF/linkerscript/output-too-large-32bit.s
Modified:
lld/trunk/ELF/Writer.cpp
lld/trunk/test/lit.cfg.py
lld/trunk/test/lit.site.cfg.py.in
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=355218&r1=355217&r2=355218&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Fri Mar 1 10:53:41 2019
@@ -82,7 +82,7 @@ private:
std::vector<PhdrEntry *> Phdrs;
- size_t FileSize;
+ uint64_t FileSize;
uint64_t SectionHeaderOff;
};
} // anonymous namespace
@@ -2480,7 +2480,7 @@ template <class ELFT> void Writer<ELFT>:
// Open a result file.
template <class ELFT> void Writer<ELFT>::openFile() {
uint64_t MaxSize = Config->Is64 ? INT64_MAX : UINT32_MAX;
- if (MaxSize < FileSize) {
+ if (FileSize != size_t(FileSize) || MaxSize < FileSize) {
error("output file too large: " + Twine(FileSize) + " bytes");
return;
}
@@ -2561,7 +2561,7 @@ template <class ELFT> void Writer<ELFT>:
return;
// Compute a hash of all sections of the output file.
- In.BuildId->writeBuildId({Out::BufferStart, FileSize});
+ In.BuildId->writeBuildId({Out::BufferStart, size_t(FileSize)});
}
template void elf::writeResult<ELF32LE>();
Added: lld/trunk/test/ELF/linkerscript/output-too-large-32bit.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/output-too-large-32bit.s?rev=355218&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/output-too-large-32bit.s (added)
+++ lld/trunk/test/ELF/linkerscript/output-too-large-32bit.s Fri Mar 1 10:53:41 2019
@@ -0,0 +1,11 @@
+# REQUIRES: x86 && !llvm-64-bits
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: echo "SECTIONS { .text : { . = 0x6fffffffffffffff; *(.text*); } }" > %t.script
+# RUN: not ld.lld --no-check-sections --script %t.script %t.o -o /dev/null 2>&1 | FileCheck %s
+
+# CHECK: output file too large
+
+.global _start
+_start:
+ nop
Modified: lld/trunk/test/lit.cfg.py
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/lit.cfg.py?rev=355218&r1=355217&r2=355218&view=diff
==============================================================================
--- lld/trunk/test/lit.cfg.py (original)
+++ lld/trunk/test/lit.cfg.py Fri Mar 1 10:53:41 2019
@@ -97,6 +97,9 @@ if config.llvm_libxml2_enabled:
if config.have_dia_sdk:
config.available_features.add("diasdk")
+if config.sizeof_void_p == 8:
+ config.available_features.add("llvm-64-bits")
+
tar_executable = lit.util.which('tar', config.environment['PATH'])
if tar_executable:
tar_version = subprocess.Popen(
Modified: lld/trunk/test/lit.site.cfg.py.in
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/lit.site.cfg.py.in?rev=355218&r1=355217&r2=355218&view=diff
==============================================================================
--- lld/trunk/test/lit.site.cfg.py.in (original)
+++ lld/trunk/test/lit.site.cfg.py.in Fri Mar 1 10:53:41 2019
@@ -15,6 +15,7 @@ config.lld_tools_dir = "@LLVM_RUNTIME_OU
config.target_triple = "@TARGET_TRIPLE@"
config.python_executable = "@PYTHON_EXECUTABLE@"
config.have_zlib = @HAVE_LIBZ@
+config.sizeof_void_p = @CMAKE_SIZEOF_VOID_P@
# Support substitution of the tools and libs dirs with user parameters. This is
# used when we can't determine the tool dir at configuration time.
More information about the llvm-commits
mailing list