[PATCH] D134454: [Driver][Distro] Fix ArchLinux sysroot detection

Fangrui Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 30 11:24:08 PDT 2022


MaskRay added a comment.

> While cross-compiling Linux kernel tools with Clang on ArchLinux, it was revealed the sysroot is not properly detected and instead of fixing the root cause in Clang, kernel developers started doing workarounds [1] upon workarounds [2] in the kernel build to be able to pass a working sysroot during Clang invocation.

I disagree that [1] and [2] are workarounds. Figuring out the sysroot and GCC installation directory is the canonical and bullet-proof way to let Clang reuse the glibc/GCC files.
It works for system cross GCC packages as well as user-built cross GCC packages, regardless how sysroot is configured.
Other approaches require file hierarchy detection which is more or less brittle. Some is unavoidable as we want Clang to be a drop-in replacement of GCC.
Unfortunately traditionally we did not set a clear bar and many extended system packages are supported, e.g. the strange mips distribution detection, gentoo-config, RedHat devtools, etc.
Adding such extended support just doesn't scale. Thankfully the main branch has now a fullblown configuration file support (probably with some rough edges) and they can be easily
extended to support a new distribution's bespoke GCC customization.

For the Arch Linux example, what if another distribution claims that they use `/usr/aarch64-linux-gnu/sysroot` and suit them better?
What if it is another directory?

Clang Driver detects a GCC installation in the sysroot, then it is backward to change the sysroot after a GCC installation is found.
Worse, `computeSysroot` result does not completely replace reading the stored `Sysroot` variable.
Some places (e.g. -isysroot, --print-search-dirs) use the `Sysroot` variable.
I am inclined to think that they are correct and what we actually need to fix are mips/Android/CSKY in `Linux::computeSysRoot`.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134454/new/

https://reviews.llvm.org/D134454



More information about the cfe-commits mailing list