[lld] [llvm] Rename `F_no_mmap` to `F_mmap` (PR #134787)
via llvm-commits
llvm-commits at lists.llvm.org
Wed May 14 13:12:20 PDT 2025
dgg5503 wrote:
Hi @MaskRay,
> --no-mmap-output-file is actually our default. This PR did not change the default, and actually switched from createOnDiskBuffer to createInMemoryBuffer.
Ah, that explains it. Thanks for picking up on this detail & creating a PR to reland this change.
I can confirm that with https://github.com/llvm/llvm-project/pull/139836, the test `lld\test\ELF\link-open-file.test` passes under Windows using a configuration similar to `llvm-clang-x86_64-sie-win`.
> @dgg5503 Can you investigate why lld::link-open-file.test failed with createInMemoryBuffer?
Yes! I did some investigation this morning and discovered that changing `OF_None` to `OF_Delete` here:
https://github.com/llvm/llvm-project/blob/8c435886aaee7619314edac9b142ef6fb2dd935f/llvm/lib/Support/FileOutputBuffer.cpp#L102
will allow the test `lld\test\ELF\link-open-file.test` to pass if it were augmented to also test `--mmap-output-file`.
In `createInMemoryBuffer`, an `InMemoryBuffer` is returned which will commit the file via `openFileForWrite`:
https://github.com/llvm/llvm-project/blob/8c435886aaee7619314edac9b142ef6fb2dd935f/llvm/lib/Support/FileOutputBuffer.cpp#L117-L125
https://github.com/llvm/llvm-project/blob/8c435886aaee7619314edac9b142ef6fb2dd935f/llvm/lib/Support/FileOutputBuffer.cpp#L91-L107
I think adding `OF_Delete` to `openFileForWrite` in `InMemoryBuffer::commit` makes sense because in `createOnDiskBuffer`, `TempFile::create` is called which also sets `OF_Delete` here:
https://github.com/llvm/llvm-project/blob/8c435886aaee7619314edac9b142ef6fb2dd935f/llvm/lib/Support/FileOutputBuffer.cpp#L127-L130
https://github.com/llvm/llvm-project/blob/61c1f6d7e84f1213bd727437a7ec5b7fc5eaf121/llvm/lib/Support/Path.cpp#L1329-L1330
The Windows only test `lld\test\ELF\link-open-file.test` is verifying that a shared file opened with `FILE_SHARE_DELETE` is capable of being overwritten by LLD , and a shared file opened _without_ `FILE_SHARE_DELETE` raises an error under LLD when attempted to be overwritten:
https://github.com/llvm/llvm-project/blob/61c1f6d7e84f1213bd727437a7ec5b7fc5eaf121/lld/test/ELF/link-open-file.test#L1-L5
If I'm understanding [MSDN documentation](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#parameters) correctly, when the test opens the output file **without** `FILE_SHARE_DELETE`, it would only fail if `the file or device has been opened for delete access` which, in LLD, `TempFile` does but `openFileForWrite` does not.
So I suppose we should set `OF_Delete` accordingly, does that sound correct? If you agree with my findings, I'd be happy to create a PR and small associated test.
https://github.com/llvm/llvm-project/pull/134787
More information about the llvm-commits
mailing list