[clang] Add support for sysroot-relative system header search paths (PR #82084)
Huaqi Fang via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 10 23:34:06 PDT 2025
================
@@ -3191,6 +3191,22 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args,
bool IsIndexHeaderMap = false;
bool IsSysrootSpecified =
Args.hasArg(OPT__sysroot_EQ) || Args.hasArg(OPT_isysroot);
+
+ // Expand a leading `=` to the sysroot if one was passed (and it's not a
+ // framework flag).
+ auto PrefixHeaderPath = [IsSysrootSpecified,
----------------
fanghuaqi wrote:
> My understanding is that with this patch, whenever is sysroot specified we match the GCC behavior (assuming the `=` spelling). Are you specifically asking to add a fallback to `<clang>/../<target>/include`?
I found it is caused by this https://github.com/llvm/llvm-project/blob/53c785d8595f42a47ecc2f0f09d8315b10edfb79/clang/lib/Driver/ToolChains/Clang.cpp#L1084-L1092
The `sysroot` returned is empty, but actually it can be computed like this `getToolChain().computeSysRoot()`, for my case, it is done in https://github.com/llvm/llvm-project/blob/53c785d8595f42a47ecc2f0f09d8315b10edfb79/clang/lib/Driver/ToolChains/BareMetal.cpp#L165
And locally I modified the code `clang/lib/Driver/ToolChains/Clang.cpp` in my side like this, then it fixed my issue.
~~~diff
// If we have a --sysroot, and don't have an explicit -isysroot flag, add an
// -isysroot to the CC1 invocation.
- StringRef sysroot = C.getSysRoot();
- if (sysroot != "") {
- if (!Args.hasArg(options::OPT_isysroot)) {
- CmdArgs.push_back("-isysroot");
- CmdArgs.push_back(C.getArgs().MakeArgString(sysroot));
- }
+ std::string sysroot = std::string(C.getSysRoot());
+ if (sysroot.empty()) {
+ sysroot = getToolChain().computeSysRoot();
+ }
+ if (!Args.hasArg(options::OPT_isysroot)) {
+ CmdArgs.push_back("-isysroot");
+ CmdArgs.push_back(C.getArgs().MakeArgString(sysroot));
}
~~~
Regarding `Are you specifically asking to add a fallback to `<clang>/../<target>/include`?`
I think it will be good, since the `=` is not handled correctly, it directly returned invalid path `=/include/libncrt` not a sysroot path + `/include/libncrt`
https://github.com/llvm/llvm-project/pull/82084
More information about the cfe-commits
mailing list