blob: 4c863712dca9360876362a634aa5a10eb31c42fc [file] [log] [blame]
Colin Cross4d9c2d12016-07-29 12:48:20 -07001// Copyright 2016 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
15package cc
16
17import (
Dan Willemsena0790e32018-10-12 00:24:23 -070018 "github.com/google/blueprint"
19
Colin Cross4d9c2d12016-07-29 12:48:20 -070020 "android/soong/android"
21)
22
23type BinaryLinkerProperties struct {
24 // compile executable with -static
25 Static_executable *bool `android:"arch_variant"`
26
27 // set the name of the output
Nan Zhang0007d812017-11-07 10:57:05 -080028 Stem *string `android:"arch_variant"`
Colin Cross4d9c2d12016-07-29 12:48:20 -070029
30 // append to the name of the output
Nan Zhang0007d812017-11-07 10:57:05 -080031 Suffix *string `android:"arch_variant"`
Colin Cross4d9c2d12016-07-29 12:48:20 -070032
33 // if set, add an extra objcopy --prefix-symbols= step
Nan Zhang0007d812017-11-07 10:57:05 -080034 Prefix_symbols *string
Colin Cross1e7d3702016-08-24 15:25:47 -070035
36 // if set, install a symlink to the preferred architecture
Nan Zhang0007d812017-11-07 10:57:05 -080037 Symlink_preferred_arch *bool
Colin Cross522e3732016-09-07 13:14:06 -070038
Colin Cross9b09f242016-12-07 13:37:42 -080039 // install symlinks to the binary. Symlink names will have the suffix and the binary
40 // extension (if any) appended
41 Symlinks []string `android:"arch_variant"`
42
Colin Cross522e3732016-09-07 13:14:06 -070043 DynamicLinker string `blueprint:"mutated"`
Yifan Hong946e32e2018-04-03 13:22:50 -070044
45 // Names of modules to be overridden. Listed modules can only be other binaries
46 // (in Make or Soong).
47 // This does not completely prevent installation of the overridden binaries, but if both
48 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
49 // from PRODUCT_PACKAGES.
50 Overrides []string
Colin Cross4d9c2d12016-07-29 12:48:20 -070051}
52
53func init() {
Jiyong Park16e91a02018-12-20 18:18:08 +090054 android.RegisterModuleType("cc_binary", BinaryFactory)
Colin Cross798bfce2016-10-12 14:28:16 -070055 android.RegisterModuleType("cc_binary_host", binaryHostFactory)
Colin Cross4d9c2d12016-07-29 12:48:20 -070056}
57
58// Module factory for binaries
Jiyong Park16e91a02018-12-20 18:18:08 +090059func BinaryFactory() android.Module {
Colin Crossb916a382016-07-29 17:28:03 -070060 module, _ := NewBinary(android.HostAndDeviceSupported)
Colin Cross4d9c2d12016-07-29 12:48:20 -070061 return module.Init()
62}
63
64// Module factory for host binaries
Colin Cross36242852017-06-23 15:06:31 -070065func binaryHostFactory() android.Module {
Colin Crossb916a382016-07-29 17:28:03 -070066 module, _ := NewBinary(android.HostSupported)
Colin Cross4d9c2d12016-07-29 12:48:20 -070067 return module.Init()
68}
69
70//
71// Executables
72//
73
Colin Crossb916a382016-07-29 17:28:03 -070074type binaryDecorator struct {
75 *baseLinker
Colin Cross1e7d3702016-08-24 15:25:47 -070076 *baseInstaller
Colin Cross4d9c2d12016-07-29 12:48:20 -070077 stripper
78
79 Properties BinaryLinkerProperties
80
Dan Willemsen4aa75ca2016-09-28 16:18:03 -070081 toolPath android.OptionalPath
Colin Cross9b09f242016-12-07 13:37:42 -080082
Colin Crossb60190a2018-09-04 16:28:17 -070083 // Location of the linked, unstripped binary
84 unstrippedOutputFile android.Path
85
Colin Cross9b09f242016-12-07 13:37:42 -080086 // Names of symlinks to be installed for use in LOCAL_MODULE_SYMLINKS
87 symlinks []string
Dan Willemsen581341d2017-02-09 16:16:31 -080088
89 // Output archive of gcno coverage information
90 coverageOutputFile android.OptionalPath
Dan Willemsen569edc52018-11-19 09:33:29 -080091
92 // Location of the file that should be copied to dist dir when requested
93 distFile android.OptionalPath
Colin Cross4d9c2d12016-07-29 12:48:20 -070094}
95
Colin Crossb916a382016-07-29 17:28:03 -070096var _ linker = (*binaryDecorator)(nil)
Colin Cross4d9c2d12016-07-29 12:48:20 -070097
Colin Crossb916a382016-07-29 17:28:03 -070098func (binary *binaryDecorator) linkerProps() []interface{} {
Colin Cross42742b82016-08-01 13:20:05 -070099 return append(binary.baseLinker.linkerProps(),
Colin Cross4d9c2d12016-07-29 12:48:20 -0700100 &binary.Properties,
101 &binary.stripper.StripProperties)
102
103}
104
Colin Crossb916a382016-07-29 17:28:03 -0700105func (binary *binaryDecorator) getStem(ctx BaseModuleContext) string {
Colin Crossce75d2c2016-10-06 16:12:58 -0700106 stem := ctx.baseModuleName()
Nan Zhang0007d812017-11-07 10:57:05 -0800107 if String(binary.Properties.Stem) != "" {
108 stem = String(binary.Properties.Stem)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700109 }
110
Nan Zhang0007d812017-11-07 10:57:05 -0800111 return stem + String(binary.Properties.Suffix)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700112}
113
Colin Cross37047f12016-12-13 17:06:13 -0800114func (binary *binaryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
Colin Cross42742b82016-08-01 13:20:05 -0700115 deps = binary.baseLinker.linkerDeps(ctx, deps)
Dan Willemsen2e47b342016-11-17 01:02:25 -0800116 if ctx.toolchain().Bionic() {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700117 if !Bool(binary.baseLinker.Properties.Nocrt) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700118 if !ctx.useSdk() {
Colin Crossb916a382016-07-29 17:28:03 -0700119 if binary.static() {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700120 deps.CrtBegin = "crtbegin_static"
121 } else {
122 deps.CrtBegin = "crtbegin_dynamic"
123 }
124 deps.CrtEnd = "crtend_android"
125 } else {
Dan Albertebedf672016-11-08 15:06:22 -0800126 // TODO(danalbert): Add generation of crt objects.
127 // For `sdk_version: "current"`, we don't actually have a
128 // freshly generated set of CRT objects. Use the last stable
129 // version.
130 version := ctx.sdkVersion()
131 if version == "current" {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -0700132 version = getCurrentNdkPrebuiltVersion(ctx)
Dan Albertebedf672016-11-08 15:06:22 -0800133 }
134
Colin Crossb916a382016-07-29 17:28:03 -0700135 if binary.static() {
Dan Albertebedf672016-11-08 15:06:22 -0800136 deps.CrtBegin = "ndk_crtbegin_static." + version
Colin Cross4d9c2d12016-07-29 12:48:20 -0700137 } else {
Colin Crossb916a382016-07-29 17:28:03 -0700138 if binary.static() {
Dan Albertebedf672016-11-08 15:06:22 -0800139 deps.CrtBegin = "ndk_crtbegin_static." + version
Colin Cross4d9c2d12016-07-29 12:48:20 -0700140 } else {
Dan Albertebedf672016-11-08 15:06:22 -0800141 deps.CrtBegin = "ndk_crtbegin_dynamic." + version
Colin Cross4d9c2d12016-07-29 12:48:20 -0700142 }
Dan Albertebedf672016-11-08 15:06:22 -0800143 deps.CrtEnd = "ndk_crtend_android." + version
Colin Cross4d9c2d12016-07-29 12:48:20 -0700144 }
145 }
146 }
147
Colin Crossb916a382016-07-29 17:28:03 -0700148 if binary.static() {
Dan Albertdc2597d2017-01-26 17:44:26 -0800149 if ctx.selectedStl() == "libc++_static" {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700150 deps.StaticLibs = append(deps.StaticLibs, "libm", "libc", "libdl")
151 }
152 // static libraries libcompiler_rt, libc and libc_nomalloc need to be linked with
153 // --start-group/--end-group along with libgcc. If they are in deps.StaticLibs,
154 // move them to the beginning of deps.LateStaticLibs
155 var groupLibs []string
156 deps.StaticLibs, groupLibs = filterList(deps.StaticLibs,
157 []string{"libc", "libc_nomalloc", "libcompiler_rt"})
158 deps.LateStaticLibs = append(groupLibs, deps.LateStaticLibs...)
159 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700160
161 if ctx.Os() == android.LinuxBionic && !binary.static() {
Dan Willemsena0790e32018-10-12 00:24:23 -0700162 deps.DynamicLinker = "linker"
163 deps.LinkerFlagsFile = "host_bionic_linker_flags"
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700164 }
Colin Cross4d9c2d12016-07-29 12:48:20 -0700165 }
166
Colin Crossb916a382016-07-29 17:28:03 -0700167 if !binary.static() && inList("libc", deps.StaticLibs) {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700168 ctx.ModuleErrorf("statically linking libc to dynamic executable, please remove libc\n" +
169 "from static libs or set static_executable: true")
170 }
Colin Cross2383f3b2018-02-06 14:40:13 -0800171
Colin Cross4d9c2d12016-07-29 12:48:20 -0700172 return deps
173}
174
Colin Crossb916a382016-07-29 17:28:03 -0700175func (binary *binaryDecorator) isDependencyRoot() bool {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700176 return true
177}
178
Colin Crossb916a382016-07-29 17:28:03 -0700179func NewBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700180 module := newModule(hod, android.MultilibFirst)
Colin Crossb916a382016-07-29 17:28:03 -0700181 binary := &binaryDecorator{
Dan Albert61f32122018-07-26 14:00:24 -0700182 baseLinker: NewBaseLinker(module.sanitize),
Colin Cross1e7d3702016-08-24 15:25:47 -0700183 baseInstaller: NewBaseInstaller("bin", "", InstallInSystem),
Colin Cross4d9c2d12016-07-29 12:48:20 -0700184 }
Colin Crossb916a382016-07-29 17:28:03 -0700185 module.compiler = NewBaseCompiler()
186 module.linker = binary
Colin Cross1e7d3702016-08-24 15:25:47 -0700187 module.installer = binary
Colin Crossb916a382016-07-29 17:28:03 -0700188 return module, binary
Colin Cross4d9c2d12016-07-29 12:48:20 -0700189}
190
Colin Crossb916a382016-07-29 17:28:03 -0700191func (binary *binaryDecorator) linkerInit(ctx BaseModuleContext) {
Colin Cross42742b82016-08-01 13:20:05 -0700192 binary.baseLinker.linkerInit(ctx)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700193
Dan Willemsen2e47b342016-11-17 01:02:25 -0800194 if !ctx.toolchain().Bionic() {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700195 if ctx.Os() == android.Linux {
Dan Willemsen3fb1fae2018-03-12 15:30:26 -0700196 if binary.Properties.Static_executable == nil && ctx.Config().HostStaticBinaries() {
Nan Zhang0007d812017-11-07 10:57:05 -0800197 binary.Properties.Static_executable = BoolPtr(true)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700198 }
Doug Hornc32c6b02019-01-17 14:44:05 -0800199 } else if !ctx.Fuchsia() {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700200 // Static executables are not supported on Darwin or Windows
Colin Crossb916a382016-07-29 17:28:03 -0700201 binary.Properties.Static_executable = nil
Colin Cross4d9c2d12016-07-29 12:48:20 -0700202 }
203 }
Colin Cross4d9c2d12016-07-29 12:48:20 -0700204}
205
Colin Crossb916a382016-07-29 17:28:03 -0700206func (binary *binaryDecorator) static() bool {
207 return Bool(binary.Properties.Static_executable)
208}
209
210func (binary *binaryDecorator) staticBinary() bool {
211 return binary.static()
212}
213
214func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
Colin Cross42742b82016-08-01 13:20:05 -0700215 flags = binary.baseLinker.linkerFlags(ctx, flags)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700216
Colin Cross446c6662018-09-14 16:00:16 -0700217 if ctx.Host() && !ctx.Windows() && !binary.static() {
Colin Cross6510f912017-11-29 00:27:14 -0800218 if !ctx.Config().IsEnvTrue("DISABLE_HOST_PIE") {
Colin Cross7a108bc2017-01-30 22:44:19 -0800219 flags.LdFlags = append(flags.LdFlags, "-pie")
Colin Cross4d9c2d12016-07-29 12:48:20 -0700220 }
221 }
222
223 // MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because
224 // all code is position independent, and then those warnings get promoted to
225 // errors.
Colin Cross3edeee12017-04-04 12:59:48 -0700226 if !ctx.Windows() {
Vishwath Mohane87b7682017-04-17 16:21:41 -0700227 flags.CFlags = append(flags.CFlags, "-fPIE")
Colin Cross4d9c2d12016-07-29 12:48:20 -0700228 }
229
Dan Willemsen2e47b342016-11-17 01:02:25 -0800230 if ctx.toolchain().Bionic() {
Colin Crossb916a382016-07-29 17:28:03 -0700231 if binary.static() {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700232 // Clang driver needs -static to create static executable.
233 // However, bionic/linker uses -shared to overwrite.
234 // Linker for x86 targets does not allow coexistance of -static and -shared,
235 // so we add -static only if -shared is not used.
236 if !inList("-shared", flags.LdFlags) {
237 flags.LdFlags = append(flags.LdFlags, "-static")
238 }
239
240 flags.LdFlags = append(flags.LdFlags,
241 "-nostdlib",
242 "-Bstatic",
243 "-Wl,--gc-sections",
244 )
Colin Cross4d9c2d12016-07-29 12:48:20 -0700245 } else {
246 if flags.DynamicLinker == "" {
Colin Cross522e3732016-09-07 13:14:06 -0700247 if binary.Properties.DynamicLinker != "" {
248 flags.DynamicLinker = binary.Properties.DynamicLinker
249 } else {
Dan Willemsen01a405a2016-06-13 17:19:03 -0700250 switch ctx.Os() {
251 case android.Android:
252 flags.DynamicLinker = "/system/bin/linker"
Dan Willemsena0790e32018-10-12 00:24:23 -0700253 if flags.Toolchain.Is64Bit() {
254 flags.DynamicLinker += "64"
255 }
Dan Willemsen01a405a2016-06-13 17:19:03 -0700256 case android.LinuxBionic:
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700257 flags.DynamicLinker = ""
Dan Willemsen01a405a2016-06-13 17:19:03 -0700258 default:
259 ctx.ModuleErrorf("unknown dynamic linker")
260 }
Dan Willemsena0790e32018-10-12 00:24:23 -0700261 }
262
263 if ctx.Os() == android.LinuxBionic {
264 // Use the dlwrap entry point, but keep _start around so
265 // that it can be used by host_bionic_inject
266 flags.LdFlags = append(flags.LdFlags,
267 "-Wl,--entry=__dlwrap__start",
268 "-Wl,--undefined=_start",
269 )
Colin Cross4d9c2d12016-07-29 12:48:20 -0700270 }
271 }
272
273 flags.LdFlags = append(flags.LdFlags,
274 "-pie",
275 "-nostdlib",
276 "-Bdynamic",
277 "-Wl,--gc-sections",
278 "-Wl,-z,nocopyreloc",
279 )
280 }
281 } else {
Colin Crossb916a382016-07-29 17:28:03 -0700282 if binary.static() {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700283 flags.LdFlags = append(flags.LdFlags, "-static")
284 }
285 if ctx.Darwin() {
286 flags.LdFlags = append(flags.LdFlags, "-Wl,-headerpad_max_install_names")
287 }
288 }
289
290 return flags
291}
292
Colin Crossb916a382016-07-29 17:28:03 -0700293func (binary *binaryDecorator) link(ctx ModuleContext,
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700294 flags Flags, deps PathDeps, objs Objects) android.Path {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700295
296 fileName := binary.getStem(ctx) + flags.Toolchain.ExecutableSuffix()
297 outputFile := android.PathForModuleOut(ctx, fileName)
298 ret := outputFile
Colin Cross4d9c2d12016-07-29 12:48:20 -0700299
300 var linkerDeps android.Paths
301
Dan Willemsena0790e32018-10-12 00:24:23 -0700302 if deps.LinkerFlagsFile.Valid() {
303 flags.LdFlags = append(flags.LdFlags, "$$(cat "+deps.LinkerFlagsFile.String()+")")
304 linkerDeps = append(linkerDeps, deps.LinkerFlagsFile.Path())
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700305 }
306
Colin Cross4d9c2d12016-07-29 12:48:20 -0700307 if flags.DynamicLinker != "" {
Dan Willemsena0790e32018-10-12 00:24:23 -0700308 flags.LdFlags = append(flags.LdFlags, "-Wl,-dynamic-linker,"+flags.DynamicLinker)
309 } else if ctx.toolchain().Bionic() && !binary.static() {
310 flags.LdFlags = append(flags.LdFlags, "-Wl,--no-dynamic-linker")
Colin Cross4d9c2d12016-07-29 12:48:20 -0700311 }
312
313 builderFlags := flagsToBuilderFlags(flags)
314
315 if binary.stripper.needsStrip(ctx) {
Chih-Hung Hsieh30485c92018-06-04 10:37:43 -0700316 // b/80093681, GNU strip/objcopy bug.
317 // Use llvm-{strip,objcopy} when clang lld is used.
Dan Willemsen8536d6b2018-10-07 20:54:34 -0700318 builderFlags.stripUseLlvmStrip = binary.baseLinker.useClangLld(ctx)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700319 strippedOutputFile := outputFile
320 outputFile = android.PathForModuleOut(ctx, "unstripped", fileName)
321 binary.stripper.strip(ctx, outputFile, strippedOutputFile, builderFlags)
322 }
323
Colin Crossb60190a2018-09-04 16:28:17 -0700324 binary.unstrippedOutputFile = outputFile
325
Nan Zhang0007d812017-11-07 10:57:05 -0800326 if String(binary.Properties.Prefix_symbols) != "" {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700327 afterPrefixSymbols := outputFile
328 outputFile = android.PathForModuleOut(ctx, "unprefixed", fileName)
Nan Zhang0007d812017-11-07 10:57:05 -0800329 TransformBinaryPrefixSymbols(ctx, String(binary.Properties.Prefix_symbols), outputFile,
Colin Cross4d9c2d12016-07-29 12:48:20 -0700330 flagsToBuilderFlags(flags), afterPrefixSymbols)
331 }
332
Dan Willemsen569edc52018-11-19 09:33:29 -0800333 if Bool(binary.baseLinker.Properties.Use_version_lib) {
334 if ctx.Host() {
335 versionedOutputFile := outputFile
336 outputFile = android.PathForModuleOut(ctx, "unversioned", fileName)
337 binary.injectVersionSymbol(ctx, outputFile, versionedOutputFile)
338 } else {
339 versionedOutputFile := android.PathForModuleOut(ctx, "versioned", fileName)
340 binary.distFile = android.OptionalPathForPath(versionedOutputFile)
341
342 if binary.stripper.needsStrip(ctx) {
343 out := android.PathForModuleOut(ctx, "versioned-stripped", fileName)
344 binary.distFile = android.OptionalPathForPath(out)
345 binary.stripper.strip(ctx, versionedOutputFile, out, builderFlags)
346 }
347
348 binary.injectVersionSymbol(ctx, outputFile, versionedOutputFile)
349 }
Colin Cross86803cf2018-02-15 14:12:26 -0800350 }
351
Dan Willemsena0790e32018-10-12 00:24:23 -0700352 if ctx.Os() == android.LinuxBionic && !binary.static() {
353 injectedOutputFile := outputFile
354 outputFile = android.PathForModuleOut(ctx, "prelinker", fileName)
355
356 if !deps.DynamicLinker.Valid() {
357 panic("Non-static host bionic modules must have a dynamic linker")
358 }
359
360 binary.injectHostBionicLinkerSymbols(ctx, outputFile, deps.DynamicLinker.Path(), injectedOutputFile)
361 }
362
Jaewoong Jung232c07c2018-12-18 11:08:25 -0800363 var sharedLibs android.Paths
364 // Ignore shared libs for static executables.
365 if !binary.static() {
Jiyong Park64a44f22019-01-18 14:37:08 +0900366 sharedLibs = deps.EarlySharedLibs
367 sharedLibs = append(sharedLibs, deps.SharedLibs...)
Jaewoong Jung232c07c2018-12-18 11:08:25 -0800368 sharedLibs = append(sharedLibs, deps.LateSharedLibs...)
Jiyong Park64a44f22019-01-18 14:37:08 +0900369 linkerDeps = append(linkerDeps, deps.EarlySharedLibsDeps...)
Jaewoong Jung232c07c2018-12-18 11:08:25 -0800370 linkerDeps = append(linkerDeps, deps.SharedLibsDeps...)
371 linkerDeps = append(linkerDeps, deps.LateSharedLibsDeps...)
372 }
373
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700374 linkerDeps = append(linkerDeps, objs.tidyFiles...)
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700375 linkerDeps = append(linkerDeps, flags.LdFlagsDeps...)
Colin Cross26c34ed2016-09-30 17:10:16 -0700376
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700377 TransformObjToDynamicBinary(ctx, objs.objFiles, sharedLibs, deps.StaticLibs,
Colin Cross4d9c2d12016-07-29 12:48:20 -0700378 deps.LateStaticLibs, deps.WholeStaticLibs, linkerDeps, deps.CrtBegin, deps.CrtEnd, true,
379 builderFlags, outputFile)
380
Dan Willemsen581341d2017-02-09 16:16:31 -0800381 objs.coverageFiles = append(objs.coverageFiles, deps.StaticLibObjs.coverageFiles...)
382 objs.coverageFiles = append(objs.coverageFiles, deps.WholeStaticLibObjs.coverageFiles...)
383 binary.coverageOutputFile = TransformCoverageFilesToLib(ctx, objs, builderFlags, binary.getStem(ctx))
384
Alex Light3d673592019-01-18 14:37:31 -0800385 // Need to determine symlinks early since some targets (ie APEX) need this
386 // information but will not call 'install'
Colin Cross9b09f242016-12-07 13:37:42 -0800387 for _, symlink := range binary.Properties.Symlinks {
388 binary.symlinks = append(binary.symlinks,
Nan Zhang0007d812017-11-07 10:57:05 -0800389 symlink+String(binary.Properties.Suffix)+ctx.toolchain().ExecutableSuffix())
Colin Cross9b09f242016-12-07 13:37:42 -0800390 }
391
Nan Zhang0007d812017-11-07 10:57:05 -0800392 if Bool(binary.Properties.Symlink_preferred_arch) {
393 if String(binary.Properties.Stem) == "" && String(binary.Properties.Suffix) == "" {
Colin Cross9b09f242016-12-07 13:37:42 -0800394 ctx.PropertyErrorf("symlink_preferred_arch", "must also specify stem or suffix")
395 }
396 if ctx.TargetPrimary() {
397 binary.symlinks = append(binary.symlinks, ctx.baseModuleName())
398 }
399 }
400
Alex Light3d673592019-01-18 14:37:31 -0800401 return ret
402}
403
404func (binary *binaryDecorator) symlinkList() []string {
405 return binary.symlinks
406}
407
408func (binary *binaryDecorator) install(ctx ModuleContext, file android.Path) {
409 binary.baseInstaller.install(ctx, file)
Colin Cross9b09f242016-12-07 13:37:42 -0800410 for _, symlink := range binary.symlinks {
411 ctx.InstallSymlink(binary.baseInstaller.installDir(ctx), symlink, binary.baseInstaller.path)
412 }
413
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700414 if ctx.Os().Class == android.Host {
415 binary.toolPath = android.OptionalPathForPath(binary.baseInstaller.path)
416 }
417}
418
419func (binary *binaryDecorator) hostToolPath() android.OptionalPath {
420 return binary.toolPath
Colin Cross4d9c2d12016-07-29 12:48:20 -0700421}
Dan Willemsena0790e32018-10-12 00:24:23 -0700422
423func init() {
424 pctx.HostBinToolVariable("hostBionicSymbolsInjectCmd", "host_bionic_inject")
425}
426
427var injectHostBionicSymbols = pctx.AndroidStaticRule("injectHostBionicSymbols",
428 blueprint.RuleParams{
429 Command: "$hostBionicSymbolsInjectCmd -i $in -l $linker -o $out",
430 CommandDeps: []string{"$hostBionicSymbolsInjectCmd"},
431 }, "linker")
432
433func (binary *binaryDecorator) injectHostBionicLinkerSymbols(ctx ModuleContext, in, linker android.Path, out android.WritablePath) {
434 ctx.Build(pctx, android.BuildParams{
435 Rule: injectHostBionicSymbols,
436 Description: "inject host bionic symbols",
437 Input: in,
438 Implicit: linker,
439 Output: out,
440 Args: map[string]string{
441 "linker": linker.String(),
442 },
443 })
444}