Page MenuHomePhabricator

Fall back on Android triple w/o API level for runtimes search
ClosedPublic

Authored by collinbaker on Dec 3 2021, 9:23 AM.

Details

Summary

Clang searches for runtimes (e.g. libclang_rt*) first in a
subdirectory named for the target triple (corresponding to
LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON), then if it's not found uses
.../lib/<os>/libclang_rt* with a suffix corresponding to the arch and
environment name.

Android triples optionally include an API level indicating the minimum
Android version to be run on
(e.g. aarch64-unknown-linux-android21). When compiler-rt is built with
LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON this API level is part of the
output path.

Linking code built for a later API level against a runtime built for
an earlier one is safe. In projects with several API level targets
this is desireable to avoid re-building the same runtimes many
times. This is difficult with the current runtime search method: if
the API levels don't exactly match Clang gives up on the per-target
runtime directory path.

To enable this more simply, this change tries target triple without
the API level before falling back on the old layout.

Another option would be to try every API level in the triple,
e.g. check aarch-64-unknown-linux-android21, then ...20, then ...19,
etc.

Diff Detail

Event Timeline

collinbaker created this revision.Dec 3 2021, 9:23 AM
collinbaker requested review of this revision.Dec 3 2021, 9:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 3 2021, 9:23 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Fix variable name style

Looks like this breaks tests on Windows: https://buildkite.com/llvm-project/premerge-checks/builds/68330#746376c2-ce48-4ffc-b60f-515619dee28c

Failed Tests (2):

Clang :: Driver/ve-toolchain.c
Clang :: Driver/ve-toolchain.cpp

This looks right to me.

clang/lib/Driver/Driver.cpp
1874

This either needs to print all of them, or the first existing one. The first existing one sounds right actually. Currently it only prints the first one if the first one exists.

clang/lib/Driver/ToolChain.cpp
500

Why do you need the environment check?

501

leftover debug logging

danalbert accepted this revision.Dec 10 2021, 1:58 PM
danalbert added a subscriber: danalbert.

LGTM once the comments are addressed. (I'd also approve the alternative approach discussed in the thread of searching each older API level directory, but have no preference one way or the other)

This revision is now accepted and ready to land.Dec 10 2021, 1:58 PM
  • Address comments
  • Fix VEToolchain build error
  • Rebase
collinbaker marked 2 inline comments as done.Dec 13 2021, 11:48 AM
collinbaker added inline comments.
clang/lib/Driver/ToolChain.cpp
500

This skips adding an extra path if the triple doesn't have an Android API level.

E.g. for the target triple aarch64-unknown-linux-android23, the environment name will be "android23". The condition will be true since "android23" != "android", and the extra path will be appended. If it had just been "android" it'll skip this step.

This revision was landed with ongoing or failed builds.Wed, Jan 5, 1:08 PM
This revision was automatically updated to reflect the committed changes.