blob: 4e64dcfda0aa00be1ced35c4c4143bceb18f3923 [file] [log] [blame]
Colin Cross1f7f3bd2016-07-27 10:12:38 -07001// Copyright (C) 2016 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package art
16
17import (
18 "android/soong"
19 "android/soong/android"
20 "android/soong/cc"
21 "fmt"
22
23 "github.com/google/blueprint"
24)
25
26var supportedArches = []string{"arm", "arm64", "mips", "mips64", "x86", "x86_64"}
27
28func globalFlags(ctx android.BaseContext) ([]string, []string) {
29 var cflags []string
30 var asflags []string
31
32 tlab := false
33
34 gcType := envDefault(ctx, "ART_DEFAULT_GC_TYPE", "CMS")
35
36 if envTrue(ctx, "ART_TEST_DEBUG_GC") {
37 gcType = "SS"
38 tlab = true
39 }
40
41 cflags = append(cflags, "-DART_DEFAULT_GC_TYPE_IS_"+gcType)
42 if tlab {
43 cflags = append(cflags, "-DART_USE_TLAB=1")
44 }
45
46 imtSize := envDefault(ctx, "ART_IMT_SIZE", "43")
47 cflags = append(cflags, "-DIMT_SIZE="+imtSize)
48
49 if envTrue(ctx, "ART_HEAP_POISONING") {
50 cflags = append(cflags, "-DART_HEAP_POISONING=1")
51 asflags = append(asflags, "-DART_HEAP_POISONING=1")
52 }
53
54 if envTrue(ctx, "ART_USE_READ_BARRIER") {
55 // Used to change the read barrier type. Valid values are BAKER, BROOKS, TABLELOOKUP.
56 // The default is BAKER.
57 barrierType := envDefault(ctx, "ART_READ_BARRIER_TYPE", "BAKER")
58 cflags = append(cflags,
59 "-DART_USE_READ_BARRIER=1",
60 "-DART_READ_BARRIER_TYPE_IS_"+barrierType+"=1")
61 asflags = append(asflags,
62 "-DART_USE_READ_BARRIER=1",
63 "-DART_READ_BARRIER_TYPE_IS_"+barrierType+"=1")
64
65 // Temporarily override -fstack-protector-strong with -fstack-protector to avoid a major
66 // slowdown with the read barrier config. b/26744236.
67 cflags = append(cflags, "-fstack-protector")
68 }
69
70 return cflags, asflags
71}
72
73func deviceFlags(ctx android.BaseContext) []string {
74 var cflags []string
75 deviceFrameSizeLimit := 1736
76 if len(ctx.AConfig().SanitizeDevice()) > 0 {
77 deviceFrameSizeLimit = 6400
78 }
79 cflags = append(cflags,
80 fmt.Sprintf("-Wframe-larger-than=%d", deviceFrameSizeLimit),
81 fmt.Sprintf("-DART_FRAME_SIZE_LIMIT=%d", deviceFrameSizeLimit),
82 )
83
84 cflags = append(cflags, "-DART_BASE_ADDRESS="+ctx.AConfig().LibartImgDeviceBaseAddress())
85 if envTrue(ctx, "ART_TARGET_LINUX") {
86 cflags = append(cflags, "-DART_TARGET_LINUX")
87 } else {
88 cflags = append(cflags, "-DART_TARGET_ANDROID")
89 }
90 minDelta := envDefault(ctx, "LIBART_IMG_TARGET_MIN_BASE_ADDRESS_DELTA", "-0x1000000")
91 maxDelta := envDefault(ctx, "LIBART_IMG_TARGET_MAX_BASE_ADDRESS_DELTA", "0x1000000")
92 cflags = append(cflags, "-DART_BASE_ADDRESS_MIN_DELTA="+minDelta)
93 cflags = append(cflags, "-DART_BASE_ADDRESS_MAX_DELTA="+maxDelta)
94
95 return cflags
96}
97
98func hostFlags(ctx android.BaseContext) []string {
99 var cflags []string
100 hostFrameSizeLimit := 1736
101 cflags = append(cflags,
102 fmt.Sprintf("-Wframe-larger-than=%d", hostFrameSizeLimit),
103 fmt.Sprintf("-DART_FRAME_SIZE_LIMIT=%d", hostFrameSizeLimit),
104 )
105
106 cflags = append(cflags, "-DART_BASE_ADDRESS="+ctx.AConfig().LibartImgHostBaseAddress())
107 minDelta := envDefault(ctx, "LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA", "-0x1000000")
108 maxDelta := envDefault(ctx, "LIBART_IMG_HOST_MAX_BASE_ADDRESS_DELTA", "0x1000000")
109 cflags = append(cflags, "-DART_BASE_ADDRESS_MIN_DELTA="+minDelta)
110 cflags = append(cflags, "-DART_BASE_ADDRESS_MAX_DELTA="+maxDelta)
111
112 return cflags
113}
114
115func (a *artGlobalDefaults) CustomizeProperties(ctx android.CustomizePropertiesContext) {
116 type props struct {
117 Target struct {
118 Android struct {
119 Cflags []string
120 }
121 Host struct {
122 Cflags []string
123 }
124 }
125 Cflags []string
126 Asflags []string
127 }
128
129 p := &props{}
130 p.Cflags, p.Asflags = globalFlags(ctx)
131 p.Target.Android.Cflags = deviceFlags(ctx)
132 p.Target.Host.Cflags = hostFlags(ctx)
133 ctx.AppendProperties(p)
134}
135
136type artGlobalDefaults struct{}
137
138func init() {
139 soong.RegisterModuleType("art_cc_library", artLibrary)
140 soong.RegisterModuleType("art_cc_defaults", artDefaultsFactory)
141 soong.RegisterModuleType("art_global_defaults", artGlobalDefaultsFactory)
142}
143
144func artGlobalDefaultsFactory() (blueprint.Module, []interface{}) {
145 c := &artGlobalDefaults{}
146 module, props := artDefaultsFactory()
147 android.AddCustomizer(module.(android.Module), c)
148
149 return module, props
150}
151
152func artDefaultsFactory() (blueprint.Module, []interface{}) {
153 c := &codegenCustomizer{}
154 module, props := cc.DefaultsFactory(&c.codegenProperties)
155 android.AddCustomizer(module.(android.Module), c)
156
157 return module, props
158}
159
160func artLibrary() (blueprint.Module, []interface{}) {
161 library, _ := cc.NewLibrary(android.HostAndDeviceSupported, true, true)
162 module, props := library.Init()
163
164 c := &codegenCustomizer{}
165 android.AddCustomizer(library, c)
166 props = append(props, &c.codegenProperties)
167 return module, props
168}
169
170func envDefault(ctx android.BaseContext, key string, defaultValue string) string {
171 ret := ctx.AConfig().Getenv(key)
172 if ret == "" {
173 return defaultValue
174 }
175 return ret
176}
177
178func envTrue(ctx android.BaseContext, key string) bool {
179 return ctx.AConfig().Getenv(key) == "true"
180}