diff options
author | Richard Smith <richard@metafoo.co.uk> | 2025-08-13 12:39:25 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-08-13 12:39:25 -0700 |
commit | 85cd3d98686c47d015dbcc17f1f7d0714b00e172 (patch) | |
tree | b9cf1f64dbce3066ab5ba2bd4a95727648733392 /llvm/lib/ObjCopy/ELF | |
parent | 36d31b0c008b2716329b5c9990f583decf919819 (diff) | |
download | llvm-85cd3d98686c47d015dbcc17f1f7d0714b00e172.zip llvm-85cd3d98686c47d015dbcc17f1f7d0714b00e172.tar.gz llvm-85cd3d98686c47d015dbcc17f1f7d0714b00e172.tar.bz2 |
Work around documented Linux mmap bug. (#152595)
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
Diffstat (limited to 'llvm/lib/ObjCopy/ELF')
0 files changed, 0 insertions, 0 deletions