<div dir="auto">In a very large class of cases the correct thing is to cleanup on next run. Not sure clang is in that class by any means, just tossing this out there...</div><div class="gmail_extra"><br><div class="gmail_quote">On 10 Nov 2017 18.21, "Mark Kettenis via llvm-dev" <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">> Date: Thu, 09 Nov 2017 13:13:52 -0800<br>
> From: Rafael Avila de Espindola via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>><br>
><br>
> Currently a power failure or other hard crash can cause lld leave a temporary<br>
> file around. The same is true for other llvm tools.<br>
><br>
> As an example, put a breakpoint in Writer.cpp:236 ("writeBuildId()") and<br>
> restart the run a few times. You will get<br>
><br>
> t.tmp43a735a  t.tmp4deeabb  t.tmp9bacdd3  t.tmpe4115c4  t.tmpeb01fff<br>
><br>
> The same would happen if there was a fatal error between the<br>
> FileOutputBuffer creation and commit. I don't think that is a code path<br>
> where that is possible right now, but it would be an easy thing to miss<br>
> in a code review.<br>
><br>
> I was hopping the OS could help us manage the temporary file so that<br>
> there was no way to accidentally leave it behind.<br>
><br>
> On linux there is O_TMPFILE, which allows us to create a file with no<br>
> name in the file system.<br>
<br>
For the LLVM use case creatinmg the file and immediately unlinking it<br>
would probably be good enough.  Howver...<br>
<br>
> A name can be given with linkat. Unfortunately we can't use<br>
><br>
> linkat(fd, "", AT_FDCWD, "destination", AT_EMPTY_PATH)<br>
><br>
> Without special permissions and have instead to depend on proc:<br>
><br>
> linkat(AT_FDCWD, "/proc/self/fd/<num>", AT_FDCWD, "destination",<br>
>        AT_SYMLINK_FOLLOW)<br>
><br>
> Another annoyance is that linkat will not replace the destination and<br>
> renameat2 doesn't support AT_EMPTY_PATH. The result is that we have to<br>
> use unlink+linkat and loop.<br>
<br>
I'd strongly recommend avoiding such unportable cleverness.<br>
<br>
I'm actually surprised Linux allows this as there are some serious<br>
security implications as this allows programs to create an entry in<br>
the filesystem for file descriptors passed over a socket.<br>
______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div>