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 ( |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 18 | "path/filepath" |
| 19 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 20 | "github.com/google/blueprint/proptools" |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 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 |
| 30 | Stem string `android:"arch_variant"` |
| 31 | |
| 32 | // append to the name of the output |
| 33 | Suffix string `android:"arch_variant"` |
| 34 | |
| 35 | // if set, add an extra objcopy --prefix-symbols= step |
| 36 | Prefix_symbols string |
Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 37 | |
dimitry | feda20b | 2017-08-29 15:00:01 +0200 | [diff] [blame] | 38 | // local file name to pass to the linker as --version_script |
| 39 | Version_script *string `android:"arch_variant"` |
| 40 | |
Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 41 | // if set, install a symlink to the preferred architecture |
| 42 | Symlink_preferred_arch bool |
Colin Cross | 522e373 | 2016-09-07 13:14:06 -0700 | [diff] [blame] | 43 | |
Colin Cross | 9b09f24 | 2016-12-07 13:37:42 -0800 | [diff] [blame] | 44 | // install symlinks to the binary. Symlink names will have the suffix and the binary |
| 45 | // extension (if any) appended |
| 46 | Symlinks []string `android:"arch_variant"` |
| 47 | |
Colin Cross | 7a108bc | 2017-01-30 22:44:19 -0800 | [diff] [blame] | 48 | // do not pass -pie |
| 49 | No_pie *bool `android:"arch_variant"` |
| 50 | |
Colin Cross | 522e373 | 2016-09-07 13:14:06 -0700 | [diff] [blame] | 51 | DynamicLinker string `blueprint:"mutated"` |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | func init() { |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 55 | android.RegisterModuleType("cc_binary", binaryFactory) |
| 56 | android.RegisterModuleType("cc_binary_host", binaryHostFactory) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | // Module factory for binaries |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 60 | func binaryFactory() android.Module { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 61 | module, _ := NewBinary(android.HostAndDeviceSupported) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 62 | return module.Init() |
| 63 | } |
| 64 | |
| 65 | // Module factory for host binaries |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 66 | func binaryHostFactory() android.Module { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 67 | module, _ := NewBinary(android.HostSupported) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 68 | return module.Init() |
| 69 | } |
| 70 | |
| 71 | // |
| 72 | // Executables |
| 73 | // |
| 74 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 75 | type binaryDecorator struct { |
| 76 | *baseLinker |
Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 77 | *baseInstaller |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 78 | stripper |
| 79 | |
| 80 | Properties BinaryLinkerProperties |
| 81 | |
Dan Willemsen | 4aa75ca | 2016-09-28 16:18:03 -0700 | [diff] [blame] | 82 | toolPath android.OptionalPath |
Colin Cross | 9b09f24 | 2016-12-07 13:37:42 -0800 | [diff] [blame] | 83 | |
| 84 | // Names of symlinks to be installed for use in LOCAL_MODULE_SYMLINKS |
| 85 | symlinks []string |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 86 | |
| 87 | // Output archive of gcno coverage information |
| 88 | coverageOutputFile android.OptionalPath |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 91 | var _ linker = (*binaryDecorator)(nil) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 92 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 93 | func (binary *binaryDecorator) linkerProps() []interface{} { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 94 | return append(binary.baseLinker.linkerProps(), |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 95 | &binary.Properties, |
| 96 | &binary.stripper.StripProperties) |
| 97 | |
| 98 | } |
| 99 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 100 | func (binary *binaryDecorator) getStem(ctx BaseModuleContext) string { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 101 | stem := ctx.baseModuleName() |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 102 | if binary.Properties.Stem != "" { |
| 103 | stem = binary.Properties.Stem |
| 104 | } |
| 105 | |
| 106 | return stem + binary.Properties.Suffix |
| 107 | } |
| 108 | |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 109 | func (binary *binaryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 110 | deps = binary.baseLinker.linkerDeps(ctx, deps) |
Dan Willemsen | 2e47b34 | 2016-11-17 01:02:25 -0800 | [diff] [blame] | 111 | if ctx.toolchain().Bionic() { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 112 | if !Bool(binary.baseLinker.Properties.Nocrt) { |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 113 | if !ctx.sdk() { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 114 | if binary.static() { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 115 | deps.CrtBegin = "crtbegin_static" |
| 116 | } else { |
| 117 | deps.CrtBegin = "crtbegin_dynamic" |
| 118 | } |
| 119 | deps.CrtEnd = "crtend_android" |
| 120 | } else { |
Dan Albert | ebedf67 | 2016-11-08 15:06:22 -0800 | [diff] [blame] | 121 | // TODO(danalbert): Add generation of crt objects. |
| 122 | // For `sdk_version: "current"`, we don't actually have a |
| 123 | // freshly generated set of CRT objects. Use the last stable |
| 124 | // version. |
| 125 | version := ctx.sdkVersion() |
| 126 | if version == "current" { |
Jayant Chowdhary | 6e8115a | 2017-05-09 10:21:52 -0700 | [diff] [blame] | 127 | version = getCurrentNdkPrebuiltVersion(ctx) |
Dan Albert | ebedf67 | 2016-11-08 15:06:22 -0800 | [diff] [blame] | 128 | } |
| 129 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 130 | if binary.static() { |
Dan Albert | ebedf67 | 2016-11-08 15:06:22 -0800 | [diff] [blame] | 131 | deps.CrtBegin = "ndk_crtbegin_static." + version |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 132 | } else { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 133 | if binary.static() { |
Dan Albert | ebedf67 | 2016-11-08 15:06:22 -0800 | [diff] [blame] | 134 | deps.CrtBegin = "ndk_crtbegin_static." + version |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 135 | } else { |
Dan Albert | ebedf67 | 2016-11-08 15:06:22 -0800 | [diff] [blame] | 136 | deps.CrtBegin = "ndk_crtbegin_dynamic." + version |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 137 | } |
Dan Albert | ebedf67 | 2016-11-08 15:06:22 -0800 | [diff] [blame] | 138 | deps.CrtEnd = "ndk_crtend_android." + version |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 143 | if binary.static() { |
Dan Albert | dc2597d | 2017-01-26 17:44:26 -0800 | [diff] [blame] | 144 | if ctx.selectedStl() == "libc++_static" { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 145 | deps.StaticLibs = append(deps.StaticLibs, "libm", "libc", "libdl") |
| 146 | } |
| 147 | // static libraries libcompiler_rt, libc and libc_nomalloc need to be linked with |
| 148 | // --start-group/--end-group along with libgcc. If they are in deps.StaticLibs, |
| 149 | // move them to the beginning of deps.LateStaticLibs |
| 150 | var groupLibs []string |
| 151 | deps.StaticLibs, groupLibs = filterList(deps.StaticLibs, |
| 152 | []string{"libc", "libc_nomalloc", "libcompiler_rt"}) |
| 153 | deps.LateStaticLibs = append(groupLibs, deps.LateStaticLibs...) |
| 154 | } |
| 155 | } |
| 156 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 157 | if !binary.static() && inList("libc", deps.StaticLibs) { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 158 | ctx.ModuleErrorf("statically linking libc to dynamic executable, please remove libc\n" + |
| 159 | "from static libs or set static_executable: true") |
| 160 | } |
| 161 | return deps |
| 162 | } |
| 163 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 164 | func (binary *binaryDecorator) isDependencyRoot() bool { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 165 | return true |
| 166 | } |
| 167 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 168 | func NewBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 169 | module := newModule(hod, android.MultilibFirst) |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 170 | binary := &binaryDecorator{ |
Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 171 | baseLinker: NewBaseLinker(), |
| 172 | baseInstaller: NewBaseInstaller("bin", "", InstallInSystem), |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 173 | } |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 174 | module.compiler = NewBaseCompiler() |
| 175 | module.linker = binary |
Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 176 | module.installer = binary |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 177 | return module, binary |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 180 | func (binary *binaryDecorator) linkerInit(ctx BaseModuleContext) { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 181 | binary.baseLinker.linkerInit(ctx) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 182 | |
Dan Willemsen | 2e47b34 | 2016-11-17 01:02:25 -0800 | [diff] [blame] | 183 | if !ctx.toolchain().Bionic() { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 184 | if ctx.Os() == android.Linux { |
| 185 | if binary.Properties.Static_executable == nil && Bool(ctx.AConfig().ProductVariables.HostStaticBinaries) { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 186 | binary.Properties.Static_executable = proptools.BoolPtr(true) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 187 | } |
| 188 | } else { |
| 189 | // Static executables are not supported on Darwin or Windows |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 190 | binary.Properties.Static_executable = nil |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 191 | } |
| 192 | } |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 195 | func (binary *binaryDecorator) static() bool { |
| 196 | return Bool(binary.Properties.Static_executable) |
| 197 | } |
| 198 | |
| 199 | func (binary *binaryDecorator) staticBinary() bool { |
| 200 | return binary.static() |
| 201 | } |
| 202 | |
| 203 | func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 204 | flags = binary.baseLinker.linkerFlags(ctx, flags) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 205 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 206 | if ctx.Host() && !binary.static() { |
Colin Cross | 7a108bc | 2017-01-30 22:44:19 -0800 | [diff] [blame] | 207 | if !ctx.AConfig().IsEnvTrue("DISABLE_HOST_PIE") { |
| 208 | flags.LdFlags = append(flags.LdFlags, "-pie") |
Colin Cross | 3edeee1 | 2017-04-04 12:59:48 -0700 | [diff] [blame] | 209 | if ctx.Windows() { |
Colin Cross | 7a108bc | 2017-01-30 22:44:19 -0800 | [diff] [blame] | 210 | flags.LdFlags = append(flags.LdFlags, "-Wl,-e_mainCRTStartup") |
| 211 | } |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 212 | } |
| 213 | } |
| 214 | |
| 215 | // MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because |
| 216 | // all code is position independent, and then those warnings get promoted to |
| 217 | // errors. |
Colin Cross | 3edeee1 | 2017-04-04 12:59:48 -0700 | [diff] [blame] | 218 | if !ctx.Windows() { |
Vishwath Mohan | e87b768 | 2017-04-17 16:21:41 -0700 | [diff] [blame] | 219 | flags.CFlags = append(flags.CFlags, "-fPIE") |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Dan Willemsen | 2e47b34 | 2016-11-17 01:02:25 -0800 | [diff] [blame] | 222 | if ctx.toolchain().Bionic() { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 223 | if binary.static() { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 224 | // Clang driver needs -static to create static executable. |
| 225 | // However, bionic/linker uses -shared to overwrite. |
| 226 | // Linker for x86 targets does not allow coexistance of -static and -shared, |
| 227 | // so we add -static only if -shared is not used. |
| 228 | if !inList("-shared", flags.LdFlags) { |
| 229 | flags.LdFlags = append(flags.LdFlags, "-static") |
| 230 | } |
| 231 | |
| 232 | flags.LdFlags = append(flags.LdFlags, |
| 233 | "-nostdlib", |
| 234 | "-Bstatic", |
| 235 | "-Wl,--gc-sections", |
| 236 | ) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 237 | } else { |
| 238 | if flags.DynamicLinker == "" { |
Colin Cross | 522e373 | 2016-09-07 13:14:06 -0700 | [diff] [blame] | 239 | if binary.Properties.DynamicLinker != "" { |
| 240 | flags.DynamicLinker = binary.Properties.DynamicLinker |
| 241 | } else { |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 242 | switch ctx.Os() { |
| 243 | case android.Android: |
| 244 | flags.DynamicLinker = "/system/bin/linker" |
| 245 | case android.LinuxBionic: |
| 246 | // The linux kernel expects the linker to be an |
| 247 | // absolute path |
| 248 | path := android.PathForOutput(ctx, |
| 249 | "host", "linux_bionic-x86", "bin", "linker") |
| 250 | if p, err := filepath.Abs(path.String()); err == nil { |
| 251 | flags.DynamicLinker = p |
| 252 | } else { |
| 253 | ctx.ModuleErrorf("can't find path to dynamic linker: %q", err) |
| 254 | } |
| 255 | default: |
| 256 | ctx.ModuleErrorf("unknown dynamic linker") |
| 257 | } |
Colin Cross | 522e373 | 2016-09-07 13:14:06 -0700 | [diff] [blame] | 258 | if flags.Toolchain.Is64Bit() { |
| 259 | flags.DynamicLinker += "64" |
| 260 | } |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 261 | } |
| 262 | } |
| 263 | |
| 264 | flags.LdFlags = append(flags.LdFlags, |
| 265 | "-pie", |
| 266 | "-nostdlib", |
| 267 | "-Bdynamic", |
| 268 | "-Wl,--gc-sections", |
| 269 | "-Wl,-z,nocopyreloc", |
| 270 | ) |
dimitry | feda20b | 2017-08-29 15:00:01 +0200 | [diff] [blame] | 271 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 272 | } |
| 273 | } else { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 274 | if binary.static() { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 275 | flags.LdFlags = append(flags.LdFlags, "-static") |
| 276 | } |
| 277 | if ctx.Darwin() { |
| 278 | flags.LdFlags = append(flags.LdFlags, "-Wl,-headerpad_max_install_names") |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | return flags |
| 283 | } |
| 284 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 285 | func (binary *binaryDecorator) link(ctx ModuleContext, |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 286 | flags Flags, deps PathDeps, objs Objects) android.Path { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 287 | |
dimitry | feda20b | 2017-08-29 15:00:01 +0200 | [diff] [blame] | 288 | versionScript := android.OptionalPathForModuleSrc(ctx, binary.Properties.Version_script) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 289 | fileName := binary.getStem(ctx) + flags.Toolchain.ExecutableSuffix() |
| 290 | outputFile := android.PathForModuleOut(ctx, fileName) |
| 291 | ret := outputFile |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 292 | |
| 293 | var linkerDeps android.Paths |
| 294 | |
| 295 | sharedLibs := deps.SharedLibs |
| 296 | sharedLibs = append(sharedLibs, deps.LateSharedLibs...) |
| 297 | |
dimitry | feda20b | 2017-08-29 15:00:01 +0200 | [diff] [blame] | 298 | if versionScript.Valid() { |
| 299 | if ctx.Darwin() { |
| 300 | ctx.PropertyErrorf("version_script", "Not supported on Darwin") |
| 301 | } else { |
| 302 | flags.LdFlags = append(flags.LdFlags, "-Wl,--version-script,"+versionScript.String()) |
| 303 | linkerDeps = append(linkerDeps, versionScript.Path()) |
| 304 | } |
| 305 | } |
| 306 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 307 | if flags.DynamicLinker != "" { |
| 308 | flags.LdFlags = append(flags.LdFlags, " -Wl,-dynamic-linker,"+flags.DynamicLinker) |
| 309 | } |
| 310 | |
| 311 | builderFlags := flagsToBuilderFlags(flags) |
| 312 | |
| 313 | if binary.stripper.needsStrip(ctx) { |
| 314 | strippedOutputFile := outputFile |
| 315 | outputFile = android.PathForModuleOut(ctx, "unstripped", fileName) |
| 316 | binary.stripper.strip(ctx, outputFile, strippedOutputFile, builderFlags) |
| 317 | } |
| 318 | |
| 319 | if binary.Properties.Prefix_symbols != "" { |
| 320 | afterPrefixSymbols := outputFile |
| 321 | outputFile = android.PathForModuleOut(ctx, "unprefixed", fileName) |
| 322 | TransformBinaryPrefixSymbols(ctx, binary.Properties.Prefix_symbols, outputFile, |
| 323 | flagsToBuilderFlags(flags), afterPrefixSymbols) |
| 324 | } |
| 325 | |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 326 | linkerDeps = append(linkerDeps, deps.SharedLibsDeps...) |
| 327 | linkerDeps = append(linkerDeps, deps.LateSharedLibsDeps...) |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 328 | linkerDeps = append(linkerDeps, objs.tidyFiles...) |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 329 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 330 | TransformObjToDynamicBinary(ctx, objs.objFiles, sharedLibs, deps.StaticLibs, |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 331 | deps.LateStaticLibs, deps.WholeStaticLibs, linkerDeps, deps.CrtBegin, deps.CrtEnd, true, |
| 332 | builderFlags, outputFile) |
| 333 | |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 334 | objs.coverageFiles = append(objs.coverageFiles, deps.StaticLibObjs.coverageFiles...) |
| 335 | objs.coverageFiles = append(objs.coverageFiles, deps.WholeStaticLibObjs.coverageFiles...) |
| 336 | binary.coverageOutputFile = TransformCoverageFilesToLib(ctx, objs, builderFlags, binary.getStem(ctx)) |
| 337 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 338 | return ret |
| 339 | } |
| 340 | |
Dan Willemsen | 4aa75ca | 2016-09-28 16:18:03 -0700 | [diff] [blame] | 341 | func (binary *binaryDecorator) install(ctx ModuleContext, file android.Path) { |
| 342 | binary.baseInstaller.install(ctx, file) |
Colin Cross | 9b09f24 | 2016-12-07 13:37:42 -0800 | [diff] [blame] | 343 | for _, symlink := range binary.Properties.Symlinks { |
| 344 | binary.symlinks = append(binary.symlinks, |
Colin Cross | 989c66e | 2016-12-08 09:43:41 -0800 | [diff] [blame] | 345 | symlink+binary.Properties.Suffix+ctx.toolchain().ExecutableSuffix()) |
Colin Cross | 9b09f24 | 2016-12-07 13:37:42 -0800 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | if binary.Properties.Symlink_preferred_arch { |
| 349 | if binary.Properties.Stem == "" && binary.Properties.Suffix == "" { |
| 350 | ctx.PropertyErrorf("symlink_preferred_arch", "must also specify stem or suffix") |
| 351 | } |
| 352 | if ctx.TargetPrimary() { |
| 353 | binary.symlinks = append(binary.symlinks, ctx.baseModuleName()) |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | for _, symlink := range binary.symlinks { |
| 358 | ctx.InstallSymlink(binary.baseInstaller.installDir(ctx), symlink, binary.baseInstaller.path) |
| 359 | } |
| 360 | |
Dan Willemsen | 4aa75ca | 2016-09-28 16:18:03 -0700 | [diff] [blame] | 361 | if ctx.Os().Class == android.Host { |
| 362 | binary.toolPath = android.OptionalPathForPath(binary.baseInstaller.path) |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | func (binary *binaryDecorator) hostToolPath() android.OptionalPath { |
| 367 | return binary.toolPath |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 368 | } |