This is an archive of the discontinued LLVM Phabricator instance.

Resubmit "Use LLVM for all stat related calls"
ClosedPublic

Authored by zturner on Mar 7 2017, 8:26 AM.

Details

Summary

This was broken due to LLVM's stat code following symlinks. I've added an option on the LLVM side to not follow symlinks and updated this patch to use it everywhere possible. The cases I couldn't get were where LLDB calls is_directory / is_regular_file / exists, etc. Those would return false on symlinks before, but now return true if the target is a directory / file / exists. I don't think that should be an issue, as I think generally that's what'e expected.

I can test this on Linux in a couple of hours unless someone beats me to it.

Diff Detail

Repository
rL LLVM

Event Timeline

zturner created this revision.Mar 7 2017, 8:26 AM
labath edited edge metadata.Mar 7 2017, 9:10 AM

Unfortunately, this does not seem to help. I'll try to debug today if I can find the time.

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
197 ↗(On Diff #90858)

This still breaks TestCompDirSymLink.py. I haven't yet dug into why, but it looks like some problem in the get_file_type implementation.

lldb/source/Target/ModuleCache.cpp
70 ↗(On Diff #90858)

This changes behavior (and breaks ModuleCache unit tests). The point of this was to check whether path is a directory, so if we cannot stat it, we should still try to create it.

labath added a comment.Mar 7 2017, 9:28 AM
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
197 ↗(On Diff #90858)

ok, so the problem is in llvm::sys::fs::fillStatus implementation. It is missing the call to S_ISLNK to decode the symlink bit (probably because it was not necessary until now).

zturner added inline comments.Mar 7 2017, 9:42 AM
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
197 ↗(On Diff #90858)

I literally just came to the same conclusion. Glad we agree on the fix! I'll also do a full audit of all the changes in regards to your other comment about the functionality change, and make sure that same mistake does not appear anywhere else.

zturner updated this revision to Diff 90905.Mar 7 2017, 11:58 AM

Fixed all the outstanding issues. I simplified the logic in ModuleCache, but I think it makes more sense this way, and the unit tests still pass. If we really care about the case where we want to create a directory on top of an existing broken symbolic link, we can see about adding that to LLVM, but in pratcice I don't think it matters.

I also went back and audited all the existing uses of the various functions, and I think they are all correct. Will run the entire test suite in a bit.

labath accepted this revision.Mar 7 2017, 1:47 PM

OK, let's give this another shot. (I haven't tried it on linux yet, so if you haven't either then let's wait until tomorrow, or maybe @eugene could try it out (?)). I don't think we need to be worried about symlink overwrite in the ModuleCache test.

llvm/include/llvm/Support/FileSystem.h
500 ↗(On Diff #90905)

missing closing paren here

This revision is now accepted and ready to land.Mar 7 2017, 1:47 PM
This revision was automatically updated to reflect the committed changes.