[llvm-dev] Experiment on how to improve our temporary file handing.

Davide Italiano via llvm-dev llvm-dev at lists.llvm.org
Mon Nov 13 11:03:42 PST 2017

On Thu, Nov 9, 2017 at 1:13 PM, Rafael Avila de Espindola
<rafael.espindola at gmail.com> wrote:
> Currently a power failure or other hard crash can cause lld leave a temporary
> file around. The same is true for other llvm tools.
> As an example, put a breakpoint in Writer.cpp:236 ("writeBuildId()") and
> restart the run a few times. You will get
> t.tmp43a735a  t.tmp4deeabb  t.tmp9bacdd3  t.tmpe4115c4  t.tmpeb01fff
> The same would happen if there was a fatal error between the
> FileOutputBuffer creation and commit. I don't think that is a code path
> where that is possible right now, but it would be an easy thing to miss
> in a code review.
> I was hopping the OS could help us manage the temporary file so that
> there was no way to accidentally leave it behind.
> On linux there is O_TMPFILE, which allows us to create a file with no
> name in the file system. A name can be given with linkat. Unfortunately
> we can't use
> linkat(fd, "", AT_FDCWD, "destination", AT_EMPTY_PATH)
> Without special permissions and have instead to depend on proc:
> linkat(AT_FDCWD, "/proc/self/fd/<num>", AT_FDCWD, "destination",
> Another annoyance is that linkat will not replace the destination and
> renameat2 doesn't support AT_EMPTY_PATH. The result is that we have to
> use unlink+linkat and loop.
> On windows there is FILE_FLAG_DELETE_ON_CLOSE, but there seems to be no
> way to cancel it. If a file is created with it I can rename it, but it
> is still deleted in the end.
> I couldn't find any support for this on FreeBSD.

AFAIK FreeBSD supports some variant of /proc that should map Linux
(although the mapping isn't 1:1).
Does it lack support for this? Thanks for looking into this, BTW!


More information about the llvm-dev mailing list