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 | |
Chris Parsons | e0f2ab3 | 2020-11-20 17:27:25 -0500 | [diff] [blame] | 45 | // override the dynamic linker |
Colin Cross | 522e373 | 2016-09-07 13:14:06 -0700 | [diff] [blame] | 46 | DynamicLinker string `blueprint:"mutated"` |
Yifan Hong | 946e32e | 2018-04-03 13:22:50 -0700 | [diff] [blame] | 47 | |
| 48 | // Names of modules to be overridden. Listed modules can only be other binaries |
| 49 | // (in Make or Soong). |
| 50 | // This does not completely prevent installation of the overridden binaries, but if both |
| 51 | // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed |
| 52 | // from PRODUCT_PACKAGES. |
| 53 | Overrides []string |
Colin Cross | d7227f9 | 2019-09-05 14:26:33 -0700 | [diff] [blame] | 54 | |
| 55 | // Inject boringssl hash into the shared library. This is only intended for use by external/boringssl. |
| 56 | Inject_bssl_hash *bool `android:"arch_variant"` |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | func init() { |
Paul Duffin | 2ee6979 | 2020-01-16 12:14:42 +0000 | [diff] [blame] | 60 | RegisterBinaryBuildComponents(android.InitRegistrationContext) |
| 61 | } |
| 62 | |
| 63 | func RegisterBinaryBuildComponents(ctx android.RegistrationContext) { |
| 64 | ctx.RegisterModuleType("cc_binary", BinaryFactory) |
| 65 | ctx.RegisterModuleType("cc_binary_host", binaryHostFactory) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Patrice Arruda | c249c71 | 2019-03-19 17:00:29 -0700 | [diff] [blame] | 68 | // cc_binary produces a binary that is runnable on a device. |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 69 | func BinaryFactory() android.Module { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 70 | module, _ := NewBinary(android.HostAndDeviceSupported) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 71 | return module.Init() |
| 72 | } |
| 73 | |
Patrice Arruda | c249c71 | 2019-03-19 17:00:29 -0700 | [diff] [blame] | 74 | // cc_binary_host produces a binary that is runnable on a host. |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 75 | func binaryHostFactory() android.Module { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 76 | module, _ := NewBinary(android.HostSupported) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 77 | return module.Init() |
| 78 | } |
| 79 | |
| 80 | // |
| 81 | // Executables |
| 82 | // |
| 83 | |
Chris Parsons | e0f2ab3 | 2020-11-20 17:27:25 -0500 | [diff] [blame] | 84 | // binaryDecorator is a decorator containing information for C++ binary modules. |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 85 | type binaryDecorator struct { |
| 86 | *baseLinker |
Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 87 | *baseInstaller |
ThiƩbaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 88 | stripper Stripper |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 89 | |
| 90 | Properties BinaryLinkerProperties |
| 91 | |
Dan Willemsen | 4aa75ca | 2016-09-28 16:18:03 -0700 | [diff] [blame] | 92 | toolPath android.OptionalPath |
Colin Cross | 9b09f24 | 2016-12-07 13:37:42 -0800 | [diff] [blame] | 93 | |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 94 | // Location of the linked, unstripped binary |
| 95 | unstrippedOutputFile android.Path |
| 96 | |
Colin Cross | 9b09f24 | 2016-12-07 13:37:42 -0800 | [diff] [blame] | 97 | // Names of symlinks to be installed for use in LOCAL_MODULE_SYMLINKS |
| 98 | symlinks []string |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 99 | |
Colin Cross | a615901 | 2020-11-12 12:14:36 -0800 | [diff] [blame] | 100 | // If the module has symlink_preferred_arch set, the name of the symlink to the |
| 101 | // binary for the preferred arch. |
| 102 | preferredArchSymlink string |
| 103 | |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 104 | // Output archive of gcno coverage information |
| 105 | coverageOutputFile android.OptionalPath |
Dan Willemsen | 569edc5 | 2018-11-19 09:33:29 -0800 | [diff] [blame] | 106 | |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 107 | // Location of the files that should be copied to dist dir when requested |
| 108 | distFiles android.TaggedDistFiles |
Jiyong Park | f119435 | 2019-02-25 11:05:47 +0900 | [diff] [blame] | 109 | |
Chris Parsons | e0f2ab3 | 2020-11-20 17:27:25 -0500 | [diff] [blame] | 110 | // Action command lines to run directly after the binary is installed. For example, |
| 111 | // may be used to symlink runtime dependencies (such as bionic) alongside installation. |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 112 | postInstallCmds []string |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 115 | var _ linker = (*binaryDecorator)(nil) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 116 | |
Chris Parsons | e0f2ab3 | 2020-11-20 17:27:25 -0500 | [diff] [blame] | 117 | // linkerProps returns the list of individual properties objects relevant |
| 118 | // for this binary. |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 119 | func (binary *binaryDecorator) linkerProps() []interface{} { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 120 | return append(binary.baseLinker.linkerProps(), |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 121 | &binary.Properties, |
| 122 | &binary.stripper.StripProperties) |
| 123 | |
| 124 | } |
| 125 | |
Chris Parsons | e0f2ab3 | 2020-11-20 17:27:25 -0500 | [diff] [blame] | 126 | // getStemWithoutSuffix returns the main section of the name to use for the symlink of |
| 127 | // the main output file of this binary module. This may be derived from the module name |
| 128 | // or other property overrides. |
| 129 | // For the full symlink name, the `Suffix` property of a binary module must be appended. |
Roland Levillain | 9efb8c7 | 2019-06-05 13:31:31 +0100 | [diff] [blame] | 130 | func (binary *binaryDecorator) getStemWithoutSuffix(ctx BaseModuleContext) string { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 131 | stem := ctx.baseModuleName() |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 132 | if String(binary.Properties.Stem) != "" { |
| 133 | stem = String(binary.Properties.Stem) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Roland Levillain | 9efb8c7 | 2019-06-05 13:31:31 +0100 | [diff] [blame] | 136 | return stem |
| 137 | } |
| 138 | |
Chris Parsons | e0f2ab3 | 2020-11-20 17:27:25 -0500 | [diff] [blame] | 139 | // getStem returns the full name to use for the symlink of the main output file of this binary |
| 140 | // module. This may be derived from the module name and/or other property overrides. |
Roland Levillain | 9efb8c7 | 2019-06-05 13:31:31 +0100 | [diff] [blame] | 141 | func (binary *binaryDecorator) getStem(ctx BaseModuleContext) string { |
| 142 | return binary.getStemWithoutSuffix(ctx) + String(binary.Properties.Suffix) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Chris Parsons | e0f2ab3 | 2020-11-20 17:27:25 -0500 | [diff] [blame] | 145 | // linkerDeps augments and returns the given `deps` to contain dependencies on |
| 146 | // modules common to most binaries, such as bionic libraries. |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 147 | func (binary *binaryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 148 | deps = binary.baseLinker.linkerDeps(ctx, deps) |
Colin Cross | d1a2813 | 2021-06-21 17:34:47 -0700 | [diff] [blame] | 149 | if !Bool(binary.baseLinker.Properties.Nocrt) { |
| 150 | if binary.static() { |
| 151 | deps.CrtBegin = ctx.toolchain().CrtBeginStaticBinary() |
| 152 | deps.CrtEnd = ctx.toolchain().CrtEndStaticBinary() |
| 153 | } else { |
| 154 | deps.CrtBegin = ctx.toolchain().CrtBeginSharedBinary() |
| 155 | deps.CrtEnd = ctx.toolchain().CrtEndSharedBinary() |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 156 | } |
Colin Cross | d1a2813 | 2021-06-21 17:34:47 -0700 | [diff] [blame] | 157 | } |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 158 | |
Colin Cross | 450744e | 2021-08-18 13:52:09 -0700 | [diff] [blame^] | 159 | if binary.static() { |
| 160 | deps.StaticLibs = append(deps.StaticLibs, deps.SystemSharedLibs...) |
| 161 | } |
| 162 | |
Colin Cross | d1a2813 | 2021-06-21 17:34:47 -0700 | [diff] [blame] | 163 | if ctx.toolchain().Bionic() { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 164 | if binary.static() { |
Dan Albert | dc2597d | 2017-01-26 17:44:26 -0800 | [diff] [blame] | 165 | if ctx.selectedStl() == "libc++_static" { |
Ryan Prichard | b49fe1b | 2019-10-11 15:03:34 -0700 | [diff] [blame] | 166 | deps.StaticLibs = append(deps.StaticLibs, "libm", "libc") |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 167 | } |
| 168 | // static libraries libcompiler_rt, libc and libc_nomalloc need to be linked with |
| 169 | // --start-group/--end-group along with libgcc. If they are in deps.StaticLibs, |
| 170 | // move them to the beginning of deps.LateStaticLibs |
| 171 | var groupLibs []string |
| 172 | deps.StaticLibs, groupLibs = filterList(deps.StaticLibs, |
| 173 | []string{"libc", "libc_nomalloc", "libcompiler_rt"}) |
| 174 | deps.LateStaticLibs = append(groupLibs, deps.LateStaticLibs...) |
| 175 | } |
Dan Willemsen | c77a0b3 | 2017-09-18 23:19:12 -0700 | [diff] [blame] | 176 | |
| 177 | if ctx.Os() == android.LinuxBionic && !binary.static() { |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 178 | deps.DynamicLinker = "linker" |
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 | |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 182 | if !binary.static() && inList("libc", deps.StaticLibs) && !ctx.BazelConversionMode() { |
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 | |
Chris Parsons | e0f2ab3 | 2020-11-20 17:27:25 -0500 | [diff] [blame] | 190 | // NewBinary builds and returns a new Module corresponding to a C++ binary. |
| 191 | // Individual module implementations which comprise a C++ binary should call this function, |
| 192 | // set some fields on the result, and then call the Init function. |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 193 | func NewBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 194 | module := newModule(hod, android.MultilibFirst) |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 195 | binary := &binaryDecorator{ |
Dan Albert | 61f3212 | 2018-07-26 14:00:24 -0700 | [diff] [blame] | 196 | baseLinker: NewBaseLinker(module.sanitize), |
Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 197 | baseInstaller: NewBaseInstaller("bin", "", InstallInSystem), |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 198 | } |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 199 | module.compiler = NewBaseCompiler() |
| 200 | module.linker = binary |
Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 201 | module.installer = binary |
Paul Duffin | 25ce04b | 2020-01-16 11:47:25 +0000 | [diff] [blame] | 202 | |
| 203 | // Allow module to be added as member of an sdk/module_exports. |
| 204 | module.sdkMemberTypes = []android.SdkMemberType{ |
| 205 | ccBinarySdkMemberType, |
| 206 | } |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 207 | return module, binary |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Chris Parsons | e0f2ab3 | 2020-11-20 17:27:25 -0500 | [diff] [blame] | 210 | // linkerInit initializes dynamic properties of the linker (such as runpath) based |
| 211 | // on properties of this binary. |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 212 | func (binary *binaryDecorator) linkerInit(ctx BaseModuleContext) { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 213 | binary.baseLinker.linkerInit(ctx) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 214 | |
Dan Willemsen | 2e47b34 | 2016-11-17 01:02:25 -0800 | [diff] [blame] | 215 | if !ctx.toolchain().Bionic() { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 216 | if ctx.Os() == android.Linux { |
Chris Parsons | e0f2ab3 | 2020-11-20 17:27:25 -0500 | [diff] [blame] | 217 | // Unless explicitly specified otherwise, host static binaries are built with -static |
| 218 | // if HostStaticBinaries is true for the product configuration. |
Dan Willemsen | 3fb1fae | 2018-03-12 15:30:26 -0700 | [diff] [blame] | 219 | if binary.Properties.Static_executable == nil && ctx.Config().HostStaticBinaries() { |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 220 | binary.Properties.Static_executable = BoolPtr(true) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 221 | } |
Colin Cross | cb0ac95 | 2021-07-20 13:17:15 -0700 | [diff] [blame] | 222 | } else { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 223 | // Static executables are not supported on Darwin or Windows |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 224 | binary.Properties.Static_executable = nil |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 225 | } |
| 226 | } |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 229 | func (binary *binaryDecorator) static() bool { |
| 230 | return Bool(binary.Properties.Static_executable) |
| 231 | } |
| 232 | |
| 233 | func (binary *binaryDecorator) staticBinary() bool { |
| 234 | return binary.static() |
| 235 | } |
| 236 | |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 237 | func (binary *binaryDecorator) binary() bool { |
| 238 | return true |
| 239 | } |
| 240 | |
Chris Parsons | e0f2ab3 | 2020-11-20 17:27:25 -0500 | [diff] [blame] | 241 | // linkerFlags returns a Flags object containing linker flags that are defined |
| 242 | // by this binary, or that are implied by attributes of this binary. These flags are |
| 243 | // combined with the given flags. |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 244 | func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 245 | flags = binary.baseLinker.linkerFlags(ctx, flags) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 246 | |
Chris Parsons | e0f2ab3 | 2020-11-20 17:27:25 -0500 | [diff] [blame] | 247 | // Passing -pie to clang for Windows binaries causes a warning that -pie is unused. |
Colin Cross | 446c666 | 2018-09-14 16:00:16 -0700 | [diff] [blame] | 248 | if ctx.Host() && !ctx.Windows() && !binary.static() { |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 249 | if !ctx.Config().IsEnvTrue("DISABLE_HOST_PIE") { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 250 | flags.Global.LdFlags = append(flags.Global.LdFlags, "-pie") |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | |
| 254 | // MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because |
| 255 | // all code is position independent, and then those warnings get promoted to |
| 256 | // errors. |
Colin Cross | 3edeee1 | 2017-04-04 12:59:48 -0700 | [diff] [blame] | 257 | if !ctx.Windows() { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 258 | flags.Global.CFlags = append(flags.Global.CFlags, "-fPIE") |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Dan Willemsen | 2e47b34 | 2016-11-17 01:02:25 -0800 | [diff] [blame] | 261 | if ctx.toolchain().Bionic() { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 262 | if binary.static() { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 263 | // Clang driver needs -static to create static executable. |
| 264 | // However, bionic/linker uses -shared to overwrite. |
| 265 | // Linker for x86 targets does not allow coexistance of -static and -shared, |
| 266 | // so we add -static only if -shared is not used. |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 267 | if !inList("-shared", flags.Local.LdFlags) { |
| 268 | flags.Global.LdFlags = append(flags.Global.LdFlags, "-static") |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 271 | flags.Global.LdFlags = append(flags.Global.LdFlags, |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 272 | "-nostdlib", |
| 273 | "-Bstatic", |
| 274 | "-Wl,--gc-sections", |
| 275 | ) |
Chris Parsons | e0f2ab3 | 2020-11-20 17:27:25 -0500 | [diff] [blame] | 276 | } else { // not static |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 277 | if flags.DynamicLinker == "" { |
Colin Cross | 522e373 | 2016-09-07 13:14:06 -0700 | [diff] [blame] | 278 | if binary.Properties.DynamicLinker != "" { |
| 279 | flags.DynamicLinker = binary.Properties.DynamicLinker |
| 280 | } else { |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 281 | switch ctx.Os() { |
| 282 | case android.Android: |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 283 | if ctx.bootstrap() && !ctx.inRecovery() && !ctx.inRamdisk() && !ctx.inVendorRamdisk() { |
Jiyong Park | a4b9dd0 | 2019-01-16 22:53:13 +0900 | [diff] [blame] | 284 | flags.DynamicLinker = "/system/bin/bootstrap/linker" |
| 285 | } else { |
| 286 | flags.DynamicLinker = "/system/bin/linker" |
| 287 | } |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 288 | if flags.Toolchain.Is64Bit() { |
| 289 | flags.DynamicLinker += "64" |
| 290 | } |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 291 | case android.LinuxBionic: |
Dan Willemsen | c77a0b3 | 2017-09-18 23:19:12 -0700 | [diff] [blame] | 292 | flags.DynamicLinker = "" |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 293 | default: |
| 294 | ctx.ModuleErrorf("unknown dynamic linker") |
| 295 | } |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | if ctx.Os() == android.LinuxBionic { |
| 299 | // Use the dlwrap entry point, but keep _start around so |
| 300 | // that it can be used by host_bionic_inject |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 301 | flags.Global.LdFlags = append(flags.Global.LdFlags, |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 302 | "-Wl,--entry=__dlwrap__start", |
| 303 | "-Wl,--undefined=_start", |
| 304 | ) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 305 | } |
| 306 | } |
| 307 | |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 308 | flags.Global.LdFlags = append(flags.Global.LdFlags, |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 309 | "-pie", |
| 310 | "-nostdlib", |
| 311 | "-Bdynamic", |
| 312 | "-Wl,--gc-sections", |
| 313 | "-Wl,-z,nocopyreloc", |
| 314 | ) |
| 315 | } |
Chris Parsons | e0f2ab3 | 2020-11-20 17:27:25 -0500 | [diff] [blame] | 316 | } else { // not bionic |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 317 | if binary.static() { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 318 | flags.Global.LdFlags = append(flags.Global.LdFlags, "-static") |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 319 | } |
| 320 | if ctx.Darwin() { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 321 | flags.Global.LdFlags = append(flags.Global.LdFlags, "-Wl,-headerpad_max_install_names") |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | |
| 325 | return flags |
| 326 | } |
| 327 | |
Chris Parsons | e0f2ab3 | 2020-11-20 17:27:25 -0500 | [diff] [blame] | 328 | // link registers actions to link this binary, and sets various fields |
| 329 | // on this binary to reflect information that should be exported up the build |
| 330 | // tree (for example, exported flags and include paths). |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 331 | func (binary *binaryDecorator) link(ctx ModuleContext, |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 332 | flags Flags, deps PathDeps, objs Objects) android.Path { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 333 | |
| 334 | fileName := binary.getStem(ctx) + flags.Toolchain.ExecutableSuffix() |
| 335 | outputFile := android.PathForModuleOut(ctx, fileName) |
| 336 | ret := outputFile |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 337 | |
| 338 | var linkerDeps android.Paths |
| 339 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 340 | if flags.DynamicLinker != "" { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 341 | flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,-dynamic-linker,"+flags.DynamicLinker) |
Colin Cross | 528d67e | 2021-07-23 22:23:07 +0000 | [diff] [blame] | 342 | } else if (ctx.toolchain().Bionic() || ctx.toolchain().Musl()) && !binary.static() { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 343 | flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--no-dynamic-linker") |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | builderFlags := flagsToBuilderFlags(flags) |
ThiƩbaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 347 | stripFlags := flagsToStripFlags(flags) |
| 348 | if binary.stripper.NeedsStrip(ctx) { |
Yi Kong | b5c34d7 | 2018-11-07 16:28:49 -0800 | [diff] [blame] | 349 | if ctx.Darwin() { |
ThiƩbaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 350 | stripFlags.StripUseGnuStrip = true |
Yi Kong | b5c34d7 | 2018-11-07 16:28:49 -0800 | [diff] [blame] | 351 | } |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 352 | strippedOutputFile := outputFile |
| 353 | outputFile = android.PathForModuleOut(ctx, "unstripped", fileName) |
ThiƩbaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 354 | binary.stripper.StripExecutableOrSharedLib(ctx, outputFile, strippedOutputFile, stripFlags) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 355 | } |
| 356 | |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 357 | binary.unstrippedOutputFile = outputFile |
| 358 | |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 359 | if String(binary.Properties.Prefix_symbols) != "" { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 360 | afterPrefixSymbols := outputFile |
| 361 | outputFile = android.PathForModuleOut(ctx, "unprefixed", fileName) |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 362 | transformBinaryPrefixSymbols(ctx, String(binary.Properties.Prefix_symbols), outputFile, |
ThiƩbaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 363 | builderFlags, afterPrefixSymbols) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Colin Cross | d7227f9 | 2019-09-05 14:26:33 -0700 | [diff] [blame] | 366 | outputFile = maybeInjectBoringSSLHash(ctx, outputFile, binary.Properties.Inject_bssl_hash, fileName) |
| 367 | |
Chris Parsons | e0f2ab3 | 2020-11-20 17:27:25 -0500 | [diff] [blame] | 368 | // If use_version_lib is true, make an android::build::GetBuildNumber() function available. |
Dan Willemsen | 569edc5 | 2018-11-19 09:33:29 -0800 | [diff] [blame] | 369 | if Bool(binary.baseLinker.Properties.Use_version_lib) { |
| 370 | if ctx.Host() { |
| 371 | versionedOutputFile := outputFile |
| 372 | outputFile = android.PathForModuleOut(ctx, "unversioned", fileName) |
| 373 | binary.injectVersionSymbol(ctx, outputFile, versionedOutputFile) |
| 374 | } else { |
Chris Parsons | e0f2ab3 | 2020-11-20 17:27:25 -0500 | [diff] [blame] | 375 | // When dist'ing a library or binary that has use_version_lib set, always |
| 376 | // distribute the stamped version, even for the device. |
Dan Willemsen | 569edc5 | 2018-11-19 09:33:29 -0800 | [diff] [blame] | 377 | versionedOutputFile := android.PathForModuleOut(ctx, "versioned", fileName) |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 378 | binary.distFiles = android.MakeDefaultDistFiles(versionedOutputFile) |
Dan Willemsen | 569edc5 | 2018-11-19 09:33:29 -0800 | [diff] [blame] | 379 | |
ThiƩbaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 380 | if binary.stripper.NeedsStrip(ctx) { |
Dan Willemsen | 569edc5 | 2018-11-19 09:33:29 -0800 | [diff] [blame] | 381 | out := android.PathForModuleOut(ctx, "versioned-stripped", fileName) |
Jingwen Chen | 40fd90a | 2020-06-15 05:24:19 +0000 | [diff] [blame] | 382 | binary.distFiles = android.MakeDefaultDistFiles(out) |
ThiƩbaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 383 | binary.stripper.StripExecutableOrSharedLib(ctx, versionedOutputFile, out, stripFlags) |
Dan Willemsen | 569edc5 | 2018-11-19 09:33:29 -0800 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | binary.injectVersionSymbol(ctx, outputFile, versionedOutputFile) |
| 387 | } |
Colin Cross | 86803cf | 2018-02-15 14:12:26 -0800 | [diff] [blame] | 388 | } |
| 389 | |
Colin Cross | f04eb99 | 2021-06-11 15:22:41 -0700 | [diff] [blame] | 390 | var validations android.WritablePaths |
| 391 | |
Chris Parsons | e0f2ab3 | 2020-11-20 17:27:25 -0500 | [diff] [blame] | 392 | // Handle host bionic linker symbols. |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 393 | if ctx.Os() == android.LinuxBionic && !binary.static() { |
Colin Cross | f04eb99 | 2021-06-11 15:22:41 -0700 | [diff] [blame] | 394 | verifyFile := android.PathForModuleOut(ctx, "host_bionic_verify.stamp") |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 395 | |
| 396 | if !deps.DynamicLinker.Valid() { |
| 397 | panic("Non-static host bionic modules must have a dynamic linker") |
| 398 | } |
| 399 | |
Colin Cross | f04eb99 | 2021-06-11 15:22:41 -0700 | [diff] [blame] | 400 | binary.verifyHostBionicLinker(ctx, outputFile, deps.DynamicLinker.Path(), verifyFile) |
| 401 | validations = append(validations, verifyFile) |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 404 | var sharedLibs android.Paths |
| 405 | // Ignore shared libs for static executables. |
| 406 | if !binary.static() { |
Jiyong Park | 64a44f2 | 2019-01-18 14:37:08 +0900 | [diff] [blame] | 407 | sharedLibs = deps.EarlySharedLibs |
| 408 | sharedLibs = append(sharedLibs, deps.SharedLibs...) |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 409 | sharedLibs = append(sharedLibs, deps.LateSharedLibs...) |
Jiyong Park | 64a44f2 | 2019-01-18 14:37:08 +0900 | [diff] [blame] | 410 | linkerDeps = append(linkerDeps, deps.EarlySharedLibsDeps...) |
Jaewoong Jung | 232c07c | 2018-12-18 11:08:25 -0800 | [diff] [blame] | 411 | linkerDeps = append(linkerDeps, deps.SharedLibsDeps...) |
| 412 | linkerDeps = append(linkerDeps, deps.LateSharedLibsDeps...) |
| 413 | } |
| 414 | |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 415 | linkerDeps = append(linkerDeps, objs.tidyFiles...) |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 416 | linkerDeps = append(linkerDeps, flags.LdFlagsDeps...) |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 417 | |
Chris Parsons | e0f2ab3 | 2020-11-20 17:27:25 -0500 | [diff] [blame] | 418 | // Register link action. |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 419 | transformObjToDynamicBinary(ctx, objs.objFiles, sharedLibs, deps.StaticLibs, |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 420 | deps.LateStaticLibs, deps.WholeStaticLibs, linkerDeps, deps.CrtBegin, deps.CrtEnd, true, |
Colin Cross | f04eb99 | 2021-06-11 15:22:41 -0700 | [diff] [blame] | 421 | builderFlags, outputFile, nil, validations) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 422 | |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 423 | objs.coverageFiles = append(objs.coverageFiles, deps.StaticLibObjs.coverageFiles...) |
| 424 | objs.coverageFiles = append(objs.coverageFiles, deps.WholeStaticLibObjs.coverageFiles...) |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 425 | binary.coverageOutputFile = transformCoverageFilesToZip(ctx, objs, binary.getStem(ctx)) |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 426 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 427 | // Need to determine symlinks early since some targets (ie APEX) need this |
| 428 | // information but will not call 'install' |
Colin Cross | 9b09f24 | 2016-12-07 13:37:42 -0800 | [diff] [blame] | 429 | for _, symlink := range binary.Properties.Symlinks { |
| 430 | binary.symlinks = append(binary.symlinks, |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 431 | symlink+String(binary.Properties.Suffix)+ctx.toolchain().ExecutableSuffix()) |
Colin Cross | 9b09f24 | 2016-12-07 13:37:42 -0800 | [diff] [blame] | 432 | } |
| 433 | |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 434 | if Bool(binary.Properties.Symlink_preferred_arch) { |
Roland Levillain | 9efb8c7 | 2019-06-05 13:31:31 +0100 | [diff] [blame] | 435 | if String(binary.Properties.Suffix) == "" { |
| 436 | ctx.PropertyErrorf("symlink_preferred_arch", "must also specify suffix") |
Colin Cross | 9b09f24 | 2016-12-07 13:37:42 -0800 | [diff] [blame] | 437 | } |
| 438 | if ctx.TargetPrimary() { |
Chris Parsons | e0f2ab3 | 2020-11-20 17:27:25 -0500 | [diff] [blame] | 439 | // Install a symlink to the preferred architecture |
Colin Cross | a615901 | 2020-11-12 12:14:36 -0800 | [diff] [blame] | 440 | symlinkName := binary.getStemWithoutSuffix(ctx) |
| 441 | binary.symlinks = append(binary.symlinks, symlinkName) |
| 442 | binary.preferredArchSymlink = symlinkName |
Colin Cross | 9b09f24 | 2016-12-07 13:37:42 -0800 | [diff] [blame] | 443 | } |
| 444 | } |
| 445 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 446 | return ret |
| 447 | } |
| 448 | |
Jiyong Park | af6d895 | 2019-01-31 12:21:23 +0900 | [diff] [blame] | 449 | func (binary *binaryDecorator) unstrippedOutputFilePath() android.Path { |
| 450 | return binary.unstrippedOutputFile |
| 451 | } |
| 452 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 453 | func (binary *binaryDecorator) symlinkList() []string { |
| 454 | return binary.symlinks |
| 455 | } |
| 456 | |
Pirama Arumuga Nainar | 65c95ff | 2019-03-25 10:21:31 -0700 | [diff] [blame] | 457 | func (binary *binaryDecorator) nativeCoverage() bool { |
| 458 | return true |
| 459 | } |
| 460 | |
Jiyong Park | ee9a98d | 2019-08-09 14:44:36 +0900 | [diff] [blame] | 461 | func (binary *binaryDecorator) coverageOutputFilePath() android.OptionalPath { |
| 462 | return binary.coverageOutputFile |
| 463 | } |
| 464 | |
Jiyong Park | f119435 | 2019-02-25 11:05:47 +0900 | [diff] [blame] | 465 | // /system/bin/linker -> /apex/com.android.runtime/bin/linker |
| 466 | func (binary *binaryDecorator) installSymlinkToRuntimeApex(ctx ModuleContext, file android.Path) { |
| 467 | dir := binary.baseInstaller.installDir(ctx) |
| 468 | dirOnDevice := android.InstallPathToOnDevicePath(ctx, dir) |
| 469 | target := "/" + filepath.Join("apex", "com.android.runtime", dir.Base(), file.Base()) |
| 470 | |
| 471 | ctx.InstallAbsoluteSymlink(dir, file.Base(), target) |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 472 | binary.postInstallCmds = append(binary.postInstallCmds, makeSymlinkCmd(dirOnDevice, file.Base(), target)) |
Jiyong Park | f119435 | 2019-02-25 11:05:47 +0900 | [diff] [blame] | 473 | |
| 474 | for _, symlink := range binary.symlinks { |
| 475 | ctx.InstallAbsoluteSymlink(dir, symlink, target) |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 476 | binary.postInstallCmds = append(binary.postInstallCmds, makeSymlinkCmd(dirOnDevice, symlink, target)) |
Jiyong Park | f119435 | 2019-02-25 11:05:47 +0900 | [diff] [blame] | 477 | } |
| 478 | } |
| 479 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 480 | func (binary *binaryDecorator) install(ctx ModuleContext, file android.Path) { |
Jiyong Park | f119435 | 2019-02-25 11:05:47 +0900 | [diff] [blame] | 481 | // Bionic binaries (e.g. linker) is installed to the bootstrap subdirectory. |
| 482 | // The original path becomes a symlink to the corresponding file in the |
| 483 | // runtime APEX. |
Colin Cross | 3b19f5d | 2019-09-17 14:45:31 -0700 | [diff] [blame] | 484 | translatedArch := ctx.Target().NativeBridge == android.NativeBridgeEnabled |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 485 | if InstallToBootstrap(ctx.baseModuleName(), ctx.Config()) && !ctx.Host() && ctx.directlyInAnyApex() && |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 486 | !translatedArch && ctx.apexVariationName() == "" && !ctx.inRamdisk() && !ctx.inRecovery() && |
| 487 | !ctx.inVendorRamdisk() { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 488 | |
Peter Collingbourne | 3478bb2 | 2019-04-24 14:41:12 -0700 | [diff] [blame] | 489 | if ctx.Device() && isBionic(ctx.baseModuleName()) { |
Jiyong Park | c3e2c86 | 2019-03-16 01:10:08 +0900 | [diff] [blame] | 490 | binary.installSymlinkToRuntimeApex(ctx, file) |
| 491 | } |
Jiyong Park | f119435 | 2019-02-25 11:05:47 +0900 | [diff] [blame] | 492 | binary.baseInstaller.subDir = "bootstrap" |
| 493 | } |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 494 | binary.baseInstaller.install(ctx, file) |
Colin Cross | a615901 | 2020-11-12 12:14:36 -0800 | [diff] [blame] | 495 | |
| 496 | var preferredArchSymlinkPath android.OptionalPath |
Colin Cross | 9b09f24 | 2016-12-07 13:37:42 -0800 | [diff] [blame] | 497 | for _, symlink := range binary.symlinks { |
Colin Cross | a615901 | 2020-11-12 12:14:36 -0800 | [diff] [blame] | 498 | installedSymlink := ctx.InstallSymlink(binary.baseInstaller.installDir(ctx), symlink, |
| 499 | binary.baseInstaller.path) |
| 500 | if symlink == binary.preferredArchSymlink { |
| 501 | // If this is the preferred arch symlink, save the installed path for use as the |
| 502 | // tool path. |
| 503 | preferredArchSymlinkPath = android.OptionalPathForPath(installedSymlink) |
| 504 | } |
Colin Cross | 9b09f24 | 2016-12-07 13:37:42 -0800 | [diff] [blame] | 505 | } |
| 506 | |
Dan Willemsen | 4aa75ca | 2016-09-28 16:18:03 -0700 | [diff] [blame] | 507 | if ctx.Os().Class == android.Host { |
Colin Cross | a615901 | 2020-11-12 12:14:36 -0800 | [diff] [blame] | 508 | // If the binary is multilib with a symlink to the preferred architecture, use the |
| 509 | // symlink instead of the binary because that's the more "canonical" name. |
| 510 | if preferredArchSymlinkPath.Valid() { |
| 511 | binary.toolPath = preferredArchSymlinkPath |
| 512 | } else { |
| 513 | binary.toolPath = android.OptionalPathForPath(binary.baseInstaller.path) |
| 514 | } |
Dan Willemsen | 4aa75ca | 2016-09-28 16:18:03 -0700 | [diff] [blame] | 515 | } |
| 516 | } |
| 517 | |
| 518 | func (binary *binaryDecorator) hostToolPath() android.OptionalPath { |
| 519 | return binary.toolPath |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 520 | } |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 521 | |
| 522 | func init() { |
Colin Cross | f04eb99 | 2021-06-11 15:22:41 -0700 | [diff] [blame] | 523 | pctx.HostBinToolVariable("verifyHostBionicCmd", "host_bionic_verify") |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 524 | } |
| 525 | |
Colin Cross | f04eb99 | 2021-06-11 15:22:41 -0700 | [diff] [blame] | 526 | var verifyHostBionic = pctx.AndroidStaticRule("verifyHostBionic", |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 527 | blueprint.RuleParams{ |
Colin Cross | f04eb99 | 2021-06-11 15:22:41 -0700 | [diff] [blame] | 528 | Command: "$verifyHostBionicCmd -i $in -l $linker && touch $out", |
| 529 | CommandDeps: []string{"$verifyHostBionicCmd"}, |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 530 | }, "linker") |
| 531 | |
Colin Cross | f04eb99 | 2021-06-11 15:22:41 -0700 | [diff] [blame] | 532 | func (binary *binaryDecorator) verifyHostBionicLinker(ctx ModuleContext, in, linker android.Path, out android.WritablePath) { |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 533 | ctx.Build(pctx, android.BuildParams{ |
Colin Cross | f04eb99 | 2021-06-11 15:22:41 -0700 | [diff] [blame] | 534 | Rule: verifyHostBionic, |
| 535 | Description: "verify host bionic", |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 536 | Input: in, |
| 537 | Implicit: linker, |
| 538 | Output: out, |
| 539 | Args: map[string]string{ |
| 540 | "linker": linker.String(), |
| 541 | }, |
| 542 | }) |
| 543 | } |