[clang] [clang][driver] Prevent clang picking the system headers/libraries when started via a symlink (PR #68091)

Martin Storsjö via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 4 13:29:52 PDT 2023


mstorsjo wrote:

> > it's quite possible that someone has ended up depending on the previous de facto behaviour.
> 
> Then we have to be super creative and find a better solution.
> 
> How about changing the logic, and where `Driver.InstalledDir` is used, if the desired file/folder is not found (like header or library), search again in `Driver.Dir` (which is the parent of ClangExecutable)?
> 
> I don't know how complicated the implementation might be, but, at first sight, it should maintain compatibility with curent use cases that create a full toolchain folder and also prevent silently falling back to system headers/libraries (like in my use case).

Yes, something like that would be possible. I wonder if this would need to be somewhat target specific. Different targets have different logic for fallback when things don't exist in the most expected directory. But perhaps it would be enough to check for `<executable>/../lib/clang/<version>` or something like that, to distinguish between the two locations - that's at least quite target independent.

On the other hand; I agree that it's kinda implausible that this directory would exist at all anywhere else than next to the actual executable. In that case, perhaps those testcases are the only cases that would need to be handled after all?

@nolange - in your efforts in https://github.com/mstorsjo/llvm-mingw/issues/362 - do you rely on making a symlink to the system installed clang executable and locating sysroots and the clang `<base>/lib/clang` directory next to the symlink?



https://github.com/llvm/llvm-project/pull/68091


More information about the cfe-commits mailing list