Skip to content

Commit c664b02

Browse files
committed
[Clang][Driver] Fix the missing Target-Triple-Level include path resolution in Baremetal Driver
The current baremetal driver implementation does not have a way to derive the target-triple-level include path within the sysroot. This feature is especially useful in setups where header paths deviate from the default bare-metal assumptions. For example, when headers are shared across target triples, it becomes necessary to organize them under target-triple-specific directories to ensure correct resolution..
1 parent 86cd1df commit c664b02

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

clang/lib/Driver/ToolChains/BareMetal.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@ void BareMetal::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
408408
if (DriverArgs.hasArg(options::OPT_nostdlibinc))
409409
return;
410410

411+
const Driver &D = getDriver();
412+
411413
if (std::optional<std::string> Path = getStdlibIncludePath())
412414
addSystemInclude(DriverArgs, CC1Args, *Path);
413415

@@ -418,6 +420,13 @@ void BareMetal::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
418420
llvm::sys::path::append(Dir, M.includeSuffix());
419421
llvm::sys::path::append(Dir, "include");
420422
addSystemInclude(DriverArgs, CC1Args, Dir.str());
423+
424+
Dir = SysRootDir;
425+
llvm::sys::path::append(Dir, getTripleString());
426+
if (D.getVFS().exists(Dir)) {
427+
llvm::sys::path::append(Dir, "include");
428+
addSystemInclude(DriverArgs, CC1Args, Dir.str());
429+
}
421430
}
422431
}
423432
}
@@ -498,9 +507,13 @@ void BareMetal::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
498507
addSystemInclude(DriverArgs, CC1Args, TargetDir.str());
499508
break;
500509
}
501-
// Add generic path if nothing else succeeded so far.
510+
// Add generic paths if nothing else succeeded so far.
502511
llvm::sys::path::append(Dir, "include", "c++", "v1");
503512
addSystemInclude(DriverArgs, CC1Args, Dir.str());
513+
Dir = SysRootDir;
514+
llvm::sys::path::append(Dir, Target, "include", "c++", "v1");
515+
if (D.getVFS().exists(Dir))
516+
addSystemInclude(DriverArgs, CC1Args, Dir.str());
504517
break;
505518
}
506519
case ToolChain::CST_Libstdcxx: {

0 commit comments

Comments
 (0)