[clang] [Darwin][Driver][clang] Prioritise `-isysroot` over `--sysroot` consistently (PR #115993)

James Y Knight via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 27 11:46:16 PST 2024


jyknight wrote:

This is the intended/expected behavior.

On every other platform, `-isysroot` is supposed to be an override setting the sysroot only for the header files, and _never_ overriding the linker sysroot. The `--sysroot` flag, on the other hand, sets the value used for both libraries and headers (unless the header sysroot is set via `-isysroot`). As such, there's almost never a reason to pass `-isysroot` -- the right flag is `--sysroot` 99% of the time.

Except, on Darwin platforms, for some reason that's probably lost to history, the `-isysroot` is used almost universally instead of `--sysroot`, and a platform special-case was added to cause `-isysroot` to affect both the header _and_ library sysroots -- unless the `--sysroot` flag is also set. This is weird and inconsistent, but it's been that way forever. The behavior was implemented very early on in Clang's development, because the pre-existing Darwin GCC port did that. 

However, notably, even on Darwin, if you pass _both_ flags, you still get the intended behavior of `-isysroot` affecting headers, and `--sysroot` affecting libraries. Your change would break that.

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


More information about the cfe-commits mailing list