diff options
| author | Reid Kleckner <rnk@google.com> | 2019-07-10 00:34:13 +0000 | 
|---|---|---|
| committer | Reid Kleckner <rnk@google.com> | 2019-07-10 00:34:13 +0000 | 
| commit | cc418a3af45adbe740f868a31bde6155083f0b9d (patch) | |
| tree | d0b24abef24564f0f5a81d17df58ec768b2de356 /llvm/lib/LTO | |
| parent | 9c147bd40bc93376df274e8a5d51c69a55199044 (diff) | |
| download | bcm5719-llvm-cc418a3af45adbe740f868a31bde6155083f0b9d.tar.gz bcm5719-llvm-cc418a3af45adbe740f868a31bde6155083f0b9d.zip  | |
[Support] Move llvm::MemoryBuffer to sys::fs::file_t
Summary:
On Windows, Posix integer file descriptors are a compatibility layer
over native file handles provided by the C runtime. There is a hard
limit on the maximum number of file descriptors that a process can open,
and the limit is 8192. LLD typically doesn't run into this limit because
it opens input files, maps them into memory, and then immediately closes
the file descriptor. This prevents it from running out of FDs.
For various reasons, I'd like to open handles to every input file and
keep them open during linking. That requires migrating MemoryBuffer over
to taking open native file handles instead of integer FDs.
Reviewers: aganea, Bigcheese
Reviewed By: aganea
Subscribers: smeenai, silvas, mehdi_amini, hiraditya, steven_wu, dexonsmith, dang, llvm-commits, zturner
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D63453
llvm-svn: 365588
Diffstat (limited to 'llvm/lib/LTO')
| -rw-r--r-- | llvm/lib/LTO/Caching.cpp | 9 | ||||
| -rw-r--r-- | llvm/lib/LTO/LTOModule.cpp | 3 | ||||
| -rw-r--r-- | llvm/lib/LTO/ThinLTOCodeGenerator.cpp | 7 | 
3 files changed, 10 insertions, 9 deletions
diff --git a/llvm/lib/LTO/Caching.cpp b/llvm/lib/LTO/Caching.cpp index 9971a28aed4..7b3fc020d6e 100644 --- a/llvm/lib/LTO/Caching.cpp +++ b/llvm/lib/LTO/Caching.cpp @@ -44,7 +44,8 @@ Expected<NativeObjectCache> lto::localCache(StringRef CacheDirectoryPath,          Twine(EntryPath), FD, sys::fs::OF_UpdateAtime, &ResultPath);      if (!EC) {        ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr = -          MemoryBuffer::getOpenFile(FD, EntryPath, +          MemoryBuffer::getOpenFile(sys::fs::convertFDToNativeFile(FD), +                                    EntryPath,                                      /*FileSize*/ -1,                                      /*RequiresNullTerminator*/ false);        close(FD); @@ -86,9 +87,9 @@ Expected<NativeObjectCache> lto::localCache(StringRef CacheDirectoryPath,          // Open the file first to avoid racing with a cache pruner.          ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr = -            MemoryBuffer::getOpenFile(TempFile.FD, TempFile.TmpName, -                                      /*FileSize*/ -1, -                                      /*RequiresNullTerminator*/ false); +            MemoryBuffer::getOpenFile( +                sys::fs::convertFDToNativeFile(TempFile.FD), TempFile.TmpName, +                /*FileSize=*/-1, /*RequiresNullTerminator=*/false);          if (!MBOrErr)            report_fatal_error(Twine("Failed to open new cache file ") +                               TempFile.TmpName + ": " + diff --git a/llvm/lib/LTO/LTOModule.cpp b/llvm/lib/LTO/LTOModule.cpp index a27c78d2595..7ffe7bf84ba 100644 --- a/llvm/lib/LTO/LTOModule.cpp +++ b/llvm/lib/LTO/LTOModule.cpp @@ -130,7 +130,8 @@ LTOModule::createFromOpenFileSlice(LLVMContext &Context, int fd, StringRef path,                                     size_t map_size, off_t offset,                                     const TargetOptions &options) {    ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr = -      MemoryBuffer::getOpenFileSlice(fd, path, map_size, offset); +      MemoryBuffer::getOpenFileSlice(sys::fs::convertFDToNativeFile(fd), path, +                                     map_size, offset);    if (std::error_code EC = BufferOrErr.getError()) {      Context.emitError(EC.message());      return EC; diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp index b5dbab0ca8f..5c447a14b06 100644 --- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp +++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp @@ -355,10 +355,9 @@ public:          Twine(EntryPath), FD, sys::fs::OF_UpdateAtime, &ResultPath);      if (EC)        return EC; -    ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr = -        MemoryBuffer::getOpenFile(FD, EntryPath, -                                  /*FileSize*/ -1, -                                  /*RequiresNullTerminator*/ false); +    ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr = MemoryBuffer::getOpenFile( +        sys::fs::convertFDToNativeFile(FD), EntryPath, +        /*FileSize=*/-1, /*RequiresNullTerminator=*/false);      close(FD);      return MBOrErr;    }  | 

