| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 1 | // 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 |  | 
 | 15 | package cc | 
 | 16 |  | 
 | 17 | import ( | 
| Jiyong Park | f119435 | 2019-02-25 11:05:47 +0900 | [diff] [blame] | 18 | 	"path/filepath" | 
 | 19 |  | 
| Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 20 | 	"github.com/google/blueprint" | 
 | 21 |  | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 22 | 	"android/soong/android" | 
 | 23 | ) | 
 | 24 |  | 
 | 25 | type BinaryLinkerProperties struct { | 
 | 26 | 	// compile executable with -static | 
 | 27 | 	Static_executable *bool `android:"arch_variant"` | 
 | 28 |  | 
 | 29 | 	// set the name of the output | 
| Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 30 | 	Stem *string `android:"arch_variant"` | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 31 |  | 
 | 32 | 	// append to the name of the output | 
| Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 33 | 	Suffix *string `android:"arch_variant"` | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 34 |  | 
 | 35 | 	// if set, add an extra objcopy --prefix-symbols= step | 
| Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 36 | 	Prefix_symbols *string | 
| Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 37 |  | 
 | 38 | 	// if set, install a symlink to the preferred architecture | 
| Roland Levillain | d9bf9be | 2019-06-05 19:20:33 +0100 | [diff] [blame] | 39 | 	Symlink_preferred_arch *bool `android:"arch_variant"` | 
| Colin Cross | 522e373 | 2016-09-07 13:14:06 -0700 | [diff] [blame] | 40 |  | 
| Colin Cross | 9b09f24 | 2016-12-07 13:37:42 -0800 | [diff] [blame] | 41 | 	// install symlinks to the binary.  Symlink names will have the suffix and the binary | 
 | 42 | 	// extension (if any) appended | 
 | 43 | 	Symlinks []string `android:"arch_variant"` | 
 | 44 |  | 
| Colin Cross | 522e373 | 2016-09-07 13:14:06 -0700 | [diff] [blame] | 45 | 	DynamicLinker string `blueprint:"mutated"` | 
| Yifan Hong | 946e32e | 2018-04-03 13:22:50 -0700 | [diff] [blame] | 46 |  | 
 | 47 | 	// Names of modules to be overridden. Listed modules can only be other binaries | 
 | 48 | 	// (in Make or Soong). | 
 | 49 | 	// This does not completely prevent installation of the overridden binaries, but if both | 
 | 50 | 	// binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed | 
 | 51 | 	// from PRODUCT_PACKAGES. | 
 | 52 | 	Overrides []string | 
| Colin Cross | d7227f9 | 2019-09-05 14:26:33 -0700 | [diff] [blame] | 53 |  | 
 | 54 | 	// Inject boringssl hash into the shared library.  This is only intended for use by external/boringssl. | 
 | 55 | 	Inject_bssl_hash *bool `android:"arch_variant"` | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 56 | } | 
 | 57 |  | 
 | 58 | func init() { | 
| Paul Duffin | 2ee6979 | 2020-01-16 12:14:42 +0000 | [diff] [blame] | 59 | 	RegisterBinaryBuildComponents(android.InitRegistrationContext) | 
 | 60 | } | 
 | 61 |  | 
 | 62 | func RegisterBinaryBuildComponents(ctx android.RegistrationContext) { | 
 | 63 | 	ctx.RegisterModuleType("cc_binary", BinaryFactory) | 
 | 64 | 	ctx.RegisterModuleType("cc_binary_host", binaryHostFactory) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 65 | } | 
 | 66 |  | 
| Patrice Arruda | c249c71 | 2019-03-19 17:00:29 -0700 | [diff] [blame] | 67 | // cc_binary produces a binary that is runnable on a device. | 
| Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 68 | func BinaryFactory() android.Module { | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 69 | 	module, _ := NewBinary(android.HostAndDeviceSupported) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 70 | 	return module.Init() | 
 | 71 | } | 
 | 72 |  | 
| Patrice Arruda | c249c71 | 2019-03-19 17:00:29 -0700 | [diff] [blame] | 73 | // cc_binary_host produces a binary that is runnable on a host. | 
| Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 74 | func binaryHostFactory() android.Module { | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 75 | 	module, _ := NewBinary(android.HostSupported) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 76 | 	return module.Init() | 
 | 77 | } | 
 | 78 |  | 
 | 79 | // | 
 | 80 | // Executables | 
 | 81 | // | 
 | 82 |  | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 83 | type binaryDecorator struct { | 
 | 84 | 	*baseLinker | 
| Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 85 | 	*baseInstaller | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 86 | 	stripper | 
 | 87 |  | 
 | 88 | 	Properties BinaryLinkerProperties | 
 | 89 |  | 
| Dan Willemsen | 4aa75ca | 2016-09-28 16:18:03 -0700 | [diff] [blame] | 90 | 	toolPath android.OptionalPath | 
| Colin Cross | 9b09f24 | 2016-12-07 13:37:42 -0800 | [diff] [blame] | 91 |  | 
| Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 92 | 	// Location of the linked, unstripped binary | 
 | 93 | 	unstrippedOutputFile android.Path | 
 | 94 |  | 
| Colin Cross | 9b09f24 | 2016-12-07 13:37:42 -0800 | [diff] [blame] | 95 | 	// Names of symlinks to be installed for use in LOCAL_MODULE_SYMLINKS | 
 | 96 | 	symlinks []string | 
| Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 97 |  | 
 | 98 | 	// Output archive of gcno coverage information | 
 | 99 | 	coverageOutputFile android.OptionalPath | 
| Dan Willemsen | 569edc5 | 2018-11-19 09:33:29 -0800 | [diff] [blame] | 100 |  | 
 | 101 | 	// Location of the file that should be copied to dist dir when requested | 
 | 102 | 	distFile android.OptionalPath | 
| Jiyong Park | f119435 | 2019-02-25 11:05:47 +0900 | [diff] [blame] | 103 |  | 
 | 104 | 	post_install_cmds []string | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 105 | } | 
 | 106 |  | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 107 | var _ linker = (*binaryDecorator)(nil) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 108 |  | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 109 | func (binary *binaryDecorator) linkerProps() []interface{} { | 
| Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 110 | 	return append(binary.baseLinker.linkerProps(), | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 111 | 		&binary.Properties, | 
 | 112 | 		&binary.stripper.StripProperties) | 
 | 113 |  | 
 | 114 | } | 
 | 115 |  | 
| Roland Levillain | 9efb8c7 | 2019-06-05 13:31:31 +0100 | [diff] [blame] | 116 | func (binary *binaryDecorator) getStemWithoutSuffix(ctx BaseModuleContext) string { | 
| Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 117 | 	stem := ctx.baseModuleName() | 
| Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 118 | 	if String(binary.Properties.Stem) != "" { | 
 | 119 | 		stem = String(binary.Properties.Stem) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 120 | 	} | 
 | 121 |  | 
| Roland Levillain | 9efb8c7 | 2019-06-05 13:31:31 +0100 | [diff] [blame] | 122 | 	return stem | 
 | 123 | } | 
 | 124 |  | 
 | 125 | func (binary *binaryDecorator) getStem(ctx BaseModuleContext) string { | 
 | 126 | 	return binary.getStemWithoutSuffix(ctx) + String(binary.Properties.Suffix) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 127 | } | 
 | 128 |  | 
| Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 129 | func (binary *binaryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps { | 
| Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 130 | 	deps = binary.baseLinker.linkerDeps(ctx, deps) | 
| Dan Willemsen | 2e47b34 | 2016-11-17 01:02:25 -0800 | [diff] [blame] | 131 | 	if ctx.toolchain().Bionic() { | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 132 | 		if !Bool(binary.baseLinker.Properties.Nocrt) { | 
| Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 133 | 			if !ctx.useSdk() { | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 134 | 				if binary.static() { | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 135 | 					deps.CrtBegin = "crtbegin_static" | 
 | 136 | 				} else { | 
 | 137 | 					deps.CrtBegin = "crtbegin_dynamic" | 
 | 138 | 				} | 
 | 139 | 				deps.CrtEnd = "crtend_android" | 
 | 140 | 			} else { | 
| Dan Albert | ebedf67 | 2016-11-08 15:06:22 -0800 | [diff] [blame] | 141 | 				// TODO(danalbert): Add generation of crt objects. | 
 | 142 | 				// For `sdk_version: "current"`, we don't actually have a | 
 | 143 | 				// freshly generated set of CRT objects. Use the last stable | 
 | 144 | 				// version. | 
 | 145 | 				version := ctx.sdkVersion() | 
 | 146 | 				if version == "current" { | 
| Jayant Chowdhary | 6e8115a | 2017-05-09 10:21:52 -0700 | [diff] [blame] | 147 | 					version = getCurrentNdkPrebuiltVersion(ctx) | 
| Dan Albert | ebedf67 | 2016-11-08 15:06:22 -0800 | [diff] [blame] | 148 | 				} | 
 | 149 |  | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 150 | 				if binary.static() { | 
| Dan Albert | ebedf67 | 2016-11-08 15:06:22 -0800 | [diff] [blame] | 151 | 					deps.CrtBegin = "ndk_crtbegin_static." + version | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 152 | 				} else { | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 153 | 					if binary.static() { | 
| Dan Albert | ebedf67 | 2016-11-08 15:06:22 -0800 | [diff] [blame] | 154 | 						deps.CrtBegin = "ndk_crtbegin_static." + version | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 155 | 					} else { | 
| Dan Albert | ebedf67 | 2016-11-08 15:06:22 -0800 | [diff] [blame] | 156 | 						deps.CrtBegin = "ndk_crtbegin_dynamic." + version | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 157 | 					} | 
| Dan Albert | ebedf67 | 2016-11-08 15:06:22 -0800 | [diff] [blame] | 158 | 					deps.CrtEnd = "ndk_crtend_android." + version | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 159 | 				} | 
 | 160 | 			} | 
 | 161 | 		} | 
 | 162 |  | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 163 | 		if binary.static() { | 
| Dan Albert | dc2597d | 2017-01-26 17:44:26 -0800 | [diff] [blame] | 164 | 			if ctx.selectedStl() == "libc++_static" { | 
| Ryan Prichard | b49fe1b | 2019-10-11 15:03:34 -0700 | [diff] [blame] | 165 | 				deps.StaticLibs = append(deps.StaticLibs, "libm", "libc") | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 166 | 			} | 
 | 167 | 			// static libraries libcompiler_rt, libc and libc_nomalloc need to be linked with | 
 | 168 | 			// --start-group/--end-group along with libgcc.  If they are in deps.StaticLibs, | 
 | 169 | 			// move them to the beginning of deps.LateStaticLibs | 
 | 170 | 			var groupLibs []string | 
 | 171 | 			deps.StaticLibs, groupLibs = filterList(deps.StaticLibs, | 
 | 172 | 				[]string{"libc", "libc_nomalloc", "libcompiler_rt"}) | 
 | 173 | 			deps.LateStaticLibs = append(groupLibs, deps.LateStaticLibs...) | 
 | 174 | 		} | 
| Dan Willemsen | c77a0b3 | 2017-09-18 23:19:12 -0700 | [diff] [blame] | 175 |  | 
 | 176 | 		if ctx.Os() == android.LinuxBionic && !binary.static() { | 
| Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 177 | 			deps.DynamicLinker = "linker" | 
 | 178 | 			deps.LinkerFlagsFile = "host_bionic_linker_flags" | 
| Dan Willemsen | c77a0b3 | 2017-09-18 23:19:12 -0700 | [diff] [blame] | 179 | 		} | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 180 | 	} | 
 | 181 |  | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 182 | 	if !binary.static() && inList("libc", deps.StaticLibs) { | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 183 | 		ctx.ModuleErrorf("statically linking libc to dynamic executable, please remove libc\n" + | 
 | 184 | 			"from static libs or set static_executable: true") | 
 | 185 | 	} | 
| Colin Cross | 2383f3b | 2018-02-06 14:40:13 -0800 | [diff] [blame] | 186 |  | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 187 | 	return deps | 
 | 188 | } | 
 | 189 |  | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 190 | func (binary *binaryDecorator) isDependencyRoot() bool { | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 191 | 	return true | 
 | 192 | } | 
 | 193 |  | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 194 | func NewBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) { | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 195 | 	module := newModule(hod, android.MultilibFirst) | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 196 | 	binary := &binaryDecorator{ | 
| Dan Albert | 61f3212 | 2018-07-26 14:00:24 -0700 | [diff] [blame] | 197 | 		baseLinker:    NewBaseLinker(module.sanitize), | 
| Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 198 | 		baseInstaller: NewBaseInstaller("bin", "", InstallInSystem), | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 199 | 	} | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 200 | 	module.compiler = NewBaseCompiler() | 
 | 201 | 	module.linker = binary | 
| Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 202 | 	module.installer = binary | 
| Paul Duffin | 25ce04b | 2020-01-16 11:47:25 +0000 | [diff] [blame] | 203 |  | 
 | 204 | 	// Allow module to be added as member of an sdk/module_exports. | 
 | 205 | 	module.sdkMemberTypes = []android.SdkMemberType{ | 
 | 206 | 		ccBinarySdkMemberType, | 
 | 207 | 	} | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 208 | 	return module, binary | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 209 | } | 
 | 210 |  | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 211 | func (binary *binaryDecorator) linkerInit(ctx BaseModuleContext) { | 
| Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 212 | 	binary.baseLinker.linkerInit(ctx) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 213 |  | 
| Dan Willemsen | 2e47b34 | 2016-11-17 01:02:25 -0800 | [diff] [blame] | 214 | 	if !ctx.toolchain().Bionic() { | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 215 | 		if ctx.Os() == android.Linux { | 
| Dan Willemsen | 3fb1fae | 2018-03-12 15:30:26 -0700 | [diff] [blame] | 216 | 			if binary.Properties.Static_executable == nil && ctx.Config().HostStaticBinaries() { | 
| Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 217 | 				binary.Properties.Static_executable = BoolPtr(true) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 218 | 			} | 
| Doug Horn | c32c6b0 | 2019-01-17 14:44:05 -0800 | [diff] [blame] | 219 | 		} else if !ctx.Fuchsia() { | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 220 | 			// Static executables are not supported on Darwin or Windows | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 221 | 			binary.Properties.Static_executable = nil | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 222 | 		} | 
 | 223 | 	} | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 224 | } | 
 | 225 |  | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 226 | func (binary *binaryDecorator) static() bool { | 
 | 227 | 	return Bool(binary.Properties.Static_executable) | 
 | 228 | } | 
 | 229 |  | 
 | 230 | func (binary *binaryDecorator) staticBinary() bool { | 
 | 231 | 	return binary.static() | 
 | 232 | } | 
 | 233 |  | 
 | 234 | func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { | 
| Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 235 | 	flags = binary.baseLinker.linkerFlags(ctx, flags) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 236 |  | 
| Colin Cross | 446c666 | 2018-09-14 16:00:16 -0700 | [diff] [blame] | 237 | 	if ctx.Host() && !ctx.Windows() && !binary.static() { | 
| Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 238 | 		if !ctx.Config().IsEnvTrue("DISABLE_HOST_PIE") { | 
| Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 239 | 			flags.Global.LdFlags = append(flags.Global.LdFlags, "-pie") | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 240 | 		} | 
 | 241 | 	} | 
 | 242 |  | 
 | 243 | 	// MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because | 
 | 244 | 	// all code is position independent, and then those warnings get promoted to | 
 | 245 | 	// errors. | 
| Colin Cross | 3edeee1 | 2017-04-04 12:59:48 -0700 | [diff] [blame] | 246 | 	if !ctx.Windows() { | 
| Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 247 | 		flags.Global.CFlags = append(flags.Global.CFlags, "-fPIE") | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 248 | 	} | 
 | 249 |  | 
| Dan Willemsen | 2e47b34 | 2016-11-17 01:02:25 -0800 | [diff] [blame] | 250 | 	if ctx.toolchain().Bionic() { | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 251 | 		if binary.static() { | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 252 | 			// Clang driver needs -static to create static executable. | 
 | 253 | 			// However, bionic/linker uses -shared to overwrite. | 
 | 254 | 			// Linker for x86 targets does not allow coexistance of -static and -shared, | 
 | 255 | 			// so we add -static only if -shared is not used. | 
| Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 256 | 			if !inList("-shared", flags.Local.LdFlags) { | 
 | 257 | 				flags.Global.LdFlags = append(flags.Global.LdFlags, "-static") | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 258 | 			} | 
 | 259 |  | 
| Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 260 | 			flags.Global.LdFlags = append(flags.Global.LdFlags, | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 261 | 				"-nostdlib", | 
 | 262 | 				"-Bstatic", | 
 | 263 | 				"-Wl,--gc-sections", | 
 | 264 | 			) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 265 | 		} else { | 
 | 266 | 			if flags.DynamicLinker == "" { | 
| Colin Cross | 522e373 | 2016-09-07 13:14:06 -0700 | [diff] [blame] | 267 | 				if binary.Properties.DynamicLinker != "" { | 
 | 268 | 					flags.DynamicLinker = binary.Properties.DynamicLinker | 
 | 269 | 				} else { | 
| Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 270 | 					switch ctx.Os() { | 
 | 271 | 					case android.Android: | 
| Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 272 | 						if ctx.bootstrap() && !ctx.inRecovery() && !ctx.inRamdisk() { | 
| Jiyong Park | a4b9dd0 | 2019-01-16 22:53:13 +0900 | [diff] [blame] | 273 | 							flags.DynamicLinker = "/system/bin/bootstrap/linker" | 
 | 274 | 						} else { | 
 | 275 | 							flags.DynamicLinker = "/system/bin/linker" | 
 | 276 | 						} | 
| Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 277 | 						if flags.Toolchain.Is64Bit() { | 
 | 278 | 							flags.DynamicLinker += "64" | 
 | 279 | 						} | 
| Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 280 | 					case android.LinuxBionic: | 
| Dan Willemsen | c77a0b3 | 2017-09-18 23:19:12 -0700 | [diff] [blame] | 281 | 						flags.DynamicLinker = "" | 
| Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 282 | 					default: | 
 | 283 | 						ctx.ModuleErrorf("unknown dynamic linker") | 
 | 284 | 					} | 
| Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 285 | 				} | 
 | 286 |  | 
 | 287 | 				if ctx.Os() == android.LinuxBionic { | 
 | 288 | 					// Use the dlwrap entry point, but keep _start around so | 
 | 289 | 					// that it can be used by host_bionic_inject | 
| Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 290 | 					flags.Global.LdFlags = append(flags.Global.LdFlags, | 
| Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 291 | 						"-Wl,--entry=__dlwrap__start", | 
 | 292 | 						"-Wl,--undefined=_start", | 
 | 293 | 					) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 294 | 				} | 
 | 295 | 			} | 
 | 296 |  | 
| Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 297 | 			flags.Global.LdFlags = append(flags.Global.LdFlags, | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 298 | 				"-pie", | 
 | 299 | 				"-nostdlib", | 
 | 300 | 				"-Bdynamic", | 
 | 301 | 				"-Wl,--gc-sections", | 
 | 302 | 				"-Wl,-z,nocopyreloc", | 
 | 303 | 			) | 
 | 304 | 		} | 
 | 305 | 	} else { | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 306 | 		if binary.static() { | 
| Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 307 | 			flags.Global.LdFlags = append(flags.Global.LdFlags, "-static") | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 308 | 		} | 
 | 309 | 		if ctx.Darwin() { | 
| Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 310 | 			flags.Global.LdFlags = append(flags.Global.LdFlags, "-Wl,-headerpad_max_install_names") | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 311 | 		} | 
 | 312 | 	} | 
 | 313 |  | 
 | 314 | 	return flags | 
 | 315 | } | 
 | 316 |  | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 317 | func (binary *binaryDecorator) link(ctx ModuleContext, | 
| Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 318 | 	flags Flags, deps PathDeps, objs Objects) android.Path { | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 319 |  | 
 | 320 | 	fileName := binary.getStem(ctx) + flags.Toolchain.ExecutableSuffix() | 
 | 321 | 	outputFile := android.PathForModuleOut(ctx, fileName) | 
 | 322 | 	ret := outputFile | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 323 |  | 
 | 324 | 	var linkerDeps android.Paths | 
 | 325 |  | 
| Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 326 | 	if deps.LinkerFlagsFile.Valid() { | 
| Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 327 | 		flags.Local.LdFlags = append(flags.Local.LdFlags, "$$(cat "+deps.LinkerFlagsFile.String()+")") | 
| Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 328 | 		linkerDeps = append(linkerDeps, deps.LinkerFlagsFile.Path()) | 
| Dan Willemsen | c77a0b3 | 2017-09-18 23:19:12 -0700 | [diff] [blame] | 329 | 	} | 
 | 330 |  | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 331 | 	if flags.DynamicLinker != "" { | 
| Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 332 | 		flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,-dynamic-linker,"+flags.DynamicLinker) | 
| Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 333 | 	} else if ctx.toolchain().Bionic() && !binary.static() { | 
| Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 334 | 		flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--no-dynamic-linker") | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 335 | 	} | 
 | 336 |  | 
 | 337 | 	builderFlags := flagsToBuilderFlags(flags) | 
 | 338 |  | 
 | 339 | 	if binary.stripper.needsStrip(ctx) { | 
| Yi Kong | b5c34d7 | 2018-11-07 16:28:49 -0800 | [diff] [blame] | 340 | 		if ctx.Darwin() { | 
 | 341 | 			builderFlags.stripUseGnuStrip = true | 
 | 342 | 		} | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 343 | 		strippedOutputFile := outputFile | 
 | 344 | 		outputFile = android.PathForModuleOut(ctx, "unstripped", fileName) | 
| Ryan Prichard | f979d73 | 2019-05-30 20:53:29 -0700 | [diff] [blame] | 345 | 		binary.stripper.stripExecutableOrSharedLib(ctx, outputFile, strippedOutputFile, builderFlags) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 346 | 	} | 
 | 347 |  | 
| Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 348 | 	binary.unstrippedOutputFile = outputFile | 
 | 349 |  | 
| Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 350 | 	if String(binary.Properties.Prefix_symbols) != "" { | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 351 | 		afterPrefixSymbols := outputFile | 
 | 352 | 		outputFile = android.PathForModuleOut(ctx, "unprefixed", fileName) | 
| Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 353 | 		TransformBinaryPrefixSymbols(ctx, String(binary.Properties.Prefix_symbols), outputFile, | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 354 | 			flagsToBuilderFlags(flags), afterPrefixSymbols) | 
 | 355 | 	} | 
 | 356 |  | 
| Colin Cross | d7227f9 | 2019-09-05 14:26:33 -0700 | [diff] [blame] | 357 | 	outputFile = maybeInjectBoringSSLHash(ctx, outputFile, binary.Properties.Inject_bssl_hash, fileName) | 
 | 358 |  | 
| Dan Willemsen | 569edc5 | 2018-11-19 09:33:29 -0800 | [diff] [blame] | 359 | 	if Bool(binary.baseLinker.Properties.Use_version_lib) { | 
 | 360 | 		if ctx.Host() { | 
 | 361 | 			versionedOutputFile := outputFile | 
 | 362 | 			outputFile = android.PathForModuleOut(ctx, "unversioned", fileName) | 
 | 363 | 			binary.injectVersionSymbol(ctx, outputFile, versionedOutputFile) | 
 | 364 | 		} else { | 
 | 365 | 			versionedOutputFile := android.PathForModuleOut(ctx, "versioned", fileName) | 
 | 366 | 			binary.distFile = android.OptionalPathForPath(versionedOutputFile) | 
 | 367 |  | 
 | 368 | 			if binary.stripper.needsStrip(ctx) { | 
 | 369 | 				out := android.PathForModuleOut(ctx, "versioned-stripped", fileName) | 
 | 370 | 				binary.distFile = android.OptionalPathForPath(out) | 
| Ryan Prichard | f979d73 | 2019-05-30 20:53:29 -0700 | [diff] [blame] | 371 | 				binary.stripper.stripExecutableOrSharedLib(ctx, versionedOutputFile, out, builderFlags) | 
| Dan Willemsen | 569edc5 | 2018-11-19 09:33:29 -0800 | [diff] [blame] | 372 | 			} | 
 | 373 |  | 
 | 374 | 			binary.injectVersionSymbol(ctx, outputFile, versionedOutputFile) | 
 | 375 | 		} | 
| Colin Cross | 86803cf | 2018-02-15 14:12:26 -0800 | [diff] [blame] | 376 | 	} | 
 | 377 |  | 
| Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 378 | 	if ctx.Os() == android.LinuxBionic && !binary.static() { | 
 | 379 | 		injectedOutputFile := outputFile | 
 | 380 | 		outputFile = android.PathForModuleOut(ctx, "prelinker", fileName) | 
 | 381 |  | 
 | 382 | 		if !deps.DynamicLinker.Valid() { | 
 | 383 | 			panic("Non-static host bionic modules must have a dynamic linker") | 
 | 384 | 		} | 
 | 385 |  | 
 | 386 | 		binary.injectHostBionicLinkerSymbols(ctx, outputFile, deps.DynamicLinker.Path(), injectedOutputFile) | 
 | 387 | 	} | 
 | 388 |  | 
| Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 389 | 	var sharedLibs android.Paths | 
 | 390 | 	// Ignore shared libs for static executables. | 
 | 391 | 	if !binary.static() { | 
| Jiyong Park | 64a44f2 | 2019-01-18 14:37:08 +0900 | [diff] [blame] | 392 | 		sharedLibs = deps.EarlySharedLibs | 
 | 393 | 		sharedLibs = append(sharedLibs, deps.SharedLibs...) | 
| Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 394 | 		sharedLibs = append(sharedLibs, deps.LateSharedLibs...) | 
| Jiyong Park | 64a44f2 | 2019-01-18 14:37:08 +0900 | [diff] [blame] | 395 | 		linkerDeps = append(linkerDeps, deps.EarlySharedLibsDeps...) | 
| Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 396 | 		linkerDeps = append(linkerDeps, deps.SharedLibsDeps...) | 
 | 397 | 		linkerDeps = append(linkerDeps, deps.LateSharedLibsDeps...) | 
 | 398 | 	} | 
 | 399 |  | 
| Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 400 | 	linkerDeps = append(linkerDeps, objs.tidyFiles...) | 
| Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 401 | 	linkerDeps = append(linkerDeps, flags.LdFlagsDeps...) | 
| Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 402 |  | 
| Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 403 | 	TransformObjToDynamicBinary(ctx, objs.objFiles, sharedLibs, deps.StaticLibs, | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 404 | 		deps.LateStaticLibs, deps.WholeStaticLibs, linkerDeps, deps.CrtBegin, deps.CrtEnd, true, | 
| Josh Gao | 75a50a2 | 2019-06-07 17:58:59 -0700 | [diff] [blame] | 405 | 		builderFlags, outputFile, nil) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 406 |  | 
| Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 407 | 	objs.coverageFiles = append(objs.coverageFiles, deps.StaticLibObjs.coverageFiles...) | 
 | 408 | 	objs.coverageFiles = append(objs.coverageFiles, deps.WholeStaticLibObjs.coverageFiles...) | 
| Oliver Nguyen | c743414 | 2019-04-24 14:22:25 -0700 | [diff] [blame] | 409 | 	binary.coverageOutputFile = TransformCoverageFilesToZip(ctx, objs, binary.getStem(ctx)) | 
| Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 410 |  | 
| Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 411 | 	// Need to determine symlinks early since some targets (ie APEX) need this | 
 | 412 | 	// information but will not call 'install' | 
| Colin Cross | 9b09f24 | 2016-12-07 13:37:42 -0800 | [diff] [blame] | 413 | 	for _, symlink := range binary.Properties.Symlinks { | 
 | 414 | 		binary.symlinks = append(binary.symlinks, | 
| Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 415 | 			symlink+String(binary.Properties.Suffix)+ctx.toolchain().ExecutableSuffix()) | 
| Colin Cross | 9b09f24 | 2016-12-07 13:37:42 -0800 | [diff] [blame] | 416 | 	} | 
 | 417 |  | 
| Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 418 | 	if Bool(binary.Properties.Symlink_preferred_arch) { | 
| Roland Levillain | 9efb8c7 | 2019-06-05 13:31:31 +0100 | [diff] [blame] | 419 | 		if String(binary.Properties.Suffix) == "" { | 
 | 420 | 			ctx.PropertyErrorf("symlink_preferred_arch", "must also specify suffix") | 
| Colin Cross | 9b09f24 | 2016-12-07 13:37:42 -0800 | [diff] [blame] | 421 | 		} | 
 | 422 | 		if ctx.TargetPrimary() { | 
| Roland Levillain | 9efb8c7 | 2019-06-05 13:31:31 +0100 | [diff] [blame] | 423 | 			binary.symlinks = append(binary.symlinks, binary.getStemWithoutSuffix(ctx)) | 
| Colin Cross | 9b09f24 | 2016-12-07 13:37:42 -0800 | [diff] [blame] | 424 | 		} | 
 | 425 | 	} | 
 | 426 |  | 
| Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 427 | 	return ret | 
 | 428 | } | 
 | 429 |  | 
| Jiyong Park | af6d895 | 2019-01-31 12:21:23 +0900 | [diff] [blame] | 430 | func (binary *binaryDecorator) unstrippedOutputFilePath() android.Path { | 
 | 431 | 	return binary.unstrippedOutputFile | 
 | 432 | } | 
 | 433 |  | 
| Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 434 | func (binary *binaryDecorator) symlinkList() []string { | 
 | 435 | 	return binary.symlinks | 
 | 436 | } | 
 | 437 |  | 
| Pirama Arumuga Nainar | 65c95ff | 2019-03-25 10:21:31 -0700 | [diff] [blame] | 438 | func (binary *binaryDecorator) nativeCoverage() bool { | 
 | 439 | 	return true | 
 | 440 | } | 
 | 441 |  | 
| Jiyong Park | ee9a98d | 2019-08-09 14:44:36 +0900 | [diff] [blame] | 442 | func (binary *binaryDecorator) coverageOutputFilePath() android.OptionalPath { | 
 | 443 | 	return binary.coverageOutputFile | 
 | 444 | } | 
 | 445 |  | 
| Jiyong Park | f119435 | 2019-02-25 11:05:47 +0900 | [diff] [blame] | 446 | // /system/bin/linker -> /apex/com.android.runtime/bin/linker | 
 | 447 | func (binary *binaryDecorator) installSymlinkToRuntimeApex(ctx ModuleContext, file android.Path) { | 
 | 448 | 	dir := binary.baseInstaller.installDir(ctx) | 
 | 449 | 	dirOnDevice := android.InstallPathToOnDevicePath(ctx, dir) | 
 | 450 | 	target := "/" + filepath.Join("apex", "com.android.runtime", dir.Base(), file.Base()) | 
 | 451 |  | 
 | 452 | 	ctx.InstallAbsoluteSymlink(dir, file.Base(), target) | 
 | 453 | 	binary.post_install_cmds = append(binary.post_install_cmds, makeSymlinkCmd(dirOnDevice, file.Base(), target)) | 
 | 454 |  | 
 | 455 | 	for _, symlink := range binary.symlinks { | 
 | 456 | 		ctx.InstallAbsoluteSymlink(dir, symlink, target) | 
 | 457 | 		binary.post_install_cmds = append(binary.post_install_cmds, makeSymlinkCmd(dirOnDevice, symlink, target)) | 
 | 458 | 	} | 
 | 459 | } | 
 | 460 |  | 
| Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 461 | func (binary *binaryDecorator) install(ctx ModuleContext, file android.Path) { | 
| Jiyong Park | f119435 | 2019-02-25 11:05:47 +0900 | [diff] [blame] | 462 | 	// Bionic binaries (e.g. linker) is installed to the bootstrap subdirectory. | 
 | 463 | 	// The original path becomes a symlink to the corresponding file in the | 
 | 464 | 	// runtime APEX. | 
| Colin Cross | 3b19f5d | 2019-09-17 14:45:31 -0700 | [diff] [blame] | 465 | 	translatedArch := ctx.Target().NativeBridge == android.NativeBridgeEnabled | 
| Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 466 | 	if InstallToBootstrap(ctx.baseModuleName(), ctx.Config()) && !translatedArch && ctx.apexName() == "" && !ctx.inRamdisk() && !ctx.inRecovery() { | 
| Peter Collingbourne | 3478bb2 | 2019-04-24 14:41:12 -0700 | [diff] [blame] | 467 | 		if ctx.Device() && isBionic(ctx.baseModuleName()) { | 
| Jiyong Park | c3e2c86 | 2019-03-16 01:10:08 +0900 | [diff] [blame] | 468 | 			binary.installSymlinkToRuntimeApex(ctx, file) | 
 | 469 | 		} | 
| Jiyong Park | f119435 | 2019-02-25 11:05:47 +0900 | [diff] [blame] | 470 | 		binary.baseInstaller.subDir = "bootstrap" | 
 | 471 | 	} | 
| Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 472 | 	binary.baseInstaller.install(ctx, file) | 
| Colin Cross | 9b09f24 | 2016-12-07 13:37:42 -0800 | [diff] [blame] | 473 | 	for _, symlink := range binary.symlinks { | 
 | 474 | 		ctx.InstallSymlink(binary.baseInstaller.installDir(ctx), symlink, binary.baseInstaller.path) | 
 | 475 | 	} | 
 | 476 |  | 
| Dan Willemsen | 4aa75ca | 2016-09-28 16:18:03 -0700 | [diff] [blame] | 477 | 	if ctx.Os().Class == android.Host { | 
 | 478 | 		binary.toolPath = android.OptionalPathForPath(binary.baseInstaller.path) | 
 | 479 | 	} | 
 | 480 | } | 
 | 481 |  | 
 | 482 | func (binary *binaryDecorator) hostToolPath() android.OptionalPath { | 
 | 483 | 	return binary.toolPath | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 484 | } | 
| Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 485 |  | 
 | 486 | func init() { | 
 | 487 | 	pctx.HostBinToolVariable("hostBionicSymbolsInjectCmd", "host_bionic_inject") | 
 | 488 | } | 
 | 489 |  | 
 | 490 | var injectHostBionicSymbols = pctx.AndroidStaticRule("injectHostBionicSymbols", | 
 | 491 | 	blueprint.RuleParams{ | 
 | 492 | 		Command:     "$hostBionicSymbolsInjectCmd -i $in -l $linker -o $out", | 
 | 493 | 		CommandDeps: []string{"$hostBionicSymbolsInjectCmd"}, | 
 | 494 | 	}, "linker") | 
 | 495 |  | 
 | 496 | func (binary *binaryDecorator) injectHostBionicLinkerSymbols(ctx ModuleContext, in, linker android.Path, out android.WritablePath) { | 
 | 497 | 	ctx.Build(pctx, android.BuildParams{ | 
 | 498 | 		Rule:        injectHostBionicSymbols, | 
 | 499 | 		Description: "inject host bionic symbols", | 
 | 500 | 		Input:       in, | 
 | 501 | 		Implicit:    linker, | 
 | 502 | 		Output:      out, | 
 | 503 | 		Args: map[string]string{ | 
 | 504 | 			"linker": linker.String(), | 
 | 505 | 		}, | 
 | 506 | 	}) | 
 | 507 | } |