This is in unfinished state as of now and not ready for submission.
- Has a bunch of TODOs that must be fixed.
- Laking Windows implementation.
Differential D36265
Support lib changes to allow VFS implementation handling working dir locally. ilya-biryukov on Aug 3 2017, 4:51 AM. Authored by
Details
This is in unfinished state as of now and not ready for submission.
Diff Detail
Event TimelineComment Actions Hi, @chapuni, @klimek told me you could probably help with Windows-specific questions. We're working on making clang's vfs::RealFileSystem more thread-friendly. Current implementation uses process-global working directory, we want to get rid of that. (vfs::FileSystem has setCurrentWorkingDirectory and must do all relative paths lookups according to its value). After doing some research, it seems that we should use NtCreateFile and pass proper ObjectAttributes.RootDirectory (e.g. see this stackoverflow question). Comment Actions It's not just Windows, but not even all unixes support openat. Minimum required version of various Unixes are: DragonFly 2.3. I don't know how old some of these are, but you should check first to make sure we don't support any versions of these unix variants with versions older than specified above. As for Windows, If we're going to use Nt functions, I would rather they be entirely separate functions. i.e. not done via an optional parameter to an existing function, but a completely new function. Comment Actions Also, even without using the Nt functions, you could get the working directory via the process's HANDLE, then stitch together a new working directory and build an absolute path out of it. It's not entirely atomic the way openat is because someone could change the working directory of the process after you query its working directory, but I suspect that wouldn't matter? Comment Actions Right, that does not matter. I actually made a patch that does exactly that in clang's vfs::FileSystem, it doesn't require any changes in the Support library and all LLVM tests seem to pass if you do that: https://reviews.llvm.org/D36226?vs=on&id=109362&whitespace=ignore-most#toc. Thanks, we definitely don't want to make LLVM incompatible with those platforms. I imagine we still need to keep LLVM running on those versions, they aren't too old and probably still widely used. Technically, creating separate functions should not be too hard.
What problems do you foresee if we switch to Nt API everywhere? Comment Actions I'll start to work on an implementation that is only enable via a configurable macro. That way, we could have it available for Unix variants that support openat. Comment Actions The main concern I have is that the Nt functions are not intended for public consumption. They're considered internal, and as such they are subject to all the caveats listed here. I fear it would also be impossible to safely implement some of the functions with the Nt methods. For example, openFileForRead returns an fd in one of its arguments. The way this is implemented is by calling CreateFile and then taking the resulting HANDLE and calling _open_osfhandle on it. Does this work when it's an NtCreate handle? Maybe? I don't know, but if we can't mix functions then this is just one of the problems. The point is that some of our APIs expose these handles and descriptors to the outside world, and we can't expect external users to use the Nt APIs. If all this is hidden behind a separate function, then the requirements for that function could be documented independently. Regardless, the main thing is that it's an internal API, and it seems like a very bad idea to have our entire filesystem library for all of LLVM be based entirely on unsupported, internal OS APIs. Comment Actions Almost certainly nobody maintains newer LLVM on older versions of mentioned BSD systems. Comment Actions I totally agree that is not ideal. Even though Nt functions for file manipulations have been there for ages. I personally highly doubt they will go away in the foreseeable future, but there is no guarantee.
That is certainly an issue I overlooked. There are no indications if _open_osfhandle will work properly on handles created by Nt functions.
Another thing is that for Windows we may get away with just converting the paths to absolute all the time. The symlinks changing their target rapidly (i.e. during a single compile) is something we're having trouble with only on Linux, and I doubt this use-case would ever come up on Windows. Good to know, thanks. |