This is an archive of the discontinued LLVM Phabricator instance.

Simplify file handling in dsymutil
ClosedPublic

Authored by rafael on Nov 14 2017, 4:58 PM.

Details

Summary

I am trying to unify llvm's temporary file handling around TempFile.

This is a step towards using it in dsymutil. It just moves the file handling out of DwarfLinker.cpp.

This fixes what is at least an oddity if not a bug. DwarfLinker.cpp was using ToolOutputFile, which uses RemoveFileOnSignal. The issue is that dsymutil.cpp uses that too. It is now clear from the interface that only dsymutil.cpp is responsible for creating and deleting files.

Diff Detail

Event Timeline

rafael created this revision.Nov 14 2017, 4:58 PM
JDevlieghere edited edge metadata.Nov 15 2017, 2:52 AM

Thanks Rafael! I added the ToolOutputFile when implementing the threading option because I wanted to make sure files were removed if some thread were to exist dsymutil. Because we only use threads when there are multiple architectures which in turn implies we use temp files, we would indeed end up removing the file twice.

It's definitely an improvement to keep the file handling logic out the DwarfLinker. I'm not really happy with how we deal with files in dsymutil.cpp though and maybe this is the opportunity to improve it. For one, I don't like that getOutputFileName is doing so much more than just generating a file name. I also don't like that we don't remove non-temporary output files if linking fails.

Maybe we can start by splitting up the logic for temporary files (using TempFile) and output files (using ToolOutputFile). The former would contribute to your goal of unifying the use of TempFile and the latter would address my second concern. Things are a little tricky for dSYM bundles, where we ideally would want to remove the whole bundle rather than just the file. There's also the call to generateUniversalBinary which takes a file path rather than a handle.

I don't know if this is the best approach and how feasible it is, but consider this a way to kick off the discussion!

JDevlieghere accepted this revision.Nov 15 2017, 9:32 AM
This revision is now accepted and ready to land.Nov 15 2017, 9:32 AM