[PATCH] D58840: ELF: Change FileSize back to a uint64_t.
Peter Collingbourne via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 1 10:41:48 PST 2019
pcc created this revision.
pcc added a reviewer: ruiu.
Herald added subscribers: MaskRay, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a reviewer: serge-sans-paille.
Herald added a project: LLVM.
This lets us detect file size overflows when creating a 64-bit binary on
a 32-bit machine.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D58840
Files:
lld/ELF/Writer.cpp
lld/test/ELF/linkerscript/output-too-large-32bit.s
lld/test/lit.cfg.py
lld/test/lit.site.cfg.py.in
llvm/utils/gn/secondary/lld/test/BUILD.gn
Index: llvm/utils/gn/secondary/lld/test/BUILD.gn
===================================================================
--- llvm/utils/gn/secondary/lld/test/BUILD.gn
+++ llvm/utils/gn/secondary/lld/test/BUILD.gn
@@ -53,6 +53,12 @@
} else {
extra_values += [ "HAVE_LIBZ=0" ] # Must be 0.
}
+
+ if (current_cpu == "x64" || current_cpu == "arm64") {
+ extra_values += [ "CMAKE_SIZEOF_VOID_P=8" ]
+ } else {
+ extra_values += [ "CMAKE_SIZEOF_VOID_P=4" ]
+ }
}
write_lit_cfg("lit_unit_site_cfg") {
Index: lld/test/lit.site.cfg.py.in
===================================================================
--- lld/test/lit.site.cfg.py.in
+++ lld/test/lit.site.cfg.py.in
@@ -15,6 +15,7 @@
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.
Index: lld/test/lit.cfg.py
===================================================================
--- lld/test/lit.cfg.py
+++ lld/test/lit.cfg.py
@@ -97,6 +97,9 @@
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(
Index: lld/test/ELF/linkerscript/output-too-large-32bit.s
===================================================================
--- /dev/null
+++ lld/test/ELF/linkerscript/output-too-large-32bit.s
@@ -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
Index: lld/ELF/Writer.cpp
===================================================================
--- lld/ELF/Writer.cpp
+++ lld/ELF/Writer.cpp
@@ -82,7 +82,7 @@
std::vector<PhdrEntry *> Phdrs;
- size_t FileSize;
+ uint64_t FileSize;
uint64_t SectionHeaderOff;
};
} // anonymous namespace
@@ -2480,7 +2480,7 @@
// 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 @@
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>();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58840.188943.patch
Type: text/x-patch
Size: 2938 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190301/650a547c/attachment.bin>
More information about the llvm-commits
mailing list