[all-commits] [llvm/llvm-project] ff07c9: [Driver] Unify InstalledDir and Dir (#80527)

Fangrui Song via All-commits all-commits at lists.llvm.org
Wed Feb 28 15:12:44 PST 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: ff07c9b701dc6372f82d989d01768051e848b30d
      https://github.com/llvm/llvm-project/commit/ff07c9b701dc6372f82d989d01768051e848b30d
  Author: Fangrui Song <i at maskray.me>
  Date:   2024-02-28 (Wed, 28 Feb 2024)

  Changed paths:
    M clang/include/clang/Driver/Driver.h
    M clang/test/Driver/darwin-header-search-libcxx.cpp
    M clang/test/Driver/mingw-sysroot.cpp
    M clang/test/Driver/no-canonical-prefixes.c
    M clang/test/Driver/program-path-priority.c
    M clang/test/Driver/rocm-detect.hip
    M clang/tools/driver/driver.cpp

  Log Message:
  -----------
  [Driver] Unify InstalledDir and Dir (#80527)

`Driver::ClangExecutable` is derived from:

* (-canonical-prefixes default): `realpath` on the executable path
* (-no-canonical-prefixes) argv[0] (consult PATH if argv[0] is a word)

`Dir` and `ResourceDir` are derived from `ClangExecutable`. Both
variables are used to derive certain include and library paths.

`InstalledDir` is a related concept used to derive certain other paths.
`InstalledDir` is weird in the -canonical-prefixes mode: Clang
calls `make_absolute` but does not follow symlinks
(FIXME from 9ade6a9a747c49383ac747bd8ffaa6a0beaef71c).
This causes some search and library paths to be mix-and-matched.

The "Do a PATH lookup, if there are no directory components." logic
makes things worse.
`InstalledDir` is different when you invoke it via `PATH`:
```
% which clang
/usr/bin/clang
% clang -v |& grep InstalledDir
InstalledDir: /usr/bin
% /usr/lib/llvm-16/bin/clang -v |& grep InstalledDir
InstalledDir: /usr/lib/llvm-16/bin
```

I believe `InstalledDir` was a partial solution to
`-no-canonical-prefixes` and should be eventually removed.

This patch removes `SetInstallDir` and relies on Driver::Driver to set
`InstalledDir` to `Dir`. The behavior for regular file `clang` or
`-no-canonical-prefixes` is unchanged.

If a user creates a symlink to the regular file `clang` and uses the
default `-canonical-prefixes`, they now consistently get search and
library paths relative to the regular file `clang`, not mix-and-match
paths.

If a user creates a symlink to the regular file `clang` and replaces
some directorys from the actual installation, they should change the
symlink to a wrapper that calls the underlying clang with
`-no-canonical-prefixes`.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list