summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBob Haarman <llvm@inglorion.net>2018-04-24 23:16:39 +0000
committerBob Haarman <llvm@inglorion.net>2018-04-24 23:16:39 +0000
commit8832f8899680298297b591b1a02957429fda1a6a (patch)
treea39a443761759c5dbf556343cc5e6d901c1eb322
parentffa650a183b9a5d8208623ac602cb7aa0881792f (diff)
downloadbcm5719-llvm-8832f8899680298297b591b1a02957429fda1a6a.tar.gz
bcm5719-llvm-8832f8899680298297b591b1a02957429fda1a6a.zip
[COFF] create MemoryBuffers without requiring NUL terminators
Summary: In a number of places in the COFF linker, we were calling MemoryBuffer::getFile() with default parameters. This causes LLVM to NUL-terminate the buffers, which can prevent them from being memory mapped. Since we operate on binary and do not use NUL as an indicator of the end of the file content, this change causes us to not require the NUL terminator anymore. Reviewers: ruiu, pcc Reviewed By: ruiu Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D45909 llvm-svn: 330786
-rw-r--r--lld/COFF/Driver.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 73905580044..aa41084d56d 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -105,7 +105,9 @@ static std::future<MBErrPair> createFutureForFile(std::string Path) {
auto Strategy = std::launch::deferred;
#endif
return std::async(Strategy, [=]() {
- auto MBOrErr = MemoryBuffer::getFile(Path);
+ auto MBOrErr = MemoryBuffer::getFile(Path,
+ /*FileSize*/ -1,
+ /*RequiresNullTerminator*/ false);
if (!MBOrErr)
return MBErrPair{nullptr, MBOrErr.getError()};
return MBErrPair{std::move(*MBOrErr), std::error_code()};
@@ -563,7 +565,8 @@ static void createImportLibrary(bool AsLib) {
// If the import library already exists, replace it only if the contents
// have changed.
- ErrorOr<std::unique_ptr<MemoryBuffer>> OldBuf = MemoryBuffer::getFile(Path);
+ ErrorOr<std::unique_ptr<MemoryBuffer>> OldBuf = MemoryBuffer::getFile(
+ Path, /*FileSize*/ -1, /*RequiresNullTerminator*/ false);
if (!OldBuf) {
HandleError(writeImportLibrary(LibName, Path, Exports, Config->Machine,
false, Config->MinGW));
@@ -582,7 +585,8 @@ static void createImportLibrary(bool AsLib) {
return;
}
- std::unique_ptr<MemoryBuffer> NewBuf = check(MemoryBuffer::getFile(TmpName));
+ std::unique_ptr<MemoryBuffer> NewBuf = check(MemoryBuffer::getFile(
+ TmpName, /*FileSize*/ -1, /*RequiresNullTerminator*/ false));
if ((*OldBuf)->getBuffer() != NewBuf->getBuffer()) {
OldBuf->reset();
HandleError(errorCodeToError(sys::fs::rename(TmpName, Path)));
OpenPOWER on IntegriCloud