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

Fangrui Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 3 16:06:07 PDT 2022


MaskRay added a comment.

- This patch should be abandoned. Inferring sysroot from gcc-toolchain is backward.
- The D644 <https://reviews.llvm.org/D644> (`Support Sourcery CodeBench MIPS toolchain`) `computeSysRoot` should not be used by new support.
- `--gcc-toolchain=` is discouraged.
- New cross compilation support should specify `--target=` with `--sysroot=` and possibly `--gcc-install-dir=`.
- If a distro wants to just use `--target=`, provide a configuration file.
- Gentoo folks are working on making https://github.com/llvm/llvm-project/issues/57570 less hacky (and eventually the bespoke gcc-config logic).

The following fragment in kernel `tools/scripts/Makefile.include` looks right to me. I don't think it is a workaround. In the future `--gcc-toolchain=` should be replaced with `--gcc-install-dir=`

  else ifneq ($(CROSS_COMPILE),)
  # Allow userspace to override CLANG_CROSS_FLAGS to specify their own
  # sysroots and flags or to avoid the GCC call in pure Clang builds.
  ifeq ($(CLANG_CROSS_FLAGS),)
  CLANG_CROSS_FLAGS := --target=$(notdir $(CROSS_COMPILE:%-=%))
  GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)gcc 2>/dev/null))
  ifneq ($(GCC_TOOLCHAIN_DIR),)
  CLANG_CROSS_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE))
  CLANG_CROSS_FLAGS += --sysroot=$(shell $(CROSS_COMPILE)gcc -print-sysroot)
  CLANG_CROSS_FLAGS += --gcc-toolchain=$(realpath $(GCC_TOOLCHAIN_DIR)/..)
  endif # GCC_TOOLCHAIN_DIR
  endif # CLANG_CROSS_FLAGS
  CFLAGS += $(CLANG_CROSS_FLAGS)
  AFLAGS += $(CLANG_CROSS_FLAGS)
  endif # CROSS_COMPILE


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

https://reviews.llvm.org/D134454



More information about the cfe-commits mailing list