aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/MemoryBuffer.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-08-13Work around documented Linux mmap bug. (#152595)Richard Smith1-2/+8
On Linux, mmap doesn't always zero-fill slack bytes ([man page]), despite being required to do so by POSIX. If the final page of a file is in the page cache and the bytes past the end of the file get overwritten by some process, those bytes then remain non-zero until the page falls out of the cache or another process overwrites them. Stop trusting that mmap behaves properly and instead check whether the buffer was indeed properly terminated. If not, fall back to using `read` to read the file contents. This fixes an obscure clang crash bug that can occur if another program (such as an editor) mmap's a source file and writes past the end of the mmap'd region shortly before clang or clangd attempts to parse the file. [man page]: https://man7.org/linux/man-pages/man2/mmap.2.html#BUGS
2025-06-11[SystemZ][z/OS] Refactor AutoConvert.h to remove large MVS guard (#143174)Abhina Sree1-6/+4
This AutoConvert.h header frequently gets mislabeled as an unused include because it is guarded by MVS internally and every usage is also guarded. This refactors the change to remove this guard and instead make these functions a noop on other non-z/OS platforms.
2024-12-11[SystemZ][z/OS] Update autoconversion functions to improve support for UTF-8 ↵Abhina Sree1-2/+14
(#98652) This fixes the following error when reading source and header files on z/OS: error: source file is not valid UTF-8
2024-11-20[Support] Remove unused includes (NFC) (#116752)Kazu Hirata1-1/+0
Identified with misc-include-cleaner.
2024-09-05[NFC][SystemZ][z/OS] Rename autoconversion-related functions to be less ↵Abhina Sree1-1/+1
generic (#107399) This patch renames the functions in AutoConvert.h/cpp to have a less generic name because they are z/OS specific.
2024-05-15Correct mismatched allocation/deallocation callsAaron Ballman1-3/+11
This amends dceaa0f4491ebe30c0b0f1bc7fa5ec365b60ced6 because ASAN caught an issue where the allocation and deallocation were not properly paired: https://lab.llvm.org/buildbot/#/builders/239/builds/7001 Use malloc and free throughout this file to ensure that all kinds of memory buffers use the proper pairing.
2024-05-15[Support] Use malloc instead of non-throwing new (#92157)Aaron Ballman1-2/+9
When allocating a memory buffer, we use a non-throwing new so that we can explicitly handle memory buffers that are too large to fit into memory. However, when exceptions are disabled, LLVM installs a custom new handler (https://github.com/llvm/llvm-project/blob/90109d444839683b09f0aafdc50b749cb4b3203b/llvm/lib/Support/InitLLVM.cpp#L61) that explicitly crashes when we run out of memory (https://github.com/llvm/llvm-project/blob/de14b749fee41d4ded711e771e43043ae3100cb3/llvm/lib/Support/ErrorHandling.cpp#L188) and that means this particular out-of-memory situation cannot be gracefully handled. This was discovered while working on #embed (https://github.com/llvm/llvm-project/pull/68620) on Windows and resulted in a crash rather than the preprocessor issuing a diagnostic as expected. This patch switches away from the non-throwing new to a call to malloc (and free), which will return a null pointer without calling a custom new handler. It is the only instance in Clang or LLVM that I could find which used a non-throwing new, so I did not think we would need anything more involved than this change. Testing this would be highly platform dependent and so it does not come with test coverage. And because it doesn't change behavior that users are likely to be able to observe, it does not come with a release note.
2023-03-14[Support][MemBuffer] Prevent UB on empty StringRefsKadir Cetinkaya1-2/+7
Empty StringRefs are usually identified by their length being zero, and sometimes they'll have Data==nullptr (e.g. default constructed, or derived from an operation like split/copy and result turned out to be empty). If such StringRef objects are passed to llvm::MemoryBuffer::getMemBufferCopy, it'll result in UB as neither src nor dst can be null, even if size is zero. This patch prevents that UB by not issuing a copy whenever StringRef is empty. Differential Revision: https://reviews.llvm.org/D144706
2022-12-16[Support] llvm::Optional => std::optionalFangrui Song1-15/+14
https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-01Cache memory buffer's name lengthserge-sans-paille1-6/+12
This avoids repeated calls to strlen while we already know its value. When preprocessing sqlite3.c, this gives a surprising 2% speedup. Full benchmark available here: https://llvm-compile-time-tracker.com/compare.php?from=d14c2d408dccd8c6defa7d151e9a96be3cac8cc3&to=04f0641c1cbdcd0bdbd11cd910ca6091420bf52e&stat=instructions:u Recommit 1824432174b3166b40bce59477beb5821170748e, with restored '\0' at the end of buffer name. Differential Revision: https://reviews.llvm.org/D138555
2022-11-29Revert "Cache memory buffer's name length"Florian Hahn1-15/+10
This reverts commit 1824432174b3166b40bce59477beb5821170748e. The change triggers an assertion when building clang on macOS: FAILED: tools/clang/include/clang/Tooling/Syntax/Nodes.inc cd /Users/florianhahn/projects/llvm-project/builds/release-with-assertions/ccache-stage1 && /Users/florianhahn/projects/llvm-project/builds/release-with-assertions/ccache-stage1/bin/clang-tblgen -gen-clang-syntax-node-list -I /Users/florianhahn/projects/llvm-project/clang/include/clang/Tooling/Syntax -I/Users/florianhahn/projects/llvm-project/clang/include -I/Users/florianhahn/projects/llvm-project/builds/release-with-assertions/ccache-stage1/tools/clang/include -I/Users/florianhahn/projects/llvm-project/builds/release-with-assertions/ccache-stage1/include -I/Users/florianhahn/projects/llvm-project/llvm/include /Users/florianhahn/projects/llvm-project/clang/include/clang/Tooling/Syntax/Nodes.td --write-if-changed -o tools/clang/include/clang/Tooling/Syntax/Nodes.inc -d tools/clang/include/clang/Tooling/Syntax/Nodes.inc.d Assertion failed: ((!RequiresNullTerminator || BufEnd[0] == 0) && "Buffer is not null terminated!"), function init, file MemoryBuffer.cpp, line 52. Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it): 0 clang-tblgen 0x000000010466b68c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56 1 clang-tblgen 0x000000010466a808 llvm::sys::RunSignalHandlers() + 64 2 clang-tblgen 0x000000010466bd60 SignalHandler(int) + 344 3 libsystem_platform.dylib 0x00000001877a92a4 _sigtramp + 56 4 libsystem_pthread.dylib 0x000000018777acec pthread_kill + 288 5 libsystem_c.dylib 0x00000001876b42c8 abort + 180 6 libsystem_c.dylib 0x00000001876b3620 err + 0 7 clang-tblgen 0x00000001046ce150 llvm::ErrorOr<std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>> getOpenFileImpl<llvm::MemoryBuffer>(int, llvm::Twine const&, unsigned long long, unsigned long long, long long, bool, bool, llvm::Optional<llvm::Align>) (.cold.1) + 0 8 clang-tblgen 0x000000010464a548 llvm::WritableMemoryBuffer::getNewUninitMemBuffer(unsigned long, llvm::Twine const&, llvm::Optional<llvm::Align>) + 496 9 clang-tblgen 0x000000010464a7a0 llvm::ErrorOr<std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>> getOpenFileImpl<llvm::MemoryBuffer>(int, llvm::Twine const&, unsigned long long, unsigned long long, long long, bool, bool, llvm::Optional<llvm::Align>) + 528 10 clang-tblgen 0x000000010464a254 llvm::ErrorOr<std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>> getFileAux<llvm::MemoryBuffer>(llvm::Twine const&, unsigned long long, unsigned long long, bool, bool, bool, llvm::Optional<llvm::Align>) + 176 11 clang-tblgen 0x000000010466fbbc llvm::TableGenMain(char const*, bool (*)(llvm::raw_ostream&, llvm::RecordKeeper&)) + 1428 12 clang-tblgen 0x0000000104626114 main + 156 13 dyld 0x0000000187453e50 start + 2544
2022-11-29Cache memory buffer's name lengthserge-sans-paille1-10/+15
This avoids repeated calls to strlen while we already know its value. When preprocessing sqlite3.c, this gives a surprising 2% speedup. Full benchmark available here: https://llvm-compile-time-tracker.com/compare.php?from=5279e6a7d677cdf4488883b77aacab911318100c&to=389601b0dbdf23cf25167ddfc49b3af5742ebd9a&stat=instructions:u Differential Revision: https://reviews.llvm.org/D138555
2022-11-12[MemoryBuffer] Allow optionally specifying desired buffer alignmentRiver Riddle1-28/+46
Underlying data may have requirements/expectations/etc. about the run-time alignment. WritableMemoryBuffer currently uses a 16 byte alignment, which works for many situations but not all. Allowing a desired alignment makes it easier to reuse WritableMemoryBuffer in situations of special alignment, and also removes a problem when opening files with special alignment constraints. Large files generally get mmaped, which has ~page alignment, but small files go through WritableMemoryBuffer which has the much smaller alignment guarantee. Differential Revision: https://reviews.llvm.org/D137820
2022-03-14Fix issing header on z/OSserge-sans-paille1-0/+4
Bug introduced in fbbc41f8dd23
2022-03-11Cleanup include: TableGenserge-sans-paille1-2/+1
This also includes a few cleanup from Support. Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D121331
2022-03-11Fixed a roll-over on size_t in getNewUninitMemBuffer()Dmitry Vassiliev1-0/+2
Reviewed By: serge-sans-paille Differential Revision: https://reviews.llvm.org/D121399
2022-02-06[llvm] Use = default (NFC)Kazu Hirata1-2/+2
2022-01-26[SystemZ][z/OS] Add AutoConvert.h header to MemoryBuffer.cppAbhina Sreeskantharajan1-0/+1
This commit https://github.com/llvm/llvm-project/commit/75e164f61d391979b4829bf2746a5d74b94e95f2 removed the AutoConvert.h header causing a build break on z/OS. This patch adds it back to fix it. Reviewed By: zibi Differential Revision: https://reviews.llvm.org/D118129
2022-01-26[NFC] Additional header dependency cleanup LLVMSupportserge-sans-paille1-1/+0
A few more forward-declarations, a few less headers. the impact on number of preprocessed lines for LLVMSupport is negligible (-3K lines) but it's always good to remove dependencies. Related discourse thread: https://llvm.discourse.group/t/include-what-you-use-include-cleanup
2022-01-21[llvm] Cleanup header dependencies in ADT and Supportserge-sans-paille1-3/+2
The cleanup was manual, but assisted by "include-what-you-use". It consists in 1. Removing unused forward declaration. No impact expected. 2. Removing unused headers in .cpp files. No impact expected. 3. Removing unused headers in .h files. This removes implicit dependencies and is generally considered a good thing, but this may break downstream builds. I've updated llvm, clang, lld, lldb and mlir deps, and included a list of the modification in the second part of the commit. 4. Replacing header inclusion by forward declaration. This has the same impact as 3. Notable changes: - llvm/Support/TargetParser.h no longer includes llvm/Support/AArch64TargetParser.h nor llvm/Support/ARMTargetParser.h - llvm/Support/TypeSize.h no longer includes llvm/Support/WithColor.h - llvm/Support/YAMLTraits.h no longer includes llvm/Support/Regex.h - llvm/ADT/SmallVector.h no longer includes llvm/Support/MemAlloc.h nor llvm/Support/ErrorHandling.h You may need to add some of these headers in your compilation units, if needs be. As an hint to the impact of the cleanup, running clang++ -E -Iinclude -I../llvm/include ../llvm/lib/Support/*.cpp -std=c++14 -fno-rtti -fno-exceptions | wc -l before: 8000919 lines after: 7917500 lines Reduced dependencies also helps incremental rebuilds and is more ccache friendly, something not shown by the above metric :-) Discourse thread on the topic: https://llvm.discourse.group/t/include-what-you-use-include-cleanup/5831
2022-01-11Support: Extract sys::fs::readNativeFileToEOF() from MemoryBufferDuncan P. N. Exon Smith1-17/+3
Extract the `readNativeFile()` loop from `MemoryBuffer::getMemoryBufferForStream()` into `readNativeFileToEOF()` to allow reuse. The chunk size is configurable; the default of `4*4096` is exposed as `sys::fs::DefaultReadChunkSize` to allow sizing of SmallVectors. There's somewhere I'd like to read a usually-small file without overhead of a MemoryBuffer; extracting existing logic rather than duplicating it. Differential Revision: https://reviews.llvm.org/D115397
2021-12-30[Support] Add MemoryBuffer::dontNeedIfMmapFangrui Song1-0/+2
On *NIX systems, this API calls madvise(MADV_DONTNEED) on read-only file mappings. It should not be used on a writable buffer. The API is used to implement ld.lld LTO memory saving trick (D116367). Note: on read-only file mappings, Linux's MADV_DONTNEED semantics match POSIX POSIX_MADV_DONTNEED and BSD systems' MADV_DONTNEED. On Windows, VirtualAllocEx MEM_COMMIT/MEM_RESET have similar semantics but are unfortunately not drop-in replacements. dontNeedIfMmap is currently a no-op. Reviewed By: aganea Differential Revision: https://reviews.llvm.org/D116366
2021-12-09Support: Avoid using SmallVector::set_size() in MemoryBufferDuncan P. N. Exon Smith1-3/+6
Update getMemoryBufferForStream() to use `resize_for_overwrite()` and `truncate()` instead of `reserve()` and `set_size()`. Differential Revision: https://reviews.llvm.org/D115384
2021-05-03[SystemZ][z/OS] Add the functions needed for handling EBCDIC I/OAbhina Sreeskantharajan1-0/+7
This patch adds the basic functions needed for controlling auto conversion on z/OS. Auto conversion is enabled on untagged input file to ASCII by making the assumption that all untagged files are EBCDIC encoded. Output files are auto converted to EBCDIC IBM-1047. This change also enables conversion for stdin/stdout/stderr. For more information on how fcntl controls codepage https://www.ibm.com/docs/en/zos/2.4.0?topic=descriptions-fcntl-bpx1fct-bpx4fct-control-open-file-descriptors Reviewed By: anirudhp Differential Revision: https://reviews.llvm.org/D100483
2021-04-16[SystemZ][z/OS][Windows] Add new functions that set Text/Binary mode for ↵Abhina Sreeskantharajan1-1/+1
Stdin and Stdout based on OpenFlags On Windows, we want to open a file in Binary mode if OF_CRLF bit is not set. On z/OS, we want to open a file in Binary mode if the OF_Text bit is not set. This patch creates two new functions called ChangeStdinMode and ChangeStdoutMode which will take OpenFlags as an arg to determine which mode to set stdin and stdout to. This will enable patches like https://reviews.llvm.org/D100056 to not affect Windows when setting the OF_Text flag for raw_fd_streams. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D100130
2021-04-06[SystemZ][z/OS][Windows] Add new OF_TextWithCRLF flag and use this flag ↵Abhina Sreeskantharajan1-1/+1
instead of OF_Text Problem: On SystemZ we need to open text files in text mode. On Windows, files opened in text mode adds a CRLF '\r\n' which may not be desirable. Solution: This patch adds two new flags - OF_CRLF which indicates that CRLF translation is used. - OF_TextWithCRLF = OF_Text | OF_CRLF indicates that the file is text and uses CRLF translation. Developers should now use either the OF_Text or OF_TextWithCRLF for text files and OF_None for binary files. If the developer doesn't want carriage returns on Windows, they should use OF_Text, if they do want carriage returns on Windows, they should use OF_TextWithCRLF. So this is the behaviour per platform with my patch: z/OS: OF_None: open in binary mode OF_Text : open in text mode OF_TextWithCRLF: open in text mode Windows: OF_None: open file with no carriage return OF_Text: open file with no carriage return OF_TextWithCRLF: open file with carriage return The Major change is in llvm/lib/Support/Windows/Path.inc to only set text mode if the OF_CRLF is set. ``` if (Flags & OF_CRLF) CrtOpenFlags |= _O_TEXT; ``` These following files are the ones that still use OF_Text which I left unchanged. I modified all these except raw_ostream.cpp in recent patches so I know these were previously in Binary mode on Windows. ./llvm/lib/Support/raw_ostream.cpp ./llvm/lib/TableGen/Main.cpp ./llvm/tools/dsymutil/DwarfLinkerForBinary.cpp ./llvm/unittests/Support/Path.cpp ./clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp ./clang/lib/Frontend/CompilerInstance.cpp ./clang/lib/Driver/Driver.cpp ./clang/lib/Driver/ToolChains/Clang.cpp Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D99426
2021-03-25[NFC] Reordering parameters in getFile and getFileOrSTDINAbhina Sreeskantharajan1-24/+22
In future patches I will be setting the IsText parameter frequently so I will refactor the args to be in the following order. I have removed the FileSize parameter because it is never used. ``` static ErrorOr<std::unique_ptr<MemoryBuffer>> getFile(const Twine &Filename, bool IsText = false, bool RequiresNullTerminator = true, bool IsVolatile = false); static ErrorOr<std::unique_ptr<MemoryBuffer>> getFileOrSTDIN(const Twine &Filename, bool IsText = false, bool RequiresNullTerminator = true); static ErrorOr<std::unique_ptr<MB>> getFileAux(const Twine &Filename, uint64_t MapSize, uint64_t Offset, bool IsText, bool RequiresNullTerminator, bool IsVolatile); static ErrorOr<std::unique_ptr<WritableMemoryBuffer>> getFile(const Twine &Filename, bool IsVolatile = false); ``` Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D99182
2021-03-19[SystemZ][z/OS] Distinguish between text and binary files on z/OSAbhina Sreeskantharajan1-12/+14
This patch consists of the initial changes to help distinguish between text and binary content correctly on z/OS. I would like to get feedback from Windows users on setting OF_None for all ToolOutputFiles. This seems to have been done as an optimization to prevent CRLF translation on Windows in the past. Reviewed By: zibi Differential Revision: https://reviews.llvm.org/D97785
2021-01-28[Support] Add some missing namespace closure comments. NFCI.Simon Pilgrim1-3/+3
Fixes some clang-tidy warnings.
2020-09-24Revert "[Modules] Add stats to measure performance of building and loading ↵Volodymyr Sapsai1-14/+2
modules." This reverts commit c4bacc3c9b333bb7032fb96f41d6f5b851623132. Test "LLVM :: ThinLTO/X86/funcimport-stats.ll" is failing. Reverting now and will recommit after making the test not fail with the added stats.
2020-09-24[Modules] Add stats to measure performance of building and loading modules.Volodymyr Sapsai1-2/+14
Measure amount of high-level or fixed-cost operations performed during building/loading modules and during header search. High-level operations like building a module or processing a .pcm file are motivated by previous issues where clang was re-building modules or re-reading .pcm files unnecessarily. Fixed-cost operations like `stat` calls are tracked because clang cannot change how long each operation takes but it can perform fewer of such operations to improve the compile time. Also tracking such stats over time can help us detect compile-time regressions. Added stats are more stable than the actual measured compilation time, so expect the detected regressions to be less noisy. rdar://problem/55715134 Reviewed By: aprantl, bruno Differential Revision: https://reviews.llvm.org/D86895
2020-09-15[MemoryBuffer] Revert unintended MemoryBuffer change from D86996Fangrui Song1-1/+2
Fixes SupportsTest MemoryBufferTest.mmapVolatileNoNull
2020-09-15[lldb] Add -l/--language option to script commandJonas Devlieghere1-2/+1
Make it possible to run the script command with a different language than currently selected. $ ./bin/lldb -l python (lldb) script -l lua >>> io.stdout:write("Hello, World!\n") Hello, World! When passing the language option and a raw command, you need to separate the flag from the script code with --. $ ./bin/lldb -l python (lldb) script -l lua -- io.stdout:write("Hello, World!\n") Hello, World! Differential revision: https://reviews.llvm.org/D86996
2020-04-15[Clang] Expose RequiresNullTerminator in FileManager.Michael Spencer1-1/+1
This is needed to fix the reason 0a2be46cfdb698fe (Modules: Invalidate out-of-date PCMs as they're discovered) and 5b44a4b07fc1d ([modules] Do not cache invalid state for modules that we attempted to load.) were reverted. These patches changed Clang to use `isVolatile` when loading modules. This had the side effect of not using mmap when loading modules, and thus greatly increased memory usage. The reason it wasn't using mmap is because `MemoryBuffer` plays some games with file size when you request null termination, and it has to disable these when `isVolatile` is set as the size may change by the time it's mmapped. Clang by default passes `RequiresNullTerminator = true`, and `shouldUseMmap` ignored if `RequiresNullTerminator` was even requested. This patch adds `RequiresNullTerminator` to the `FileManager` interface so Clang can use it when loading modules, and changes `shouldUseMmap` to only take volatility into account if `RequiresNullTerminator` is true. This is fine as both `mmap` and a `read` loop are vulnerable to modifying the file while reading, but are immune to the rename Clang does when replacing a module file. Differential Revision: https://reviews.llvm.org/D77772
2020-02-29Avoid including FileSystem.h from MemoryBuffer.hReid Kleckner1-1/+15
Lots of headers pass around MemoryBuffer objects, but very few open them. Let those that do include FileSystem.h. Saves ~250 includes of Chrono.h & FileSystem.h: $ diff -u thedeps-before.txt thedeps-after.txt | grep '^[-+] ' | sort | uniq -c | sort -nr 254 - ../llvm/include/llvm/Support/FileSystem.h 253 - ../llvm/include/llvm/Support/Chrono.h 237 - ../llvm/include/llvm/Support/NativeFormatting.h 237 - ../llvm/include/llvm/Support/FormatProviders.h 192 - ../llvm/include/llvm/ADT/StringSwitch.h 190 - ../llvm/include/llvm/Support/FormatVariadicDetails.h ... This requires duplicating the file_t typedef, which is unfortunate. I sunk the choice of mapping mode down into the cpp file using variable template specializations instead of class members in headers.
2020-02-10Revert "Remove redundant "std::move"s in return statements"Bill Wendling1-4/+4
The build failed with error: call to deleted constructor of 'llvm::Error' errors. This reverts commit 1c2241a7936bf85aa68aef94bd40c3ba77d8ddf2.
2020-02-10Remove redundant "std::move"s in return statementsBill Wendling1-4/+4
2019-08-22[Support] Improve readNativeFile(Slice) interfacePavel Labath1-10/+23
Summary: There was a subtle, but pretty important difference between the Slice and regular versions of this function. The Slice function was zero-initializing the rest of the buffer when the read syscall returned less bytes than expected, while the regular function did not. This patch removes the inconsistency by making both functions *not* zero-initialize the buffer. The zeroing code is moved to the MemoryBuffer class, which is currently the only user of this code. This makes the API more consistent, and the code shorter. While in there, I also refactor the functions to return the number of bytes through the regular return value (via Expected<size_t>) instead of a separate by-ref argument. Reviewers: aganea, rnk Subscribers: kristina, Bigcheese, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66471 llvm-svn: 369627
2019-08-20Recommit "MemoryBuffer: Add a missing error-check to getOpenFileImpl"Pavel Labath1-1/+3
This recommits r368977, which was reverted in r369027 due to test failures in lldb. The cause of this was different behavior of readNativeFileSlice on windows and unix. These have been addressed in r369269. The original commit message was: In case the function was called with a desired read size *and* the file was not an "mmap()" candidate, the function was falling back to a "pread()", but it was failing to check the result of that system call. This meant that the function would return "success" even though the read operation failed, and it returned a buffer full of uninitialized memory. Reviewers: rnk, dblaikie Subscribers: kristina, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66224 llvm-svn: 369370
2019-08-15Revert "MemoryBuffer: Add a missing error-check to getOpenFileImpl"Pavel Labath1-3/+1
This reverts commit r368977 because it broke a couple of tests in lldb. llvm-svn: 369027
2019-08-15MemoryBuffer: Add a missing error-check to getOpenFileImplPavel Labath1-1/+3
Summary: In case the function was called with a desired read size *and* the file was not an "mmap()" candidate, the function was falling back to a "pread()", but it was failing to check the result of that system call. This meant that the function would return "success" even though the read operation failed, and it returned a buffer full of uninitialized memory. Reviewers: rnk, dblaikie Subscribers: kristina, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66224 llvm-svn: 368977
2019-07-10[Support] Move llvm::MemoryBuffer to sys::fs::file_tReid Kleckner1-56/+31
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
2019-05-08[Support] Add error handling to sys::Process::getPageSize().Lang Hames1-1/+1
This patch changes the return type of sys::Process::getPageSize to Expected<unsigned> to account for the fact that the underlying syscalls used to obtain the page size may fail (see below). For clients who use the page size as an optimization only this patch adds a new method, getPageSizeEstimate, which calls through to getPageSize but discards any error returned and substitues a "reasonable" page size estimate estimate instead. All existing LLVM clients are updated to call getPageSizeEstimate rather than getPageSize. On Unix, sys::Process::getPageSize is implemented in terms of getpagesize or sysconf, depending on which macros are set. The sysconf call is documented to return -1 on failure. On Darwin getpagesize is implemented in terms of sysconf and may also fail (though the manpage documentation does not mention this). These failures have been observed in practice when highly restrictive sandbox permissions have been applied. Without this patch, the result is that getPageSize returns -1, which wreaks havoc on any subsequent code that was assuming a sane page size value. <rdar://problem/41654857> Reviewers: dblaikie, echristo Subscribers: kristina, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D59107 llvm-svn: 360221
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-07-30Remove trailing spaceFangrui Song1-1/+1
sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h} llvm-svn: 338293
2018-07-27[Support] Remove unnecessary MemoryBuffer::anchor (where the destructor ↵Fangrui Song1-2/+1
serves as the key function) llvm-svn: 338175
2018-06-11Fix build errors on some configurationsPavel Labath1-1/+1
It's been reported <http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20180611/559616.html> that template argument deduction for RetryAfterSignal fails if open is not prefixed with "::". This should help us build correctly on those platforms and explicitly specifying the namespace is more correct anyway. llvm-svn: 334403
2018-06-07[FileSystem] Split up the OpenFlags enumeration.Zachary Turner1-4/+4
This breaks the OpenFlags enumeration into two separate enumerations: OpenFlags and CreationDisposition. The first controls the behavior of the API depending on whether or not the target file already exists, and is not a flags-based enum. The second controls more flags-like values. This yields a more easy to understand API, while also allowing flags to be passed to the openForRead api, where most of the values didn't make sense before. This also makes the apis more testable as it becomes easy to enumerate all the configurations which make sense, so I've added many new tests to exercise all the different values. llvm-svn: 334221
2018-05-01Remove \brief commands from doxygen comments.Adrian Prantl1-1/+1
We've been running doxygen with the autobrief option for a couple of years now. This makes the \brief markers into our comments redundant. Since they are a visual distraction and we don't want to encourage more \brief markers in new code either, this patch removes them all. Patch produced by for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done Differential Revision: https://reviews.llvm.org/D46290 llvm-svn: 331272
2018-04-16Rename ObjectMemoryBuffer to SmallVectorMemoryBuffer; NFCIWeiming Zhao1-2/+2
Summary: As discussed in https://reviews.llvm.org/D45606, it makes more sense to name the class as SmallVectorMemoryBuffer Reviewers: bkramer, dblaikie Reviewed By: dblaikie Subscribers: mehdi_amini, eraman, llvm-commits Differential Revision: https://reviews.llvm.org/D45661 llvm-svn: 330107