llvm / llvm/llvm-project

OHOS driver looks for compiler-rt CRT/builtins in a directory that compiler-rt does not install to

Open
#219,643 0 comments 0 reactions 0 assignees View on GitHub
new issue
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

## Summary

The OpenHarmony driver (`clang/lib/Driver/ToolChains/OHOS.cpp`) searches for `clang_rt.crtbegin.o` / `libclang_rt.builtins.a` under the
"multiarch" spelling **`aarch64-linux-ohos`**, but a self-built compiler-rt installs them under the normalized spelling **`aarch64-unknown-linux-ohos`**. The result is that a self-built clang cannot find its own compiler-rt, and a symlink is required to make it work.

## Description

We were building compiler-rt via the runtimes build and installing it into a clang prefix, then checking what path clang actually searches:

```
$ clang --target=aarch64-linux-ohos -print-target-triple
aarch64-unknown-linux-ohos # compiler-rt installs under this (normalized) name

$ clang -### -rtlib=compiler-rt x.c -o x
.../lib/clang/22/lib/aarch64-linux-ohos/libclang_rt.builtins.a # driver searches this (multiarch) name
```

We found that in `OHOS.cpp`:

- `getMultiarchTriple()` hard-codes the short spelling for aarch64:
```cpp
case llvm::Triple::aarch64:
return "aarch64-linux-ohos";
```
- `getCompilerRT()` and `getArchSpecificLibPaths()` build their search path using **only** `getMultiarchTriple()`:
```cpp
std::string OHOS::getCompilerRT(...) const {
SmallString<128> Path(getDriver().ResourceDir);
llvm::sys::path::append(Path, "lib", getMultiarchTriple(getTriple()), ...);
...
}
```
- Meanwhile compiler-rt's install directory is derived from `COMPILER_RT_DEFAULT_TARGET_TRIPLE`, which the runtimes build normalizes via `clang -print-target-triple` to `aarch64-unknown-linux-ohos`.

Notably, `getRuntimePaths()` in the same file already tries **three** spellings (as-passed, `Triple::str()` normalized, and multiarch) — but `getCompilerRT()` and `getArchSpecificLibPaths()` only try the multiarch spelling.

As a workaround, we created the symlink `lib/clang/22/lib/aarch64-linux-ohos -> aarch64-unknown-linux-ohos`.

**Suggested fix:** make `getCompilerRT()` and `getArchSpecificLibPaths()` also fall back to the normalized triple (and/or the as-passed triple), mirroring what `getRuntimePaths()` already does.

---

We used branch `release/22.x` commit `ca7933e47d3a3451d81e72ac174dcb5aa28b59d1`.

Environment: HarmonyOS 7.0.0.102, `uname -a`: `HarmonyOS localhost HongMeng Kernel 1.13.0 #1 SMP Sat Aug 15 11:19:26 UTC 2026 aarch64 GNU/Linux`

Contributor guide

Open the contributing guide

Research direction

Start in clang/lib/Driver/ToolChains/OHOS.cpp, comparing getCompilerRT() and getArchSpecificLibPaths() with getRuntimePaths() and its three triple spellings. Reproduce with --target=aarch64-linux-ohos -print-target-triple and -### -rtlib=compiler-rt x.c -o x. Done when compiler-rt installed under aarch64-unknown-linux-ohos is found without a symlink while the existing multiarch case still works.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.