Skip to content

[clang][driver] Cleanup UEFI toolchain driver #111473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions clang/lib/Basic/Targets/X86.h
Original file line number Diff line number Diff line change
Expand Up @@ -826,11 +826,6 @@ class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo
"i64:64-i128:128-f80:128-n8:16:32:64-S128");
}

void getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const override {
getOSDefines(Opts, X86TargetInfo::getTriple(), Builder);
}

BuiltinVaListKind getBuiltinVaListKind() const override {
return TargetInfo::CharPtrBuiltinVaList;
}
Expand Down
18 changes: 18 additions & 0 deletions clang/lib/Driver/ToolChains/UEFI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ UEFI::UEFI(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)

Tool *UEFI::buildLinker() const { return new tools::uefi::Linker(*this); }

void UEFI::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
if (DriverArgs.hasArg(options::OPT_nostdinc))
return;

if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
SmallString<128> Dir(getDriver().ResourceDir);
llvm::sys::path::append(Dir, "include");
addSystemInclude(DriverArgs, CC1Args, Dir.str());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petrhosek -- Introduced this to include headers from clang resource directory. Rest of this method implementation is copied from Baremetal driver without much thought. PTAL.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fine so long as it includes lib/<triple/ and lib/clang/20/lib/<triple>. Do we have an existing clang driver UEFI target test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a minimal test here: https://github.com/llvm/llvm-project/blob/main/clang/test/Driver/uefi-constructed-args.c

This is the header search paths with this PR. My original goal of this change was to remove /usr/include and /usr/local/include from the search list.

[hi on] prabhukr@prabhukr:~/llvm-builds/b2$ ./bin/clang -E -v --target=x86_64-uefi - < /dev/null
Fuchsia clang version 20.0.0git ([email protected]:prabhuk/llvm-project.git e30c180214f2ca102ba6fcf1b542db7c5f2ac5fd)
Target: x86_64-unknown-uefi
Thread model: posix
InstalledDir: /usr/local/google/home/prabhukr/llvm-builds/b2/bin
Build config: +assertions
 (in-process)
 "/usr/local/google/home/prabhukr/llvm-builds/b2/bin/llvm" "clang" -cc1 -triple x86_64-unknown-uefi -E -disable-free -clear-ast-before-backend -main-file-name - -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/usr/local/google/home/prabhukr/llvm-builds/b2 -v -fcoverage-compilation-dir=/usr/local/google/home/prabhukr/llvm-builds/b2 -resource-dir /usr/local/google/home/prabhukr/llvm-builds/b2/lib/clang/20 -internal-isystem /usr/local/google/home/prabhukr/llvm-builds/b2/lib/clang/20/include -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -faddrsig -o - -x c -
clang -cc1 version 20.0.0git based upon LLVM 20.0.0git default target x86_64-unknown-linux-gnu
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/google/home/prabhukr/llvm-builds/b2/lib/clang/20/include
End of search list.
# 1 "<stdin>"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 389 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "<stdin>" 2

}

if (DriverArgs.hasArg(options::OPT_nostdlibinc))
return;

if (std::optional<std::string> Path = getStdlibIncludePath())
addSystemInclude(DriverArgs, CC1Args, *Path);
}

void tools::uefi::Linker::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfo &Output,
const InputInfoList &Inputs,
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Driver/ToolChains/UEFI.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class LLVM_LIBRARY_VISIBILITY UEFI : public ToolChain {
return false;
}
bool isPICDefaultForced() const override { return true; }

void
AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;
};

} // namespace toolchains
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Lex/InitHeaderSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ bool InitHeaderSearch::ShouldAddDefaultIncludePaths(
case llvm::Triple::PS5:
case llvm::Triple::RTEMS:
case llvm::Triple::Solaris:
case llvm::Triple::UEFI:
case llvm::Triple::WASI:
case llvm::Triple::ZOS:
return false;
Expand Down
Loading