Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 1 | // Copyright 2017 Google Inc. All rights reserved. |
| 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 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
| 18 | "strings" |
| 19 | |
| 20 | "android/soong/android" |
| 21 | ) |
| 22 | |
| 23 | var ( |
Justin Yun | 3e2323d | 2018-06-08 15:08:40 +0900 | [diff] [blame] | 24 | vndkSuffix = ".vndk." |
| 25 | binder32Suffix = ".binder32" |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 26 | ) |
| 27 | |
| 28 | // Creates vndk prebuilts that include the VNDK version. |
| 29 | // |
| 30 | // Example: |
| 31 | // |
Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 32 | // vndk_prebuilt_shared { |
| 33 | // name: "libfoo", |
| 34 | // version: "27", |
| 35 | // target_arch: "arm64", |
| 36 | // vendor_available: true, |
| 37 | // product_available: true, |
| 38 | // vndk: { |
| 39 | // enabled: true, |
| 40 | // }, |
| 41 | // export_include_dirs: ["include/external/libfoo/vndk_include"], |
| 42 | // arch: { |
| 43 | // arm64: { |
| 44 | // srcs: ["arm/lib64/libfoo.so"], |
| 45 | // }, |
| 46 | // arm: { |
| 47 | // srcs: ["arm/lib/libfoo.so"], |
| 48 | // }, |
| 49 | // }, |
| 50 | // } |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 51 | type vndkPrebuiltProperties struct { |
Kiyoung Kim | 9f26fcf | 2024-05-27 17:25:52 +0900 | [diff] [blame^] | 52 | VndkProperties |
| 53 | |
Jae Shin | 43ef264 | 2017-12-29 16:20:21 +0900 | [diff] [blame] | 54 | // VNDK snapshot version. |
| 55 | Version *string |
| 56 | |
SzuWei Lin | 31c4dfc | 2020-11-03 18:27:32 +0800 | [diff] [blame] | 57 | // Target arch name of the snapshot (e.g. 'arm64' for variant 'aosp_arm64') |
Jae Shin | 43ef264 | 2017-12-29 16:20:21 +0900 | [diff] [blame] | 58 | Target_arch *string |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 59 | |
Justin Yun | 3e2323d | 2018-06-08 15:08:40 +0900 | [diff] [blame] | 60 | // If the prebuilt snapshot lib is built with 32 bit binder, this must be set to true. |
| 61 | // The lib with 64 bit binder does not need to set this property. |
| 62 | Binder32bit *bool |
| 63 | |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 64 | // Prebuilt files for each arch. |
| 65 | Srcs []string `android:"arch_variant"` |
Logan Chien | 4fcea3d | 2018-11-20 11:59:08 +0800 | [diff] [blame] | 66 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 67 | // list of flags that will be used for any module that links against this module. |
| 68 | Export_flags []string `android:"arch_variant"` |
| 69 | |
Logan Chien | 4fcea3d | 2018-11-20 11:59:08 +0800 | [diff] [blame] | 70 | // Check the prebuilt ELF files (e.g. DT_SONAME, DT_NEEDED, resolution of undefined symbols, |
| 71 | // etc). |
| 72 | Check_elf_files *bool |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | type vndkPrebuiltLibraryDecorator struct { |
| 76 | *libraryDecorator |
Inseob Kim | 2b96bf5 | 2020-02-17 18:00:39 +0900 | [diff] [blame] | 77 | properties vndkPrebuiltProperties |
| 78 | androidMkSuffix string |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | func (p *vndkPrebuiltLibraryDecorator) Name(name string) string { |
Jae Shin | 43ef264 | 2017-12-29 16:20:21 +0900 | [diff] [blame] | 82 | return name + p.NameSuffix() |
| 83 | } |
| 84 | |
| 85 | func (p *vndkPrebuiltLibraryDecorator) NameSuffix() string { |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 86 | suffix := p.Version() |
Jae Shin | 43ef264 | 2017-12-29 16:20:21 +0900 | [diff] [blame] | 87 | if p.arch() != "" { |
Justin Yun | 3e2323d | 2018-06-08 15:08:40 +0900 | [diff] [blame] | 88 | suffix += "." + p.arch() |
Jae Shin | 43ef264 | 2017-12-29 16:20:21 +0900 | [diff] [blame] | 89 | } |
Justin Yun | 3e2323d | 2018-06-08 15:08:40 +0900 | [diff] [blame] | 90 | if Bool(p.properties.Binder32bit) { |
| 91 | suffix += binder32Suffix |
| 92 | } |
| 93 | return vndkSuffix + suffix |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 94 | } |
| 95 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 96 | func (p *vndkPrebuiltLibraryDecorator) Version() string { |
Jae Shin | 43ef264 | 2017-12-29 16:20:21 +0900 | [diff] [blame] | 97 | return String(p.properties.Version) |
| 98 | } |
| 99 | |
| 100 | func (p *vndkPrebuiltLibraryDecorator) arch() string { |
| 101 | return String(p.properties.Target_arch) |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 102 | } |
| 103 | |
Justin Yun | 3e2323d | 2018-06-08 15:08:40 +0900 | [diff] [blame] | 104 | func (p *vndkPrebuiltLibraryDecorator) binderBit() string { |
| 105 | if Bool(p.properties.Binder32bit) { |
| 106 | return "32" |
| 107 | } |
| 108 | return "64" |
| 109 | } |
| 110 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 111 | func (p *vndkPrebuiltLibraryDecorator) SnapshotAndroidMkSuffix() string { |
Colin Cross | a889080 | 2021-01-22 14:06:33 -0800 | [diff] [blame] | 112 | return ".vendor" |
| 113 | } |
| 114 | |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 115 | func (p *vndkPrebuiltLibraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { |
Jae Shin | 43ef264 | 2017-12-29 16:20:21 +0900 | [diff] [blame] | 116 | p.libraryDecorator.libName = strings.TrimSuffix(ctx.ModuleName(), p.NameSuffix()) |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 117 | return p.libraryDecorator.linkerFlags(ctx, flags) |
| 118 | } |
| 119 | |
| 120 | func (p *vndkPrebuiltLibraryDecorator) singleSourcePath(ctx ModuleContext) android.Path { |
| 121 | if len(p.properties.Srcs) == 0 { |
| 122 | ctx.PropertyErrorf("srcs", "missing prebuilt source file") |
| 123 | return nil |
| 124 | } |
| 125 | |
| 126 | if len(p.properties.Srcs) > 1 { |
| 127 | ctx.PropertyErrorf("srcs", "multiple prebuilt source files") |
| 128 | return nil |
| 129 | } |
| 130 | |
| 131 | return android.PathForModuleSrc(ctx, p.properties.Srcs[0]) |
| 132 | } |
| 133 | |
| 134 | func (p *vndkPrebuiltLibraryDecorator) link(ctx ModuleContext, |
| 135 | flags Flags, deps PathDeps, objs Objects) android.Path { |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 136 | if !p.MatchesWithDevice(ctx.DeviceConfig()) { |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 137 | ctx.Module().HideFromMake() |
Colin Cross | ff6c33d | 2019-10-02 16:01:35 -0700 | [diff] [blame] | 138 | return nil |
| 139 | } |
| 140 | |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 141 | if len(p.properties.Srcs) > 0 && p.shared() { |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 142 | p.libraryDecorator.exportIncludes(ctx) |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 143 | p.libraryDecorator.reexportFlags(p.properties.Export_flags...) |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 144 | // current VNDK prebuilts are only shared libs. |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 145 | |
| 146 | in := p.singleSourcePath(ctx) |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 147 | p.unstrippedOutputFile = in |
| 148 | libName := in.Base() |
Thiébaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 149 | if p.stripper.NeedsStrip(ctx) { |
| 150 | stripFlags := flagsToStripFlags(flags) |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 151 | stripped := android.PathForModuleOut(ctx, "stripped", libName) |
Thiébaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 152 | p.stripper.StripExecutableOrSharedLib(ctx, in, stripped, stripFlags) |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 153 | in = stripped |
| 154 | } |
| 155 | |
| 156 | // Optimize out relinking against shared libraries whose interface hasn't changed by |
| 157 | // depending on a table of contents file instead of the library itself. |
| 158 | tocFile := android.PathForModuleOut(ctx, libName+".toc") |
| 159 | p.tocFile = android.OptionalPathForPath(tocFile) |
Ivan Lozano | 7b0781d | 2021-11-03 15:30:18 -0400 | [diff] [blame] | 160 | TransformSharedObjectToToc(ctx, in, tocFile) |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 161 | |
Inseob Kim | 2b96bf5 | 2020-02-17 18:00:39 +0900 | [diff] [blame] | 162 | p.androidMkSuffix = p.NameSuffix() |
| 163 | |
Colin Cross | 4021302 | 2023-12-13 15:19:49 -0800 | [diff] [blame] | 164 | android.SetProvider(ctx, SharedLibraryInfoProvider, SharedLibraryInfo{ |
Liz Kammer | ef6dfea | 2021-06-08 15:37:09 -0400 | [diff] [blame] | 165 | SharedLibrary: in, |
| 166 | Target: ctx.Target(), |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 167 | |
| 168 | TableOfContents: p.tocFile, |
| 169 | }) |
| 170 | |
Inseob Kim | 70cb3b6 | 2020-10-16 16:23:05 +0900 | [diff] [blame] | 171 | p.libraryDecorator.flagExporter.setProvider(ctx) |
| 172 | |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 173 | return in |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 174 | } |
Colin Cross | ff6c33d | 2019-10-02 16:01:35 -0700 | [diff] [blame] | 175 | |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 176 | ctx.Module().HideFromMake() |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 177 | return nil |
| 178 | } |
| 179 | |
Colin Cross | 4a9e6ec | 2023-12-18 15:29:41 -0800 | [diff] [blame] | 180 | func (p *vndkPrebuiltLibraryDecorator) moduleInfoJSON(ctx ModuleContext, moduleInfoJSON *android.ModuleInfoJSON) { |
| 181 | p.libraryDecorator.moduleInfoJSON(ctx, moduleInfoJSON) |
| 182 | moduleInfoJSON.SubName += p.androidMkSuffix |
| 183 | } |
| 184 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 185 | func (p *vndkPrebuiltLibraryDecorator) MatchesWithDevice(config android.DeviceConfig) bool { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 186 | arches := config.Arches() |
| 187 | if len(arches) == 0 || arches[0].ArchType.String() != p.arch() { |
| 188 | return false |
| 189 | } |
| 190 | if config.BinderBitness() != p.binderBit() { |
| 191 | return false |
| 192 | } |
| 193 | if len(p.properties.Srcs) == 0 { |
| 194 | return false |
| 195 | } |
| 196 | return true |
| 197 | } |
| 198 | |
Inseob Kim | c9fa4a3 | 2019-09-09 10:49:03 +0900 | [diff] [blame] | 199 | func (p *vndkPrebuiltLibraryDecorator) nativeCoverage() bool { |
| 200 | return false |
| 201 | } |
| 202 | |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 203 | func (p *vndkPrebuiltLibraryDecorator) IsSnapshotPrebuilt() bool { |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 204 | return true |
| 205 | } |
| 206 | |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 207 | func (p *vndkPrebuiltLibraryDecorator) install(ctx ModuleContext, file android.Path) { |
Jooyung Han | 261e158 | 2020-10-20 18:54:21 +0900 | [diff] [blame] | 208 | // do not install vndk libs |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | func vndkPrebuiltSharedLibrary() *Module { |
| 212 | module, library := NewLibrary(android.DeviceSupported) |
| 213 | library.BuildOnlyShared() |
| 214 | module.stl = nil |
| 215 | module.sanitize = nil |
Thiébaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 216 | library.disableStripping() |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 217 | |
| 218 | prebuilt := &vndkPrebuiltLibraryDecorator{ |
| 219 | libraryDecorator: library, |
| 220 | } |
| 221 | |
Logan Chien | 4fcea3d | 2018-11-20 11:59:08 +0800 | [diff] [blame] | 222 | prebuilt.properties.Check_elf_files = BoolPtr(false) |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 223 | prebuilt.baseLinker.Properties.No_libcrt = BoolPtr(true) |
| 224 | prebuilt.baseLinker.Properties.Nocrt = BoolPtr(true) |
Kalesh Singh | f4ffe0a | 2024-01-29 13:01:51 -0800 | [diff] [blame] | 225 | prebuilt.baseLinker.Properties.No_crt_pad_segment = BoolPtr(true) |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 226 | |
| 227 | // Prevent default system libs (libc, libm, and libdl) from being linked |
| 228 | if prebuilt.baseLinker.Properties.System_shared_libs == nil { |
| 229 | prebuilt.baseLinker.Properties.System_shared_libs = []string{} |
| 230 | } |
Logan Chien | 4fcea3d | 2018-11-20 11:59:08 +0800 | [diff] [blame] | 231 | |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 232 | module.compiler = nil |
| 233 | module.linker = prebuilt |
| 234 | module.installer = prebuilt |
| 235 | |
| 236 | module.AddProperties( |
| 237 | &prebuilt.properties, |
| 238 | ) |
| 239 | |
| 240 | return module |
| 241 | } |
| 242 | |
Patrice Arruda | ad03150 | 2019-04-01 10:56:49 -0700 | [diff] [blame] | 243 | // vndk_prebuilt_shared installs Vendor Native Development kit (VNDK) snapshot |
| 244 | // shared libraries for system build. Example: |
| 245 | // |
Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 246 | // vndk_prebuilt_shared { |
| 247 | // name: "libfoo", |
| 248 | // version: "27", |
| 249 | // target_arch: "arm64", |
| 250 | // vendor_available: true, |
| 251 | // product_available: true, |
| 252 | // vndk: { |
| 253 | // enabled: true, |
| 254 | // }, |
| 255 | // export_include_dirs: ["include/external/libfoo/vndk_include"], |
| 256 | // arch: { |
| 257 | // arm64: { |
| 258 | // srcs: ["arm/lib64/libfoo.so"], |
| 259 | // }, |
| 260 | // arm: { |
| 261 | // srcs: ["arm/lib/libfoo.so"], |
| 262 | // }, |
| 263 | // }, |
| 264 | // } |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 265 | func VndkPrebuiltSharedFactory() android.Module { |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 266 | module := vndkPrebuiltSharedLibrary() |
| 267 | return module.Init() |
| 268 | } |
| 269 | |
| 270 | func init() { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 271 | android.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory) |
Colin Cross | 7a6fcbe | 2017-12-06 13:08:00 -0800 | [diff] [blame] | 272 | } |
Kiyoung Kim | 9f26fcf | 2024-05-27 17:25:52 +0900 | [diff] [blame^] | 273 | |
| 274 | func IsForVndkApex(mctx android.BottomUpMutatorContext, m *Module) bool { |
| 275 | if !m.Enabled(mctx) { |
| 276 | return true |
| 277 | } |
| 278 | |
| 279 | if p, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok { |
| 280 | return p.MatchesWithDevice(mctx.DeviceConfig()) && Bool(p.properties.Vndk.Enabled) |
| 281 | } |
| 282 | return false |
| 283 | } |