Always respect min_sdk_version
Background: When compiling cc_* modules, min_sdk_version determines the "version" part of the clang triple: -target <arch>-linux-android<version>. The version part is used to make sure that calls to the APIs that are added after the version are guarded with a runtime check (i.e. __builtin_available). Previously, min_sdk_version was used as the version part only when the cc_* module is unbundled (e.g. built for an APEX or built with SDK). In other words, min_sdk_version has been ignored for the platform variants. They were built with the version number 10000. This was problematic for Mainline module tests. Since they are neither part of an APEX nor built with SDK (because they need to have access to some of the module-only APIs), they are built with the version number 10000. As a side effect, __builtin_available macro are expanded to 1 at build time - because 10000 is higher than any API versions. When such a test built in the latest platform source tree runs on a device running an old platform, it tries to call an API that might not be available on the platform and experience a crash, due to the lack of the runtime check. This change fixes the problem by using min_sdk_version as the "version" part of the clang triple, regardless of the module's variant. Then __builtin_available macro in the tests doesn't expand to 1, but to a function call to the libclang_rt.builtin library which checks the system property ro.build.version.sdk. Bug: N/A Test: run resolv_stress_test Change-Id: I88f64c5a35f1b5276c3350e177b116932011a940
This commit is contained in:
parent
2b077baa5e
commit
a008fb08cf
2 changed files with 13 additions and 6 deletions
|
@ -3628,6 +3628,18 @@ func TestAidlFlagsPassedToTheAidlCompiler(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestMinSdkVersionInClangTriple(t *testing.T) {
|
||||
ctx := testCc(t, `
|
||||
cc_library_shared {
|
||||
name: "libfoo",
|
||||
srcs: ["foo.c"],
|
||||
min_sdk_version: "29",
|
||||
}`)
|
||||
|
||||
cFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"]
|
||||
android.AssertStringDoesContain(t, "min sdk version", cFlags, "-target aarch64-linux-android29")
|
||||
}
|
||||
|
||||
type MemtagNoteType int
|
||||
|
||||
const (
|
||||
|
|
|
@ -411,12 +411,7 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
|
|||
|
||||
target := "-target " + tc.ClangTriple()
|
||||
if ctx.Os().Class == android.Device {
|
||||
// When built for the non-updateble part of platform, minSdkVersion doesn't matter.
|
||||
// It matters only when building we are building for modules that can be unbundled.
|
||||
version := "current"
|
||||
if !ctx.isForPlatform() || ctx.isSdkVariant() {
|
||||
version = ctx.minSdkVersion()
|
||||
}
|
||||
version := ctx.minSdkVersion()
|
||||
if version == "" || version == "current" {
|
||||
target += strconv.Itoa(android.FutureApiLevelInt)
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue