[LLD][ELF][Windows] Allow LLD to overwrite existing output files that are in use
authorBen Dunbobbin <Ben.Dunbobbin@sony.com>
Fri, 3 Jul 2020 11:54:24 +0000 (12:54 +0100)
committerBen Dunbobbin <Ben.Dunbobbin@sony.com>
Fri, 3 Jul 2020 12:08:56 +0000 (13:08 +0100)
commitf42f599d3724cd4a2f470a53551604f722965de6
tree850e0540a44368f1557130fe526b9ba0cb2d8d5d
parentbb69ca822aae38e12546757f48670cbf689bc227
[LLD][ELF][Windows] Allow LLD to overwrite existing output files that are in use

On Windows co-operative programs can be expected to open LLD's
output in FILE_SHARE_DELETE mode. This allows us to delete the
file (by moving it to a temporary filename and then deleting
it) so that we can link another output file that overwrites
the existing file, even if the current file is in use.

A similar strategy is documented here:
https://boostgsoc13.github.io/boost.afio/doc/html/afio/FAQ/deleting_open_files.html

Differential Revision: https://reviews.llvm.org/D82567
lld/Common/Filesystem.cpp
lld/test/ELF/link-open-file.test [new file with mode: 0644]