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 ( |
| 18 | "fmt" |
Colin Cross | fb44cd2 | 2022-09-09 15:11:16 -0700 | [diff] [blame] | 19 | "strings" |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 20 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 21 | "android/soong/android" |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 22 | "android/soong/bazel" |
Chris Parsons | f874e46 | 2022-05-10 13:50:12 -0400 | [diff] [blame] | 23 | "android/soong/bazel/cquery" |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 24 | ) |
| 25 | |
| 26 | // |
| 27 | // Objects (for crt*.o) |
| 28 | // |
| 29 | |
| 30 | func init() { |
Colin Cross | e40b4ea | 2018-10-02 22:25:58 -0700 | [diff] [blame] | 31 | android.RegisterModuleType("cc_object", ObjectFactory) |
Martin Stjernholm | cd07bce | 2020-03-10 22:37:59 +0000 | [diff] [blame] | 32 | android.RegisterSdkMemberType(ccObjectSdkMemberType) |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 33 | |
Martin Stjernholm | cd07bce | 2020-03-10 22:37:59 +0000 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | var ccObjectSdkMemberType = &librarySdkMemberType{ |
| 37 | SdkMemberTypeBase: android.SdkMemberTypeBase{ |
| 38 | PropertyName: "native_objects", |
| 39 | SupportsSdk: true, |
| 40 | }, |
| 41 | prebuiltModuleType: "cc_prebuilt_object", |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | type objectLinker struct { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 45 | *baseLinker |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 46 | Properties ObjectLinkerProperties |
| 47 | } |
| 48 | |
Chris Parsons | 8d6e433 | 2021-02-22 16:13:50 -0500 | [diff] [blame] | 49 | type objectBazelHandler struct { |
Chris Parsons | 8d6e433 | 2021-02-22 16:13:50 -0500 | [diff] [blame] | 50 | module *Module |
| 51 | } |
| 52 | |
Chris Parsons | 6ce2cf9 | 2022-05-20 10:54:17 -0400 | [diff] [blame] | 53 | var _ BazelHandler = (*objectBazelHandler)(nil) |
| 54 | |
Chris Parsons | f874e46 | 2022-05-10 13:50:12 -0400 | [diff] [blame] | 55 | func (handler *objectBazelHandler) QueueBazelCall(ctx android.BaseModuleContext, label string) { |
Liz Kammer | 8206d4f | 2021-03-03 16:40:52 -0500 | [diff] [blame] | 56 | bazelCtx := ctx.Config().BazelContext |
Yu Liu | e431240 | 2023-01-18 09:15:31 -0800 | [diff] [blame] | 57 | bazelCtx.QueueBazelRequest(label, cquery.GetOutputFiles, android.GetConfigKeyApexVariant(ctx, GetApexConfigKey(ctx))) |
Chris Parsons | f874e46 | 2022-05-10 13:50:12 -0400 | [diff] [blame] | 58 | } |
Liz Kammer | 8206d4f | 2021-03-03 16:40:52 -0500 | [diff] [blame] | 59 | |
Chris Parsons | f874e46 | 2022-05-10 13:50:12 -0400 | [diff] [blame] | 60 | func (handler *objectBazelHandler) ProcessBazelQueryResponse(ctx android.ModuleContext, label string) { |
| 61 | bazelCtx := ctx.Config().BazelContext |
Yu Liu | e431240 | 2023-01-18 09:15:31 -0800 | [diff] [blame] | 62 | objPaths, err := bazelCtx.GetOutputFiles(label, android.GetConfigKeyApexVariant(ctx, GetApexConfigKey(ctx))) |
Chris Parsons | f874e46 | 2022-05-10 13:50:12 -0400 | [diff] [blame] | 63 | if err != nil { |
| 64 | ctx.ModuleErrorf(err.Error()) |
| 65 | return |
Liz Kammer | 8206d4f | 2021-03-03 16:40:52 -0500 | [diff] [blame] | 66 | } |
Chris Parsons | f874e46 | 2022-05-10 13:50:12 -0400 | [diff] [blame] | 67 | |
| 68 | if len(objPaths) != 1 { |
| 69 | ctx.ModuleErrorf("expected exactly one object file for '%s', but got %s", label, objPaths) |
| 70 | return |
| 71 | } |
| 72 | |
| 73 | handler.module.outputFile = android.OptionalPathForPath(android.PathForBazelOut(ctx, objPaths[0])) |
Chris Parsons | 8d6e433 | 2021-02-22 16:13:50 -0500 | [diff] [blame] | 74 | } |
| 75 | |
Pete Bentley | 74c9bba | 2019-08-16 20:25:06 +0100 | [diff] [blame] | 76 | type ObjectLinkerProperties struct { |
Colin Cross | 137d7da | 2021-06-21 16:41:29 -0700 | [diff] [blame] | 77 | // list of static library modules that should only provide headers for this module. |
| 78 | Static_libs []string `android:"arch_variant,variant_prepend"` |
| 79 | |
| 80 | // list of shared library modules should only provide headers for this module. |
Zi Wang | 9f609db | 2023-01-04 11:06:54 -0800 | [diff] [blame] | 81 | Shared_libs []string `android:"arch_variant,variant_prepend"` |
Colin Cross | 137d7da | 2021-06-21 16:41:29 -0700 | [diff] [blame] | 82 | |
Pete Bentley | 74c9bba | 2019-08-16 20:25:06 +0100 | [diff] [blame] | 83 | // list of modules that should only provide headers for this module. |
| 84 | Header_libs []string `android:"arch_variant,variant_prepend"` |
| 85 | |
Colin Cross | 137d7da | 2021-06-21 16:41:29 -0700 | [diff] [blame] | 86 | // list of default libraries that will provide headers for this module. If unset, generally |
| 87 | // defaults to libc, libm, and libdl. Set to [] to prevent using headers from the defaults. |
Colin Cross | 6b8f425 | 2021-07-22 11:39:44 -0700 | [diff] [blame] | 88 | System_shared_libs []string `android:"arch_variant"` |
Colin Cross | 137d7da | 2021-06-21 16:41:29 -0700 | [diff] [blame] | 89 | |
Pete Bentley | 74c9bba | 2019-08-16 20:25:06 +0100 | [diff] [blame] | 90 | // names of other cc_object modules to link into this module using partial linking |
| 91 | Objs []string `android:"arch_variant"` |
| 92 | |
| 93 | // if set, add an extra objcopy --prefix-symbols= step |
| 94 | Prefix_symbols *string |
| 95 | |
| 96 | // if set, the path to a linker script to pass to ld -r when combining multiple object files. |
| 97 | Linker_script *string `android:"path,arch_variant"` |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 98 | |
| 99 | // Indicates that this module is a CRT object. CRT objects will be split |
| 100 | // into a variant per-API level between min_sdk_version and current. |
| 101 | Crt *bool |
Pete Bentley | 74c9bba | 2019-08-16 20:25:06 +0100 | [diff] [blame] | 102 | } |
| 103 | |
Colin Cross | 7cabd42 | 2021-06-25 14:21:04 -0700 | [diff] [blame] | 104 | func newObject(hod android.HostOrDeviceSupported) *Module { |
| 105 | module := newBaseModule(hod, android.MultilibBoth) |
Martin Stjernholm | 0b92ac8 | 2020-03-11 21:45:49 +0000 | [diff] [blame] | 106 | module.sanitize = &sanitize{} |
| 107 | module.stl = &stl{} |
| 108 | return module |
| 109 | } |
| 110 | |
Patrice Arruda | baff0ce | 2019-03-26 10:39:49 -0700 | [diff] [blame] | 111 | // cc_object runs the compiler without running the linker. It is rarely |
| 112 | // necessary, but sometimes used to generate .s files from .c files to use as |
| 113 | // input to a cc_genrule module. |
Colin Cross | e40b4ea | 2018-10-02 22:25:58 -0700 | [diff] [blame] | 114 | func ObjectFactory() android.Module { |
Colin Cross | 7cabd42 | 2021-06-25 14:21:04 -0700 | [diff] [blame] | 115 | module := newObject(android.HostAndDeviceSupported) |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 116 | module.linker = &objectLinker{ |
Peter Collingbourne | 1c648b8 | 2019-09-26 12:24:45 -0700 | [diff] [blame] | 117 | baseLinker: NewBaseLinker(module.sanitize), |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 118 | } |
| 119 | module.compiler = NewBaseCompiler() |
Chris Parsons | 8d6e433 | 2021-02-22 16:13:50 -0500 | [diff] [blame] | 120 | module.bazelHandler = &objectBazelHandler{module: module} |
Peter Collingbourne | 486e42c | 2018-10-25 10:53:44 -0700 | [diff] [blame] | 121 | |
| 122 | // Clang's address-significance tables are incompatible with ld -r. |
| 123 | module.compiler.appendCflags([]string{"-fno-addrsig"}) |
| 124 | |
Martin Stjernholm | cd07bce | 2020-03-10 22:37:59 +0000 | [diff] [blame] | 125 | module.sdkMemberTypes = []android.SdkMemberType{ccObjectSdkMemberType} |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 126 | |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 127 | module.bazelable = true |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 128 | return module.Init() |
| 129 | } |
| 130 | |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 131 | // For bp2build conversion. |
| 132 | type bazelObjectAttributes struct { |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 133 | Srcs bazel.LabelListAttribute |
| 134 | Srcs_as bazel.LabelListAttribute |
| 135 | Hdrs bazel.LabelListAttribute |
Colin Cross | 65ebc42 | 2022-12-05 21:18:13 -0800 | [diff] [blame] | 136 | Objs bazel.LabelListAttribute |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 137 | Deps bazel.LabelListAttribute |
| 138 | System_dynamic_deps bazel.LabelListAttribute |
| 139 | Copts bazel.StringListAttribute |
| 140 | Asflags bazel.StringListAttribute |
| 141 | Local_includes bazel.StringListAttribute |
| 142 | Absolute_includes bazel.StringListAttribute |
| 143 | Stl *string |
| 144 | Linker_script bazel.LabelAttribute |
Sam Delmerico | 3fad8ed | 2023-01-25 16:52:36 -0500 | [diff] [blame] | 145 | Crt *bool |
Yu Liu | fc60316 | 2022-03-01 15:44:08 -0800 | [diff] [blame] | 146 | sdkAttributes |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 147 | } |
| 148 | |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 149 | // objectBp2Build is the bp2build converter from cc_object modules to the |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 150 | // Bazel equivalent target, plus any necessary include deps for the cc_object. |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 151 | func objectBp2Build(ctx android.TopDownMutatorContext, m *Module) { |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 152 | if m.compiler == nil { |
| 153 | // a cc_object must have access to the compiler decorator for its props. |
| 154 | ctx.ModuleErrorf("compiler must not be nil for a cc_object module") |
| 155 | } |
| 156 | |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 157 | // Set arch-specific configurable attributes |
Liz Kammer | e658348 | 2021-10-19 13:56:10 -0400 | [diff] [blame] | 158 | baseAttributes := bp2BuildParseBaseProps(ctx, m) |
| 159 | compilerAttrs := baseAttributes.compilerAttributes |
Colin Cross | 65ebc42 | 2022-12-05 21:18:13 -0800 | [diff] [blame] | 160 | var objs bazel.LabelListAttribute |
Jingwen Chen | 0702791 | 2021-03-15 06:02:43 -0400 | [diff] [blame] | 161 | var deps bazel.LabelListAttribute |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 162 | systemDynamicDeps := bazel.LabelListAttribute{ForceSpecifyEmptyList: true} |
| 163 | |
| 164 | var linkerScript bazel.LabelAttribute |
| 165 | |
| 166 | for axis, configToProps := range m.GetArchVariantProperties(ctx, &ObjectLinkerProperties{}) { |
| 167 | for config, props := range configToProps { |
| 168 | if objectLinkerProps, ok := props.(*ObjectLinkerProperties); ok { |
| 169 | if objectLinkerProps.Linker_script != nil { |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 170 | label := android.BazelLabelForModuleSrcSingle(ctx, *objectLinkerProps.Linker_script) |
| 171 | linkerScript.SetSelectValue(axis, config, label) |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 172 | } |
Colin Cross | 65ebc42 | 2022-12-05 21:18:13 -0800 | [diff] [blame] | 173 | objs.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, objectLinkerProps.Objs)) |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 174 | systemSharedLibs := objectLinkerProps.System_shared_libs |
| 175 | if len(systemSharedLibs) > 0 { |
| 176 | systemSharedLibs = android.FirstUniqueStrings(systemSharedLibs) |
| 177 | } |
| 178 | systemDynamicDeps.SetSelectValue(axis, config, bazelLabelForSharedDeps(ctx, systemSharedLibs)) |
Colin Cross | 65ebc42 | 2022-12-05 21:18:13 -0800 | [diff] [blame] | 179 | deps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, objectLinkerProps.Static_libs)) |
| 180 | deps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, objectLinkerProps.Shared_libs)) |
| 181 | deps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, objectLinkerProps.Header_libs)) |
Zi Wang | 9f609db | 2023-01-04 11:06:54 -0800 | [diff] [blame] | 182 | // static_libs, shared_libs, and header_libs have variant_prepend tag |
| 183 | deps.Prepend = true |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 184 | } |
Jingwen Chen | db12024 | 2021-02-23 00:46:47 -0500 | [diff] [blame] | 185 | } |
| 186 | } |
Colin Cross | 65ebc42 | 2022-12-05 21:18:13 -0800 | [diff] [blame] | 187 | objs.ResolveExcludes() |
Jingwen Chen | db12024 | 2021-02-23 00:46:47 -0500 | [diff] [blame] | 188 | |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 189 | // Don't split cc_object srcs across languages. Doing so would add complexity, |
| 190 | // and this isn't typically done for cc_object. |
| 191 | srcs := compilerAttrs.srcs |
| 192 | srcs.Append(compilerAttrs.cSrcs) |
Chris Parsons | 69fa9f9 | 2021-07-13 11:47:44 -0400 | [diff] [blame] | 193 | |
| 194 | asFlags := compilerAttrs.asFlags |
| 195 | if compilerAttrs.asSrcs.IsEmpty() { |
| 196 | // Skip asflags for BUILD file simplicity if there are no assembly sources. |
| 197 | asFlags = bazel.MakeStringListAttribute(nil) |
| 198 | } |
Chris Parsons | 990c4f4 | 2021-05-25 12:10:58 -0400 | [diff] [blame] | 199 | |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 200 | attrs := &bazelObjectAttributes{ |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 201 | Srcs: srcs, |
| 202 | Srcs_as: compilerAttrs.asSrcs, |
Colin Cross | 65ebc42 | 2022-12-05 21:18:13 -0800 | [diff] [blame] | 203 | Objs: objs, |
Chris Parsons | a37e195 | 2021-09-28 16:47:36 -0400 | [diff] [blame] | 204 | Deps: deps, |
| 205 | System_dynamic_deps: systemDynamicDeps, |
| 206 | Copts: compilerAttrs.copts, |
| 207 | Asflags: asFlags, |
| 208 | Local_includes: compilerAttrs.localIncludes, |
| 209 | Absolute_includes: compilerAttrs.absoluteIncludes, |
| 210 | Stl: compilerAttrs.stl, |
| 211 | Linker_script: linkerScript, |
Sam Delmerico | 3fad8ed | 2023-01-25 16:52:36 -0500 | [diff] [blame] | 212 | Crt: m.linker.(*objectLinker).Properties.Crt, |
Yu Liu | fc60316 | 2022-03-01 15:44:08 -0800 | [diff] [blame] | 213 | sdkAttributes: bp2BuildParseSdkAttributes(m), |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 214 | } |
| 215 | |
Liz Kammer | fc46bc1 | 2021-02-19 11:06:17 -0500 | [diff] [blame] | 216 | props := bazel.BazelTargetModuleProperties{ |
| 217 | Rule_class: "cc_object", |
Liz Kammer | 2b376bc | 2022-01-12 12:00:49 -0500 | [diff] [blame] | 218 | Bzl_load_location: "//build/bazel/rules/cc:cc_object.bzl", |
Liz Kammer | fc46bc1 | 2021-02-19 11:06:17 -0500 | [diff] [blame] | 219 | } |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 220 | |
Sam Delmerico | eddd3c0 | 2022-12-02 17:31:58 -0500 | [diff] [blame] | 221 | tags := android.ApexAvailableTags(m) |
| 222 | |
| 223 | ctx.CreateBazelTargetModule(props, android.CommonAttributes{ |
| 224 | Name: m.Name(), |
| 225 | Tags: tags, |
| 226 | }, attrs) |
Jingwen Chen | 8c1b97e | 2021-02-18 03:21:34 -0500 | [diff] [blame] | 227 | } |
| 228 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 229 | func (object *objectLinker) appendLdflags(flags []string) { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 230 | panic(fmt.Errorf("appendLdflags on objectLinker not supported")) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 233 | func (object *objectLinker) linkerProps() []interface{} { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 234 | return []interface{}{&object.Properties} |
| 235 | } |
| 236 | |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 237 | func (*objectLinker) linkerInit(ctx BaseModuleContext) {} |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 238 | |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 239 | func (object *objectLinker) linkerDeps(ctx DepsContext, deps Deps) Deps { |
Paul Duffin | a37832a | 2019-07-18 12:31:26 +0100 | [diff] [blame] | 240 | deps.HeaderLibs = append(deps.HeaderLibs, object.Properties.Header_libs...) |
Colin Cross | 137d7da | 2021-06-21 16:41:29 -0700 | [diff] [blame] | 241 | deps.SharedLibs = append(deps.SharedLibs, object.Properties.Shared_libs...) |
| 242 | deps.StaticLibs = append(deps.StaticLibs, object.Properties.Static_libs...) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 243 | deps.ObjFiles = append(deps.ObjFiles, object.Properties.Objs...) |
Colin Cross | 137d7da | 2021-06-21 16:41:29 -0700 | [diff] [blame] | 244 | |
Colin Cross | 6b8f425 | 2021-07-22 11:39:44 -0700 | [diff] [blame] | 245 | deps.SystemSharedLibs = object.Properties.System_shared_libs |
Colin Cross | 137d7da | 2021-06-21 16:41:29 -0700 | [diff] [blame] | 246 | if deps.SystemSharedLibs == nil { |
Colin Cross | 6b8f425 | 2021-07-22 11:39:44 -0700 | [diff] [blame] | 247 | // Provide a default set of shared libraries if system_shared_libs is unspecified. |
Colin Cross | 137d7da | 2021-06-21 16:41:29 -0700 | [diff] [blame] | 248 | // Note: If an empty list [] is specified, it implies that the module declines the |
| 249 | // default shared libraries. |
| 250 | deps.SystemSharedLibs = append(deps.SystemSharedLibs, ctx.toolchain().DefaultSharedLibraries()...) |
| 251 | } |
| 252 | deps.LateSharedLibs = append(deps.LateSharedLibs, deps.SystemSharedLibs...) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 253 | return deps |
| 254 | } |
| 255 | |
Pete Bentley | 74c9bba | 2019-08-16 20:25:06 +0100 | [diff] [blame] | 256 | func (object *objectLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags { |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 257 | flags.Global.LdFlags = append(flags.Global.LdFlags, ctx.toolchain().ToolchainLdflags()) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 258 | |
Pete Bentley | 74c9bba | 2019-08-16 20:25:06 +0100 | [diff] [blame] | 259 | if lds := android.OptionalPathForModuleSrc(ctx, object.Properties.Linker_script); lds.Valid() { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 260 | flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,-T,"+lds.String()) |
Pete Bentley | 74c9bba | 2019-08-16 20:25:06 +0100 | [diff] [blame] | 261 | flags.LdFlagsDeps = append(flags.LdFlagsDeps, lds.Path()) |
| 262 | } |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 263 | return flags |
| 264 | } |
| 265 | |
| 266 | func (object *objectLinker) link(ctx ModuleContext, |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 267 | flags Flags, deps PathDeps, objs Objects) android.Path { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 268 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 269 | objs = objs.Append(deps.Objs) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 270 | |
| 271 | var outputFile android.Path |
Dan Willemsen | efb1dd9 | 2017-09-18 22:47:20 -0700 | [diff] [blame] | 272 | builderFlags := flagsToBuilderFlags(flags) |
Colin Cross | fb44cd2 | 2022-09-09 15:11:16 -0700 | [diff] [blame] | 273 | outputName := ctx.ModuleName() |
| 274 | if !strings.HasSuffix(outputName, objectExtension) { |
| 275 | outputName += objectExtension |
| 276 | } |
Dan Willemsen | efb1dd9 | 2017-09-18 22:47:20 -0700 | [diff] [blame] | 277 | |
Pete Bentley | ab65ba9 | 2019-10-18 12:39:56 +0100 | [diff] [blame] | 278 | if len(objs.objFiles) == 1 && String(object.Properties.Linker_script) == "" { |
Colin Cross | fb44cd2 | 2022-09-09 15:11:16 -0700 | [diff] [blame] | 279 | output := android.PathForModuleOut(ctx, outputName) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 280 | outputFile = output |
Dan Willemsen | efb1dd9 | 2017-09-18 22:47:20 -0700 | [diff] [blame] | 281 | |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 282 | if String(object.Properties.Prefix_symbols) != "" { |
Colin Cross | fb44cd2 | 2022-09-09 15:11:16 -0700 | [diff] [blame] | 283 | transformBinaryPrefixSymbols(ctx, String(object.Properties.Prefix_symbols), objs.objFiles[0], |
| 284 | builderFlags, output) |
| 285 | } else { |
| 286 | ctx.Build(pctx, android.BuildParams{ |
| 287 | Rule: android.Cp, |
| 288 | Input: objs.objFiles[0], |
| 289 | Output: output, |
| 290 | }) |
| 291 | } |
| 292 | } else { |
| 293 | output := android.PathForModuleOut(ctx, outputName) |
| 294 | outputFile = output |
| 295 | |
| 296 | if String(object.Properties.Prefix_symbols) != "" { |
| 297 | input := android.PathForModuleOut(ctx, "unprefixed", outputName) |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 298 | transformBinaryPrefixSymbols(ctx, String(object.Properties.Prefix_symbols), input, |
Dan Willemsen | efb1dd9 | 2017-09-18 22:47:20 -0700 | [diff] [blame] | 299 | builderFlags, output) |
| 300 | output = input |
| 301 | } |
| 302 | |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 303 | transformObjsToObj(ctx, objs.objFiles, builderFlags, output, flags.LdFlagsDeps) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | ctx.CheckbuildFile(outputFile) |
| 307 | return outputFile |
| 308 | } |
Jiyong Park | af6d895 | 2019-01-31 12:21:23 +0900 | [diff] [blame] | 309 | |
Colin Cross | 137d7da | 2021-06-21 16:41:29 -0700 | [diff] [blame] | 310 | func (object *objectLinker) linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps { |
| 311 | specifiedDeps.sharedLibs = append(specifiedDeps.sharedLibs, object.Properties.Shared_libs...) |
| 312 | |
Colin Cross | 6b8f425 | 2021-07-22 11:39:44 -0700 | [diff] [blame] | 313 | // Must distinguish nil and [] in system_shared_libs - ensure that [] in |
Colin Cross | 137d7da | 2021-06-21 16:41:29 -0700 | [diff] [blame] | 314 | // either input list doesn't come out as nil. |
Colin Cross | 6b8f425 | 2021-07-22 11:39:44 -0700 | [diff] [blame] | 315 | if specifiedDeps.systemSharedLibs == nil { |
| 316 | specifiedDeps.systemSharedLibs = object.Properties.System_shared_libs |
Colin Cross | 137d7da | 2021-06-21 16:41:29 -0700 | [diff] [blame] | 317 | } else { |
Colin Cross | 6b8f425 | 2021-07-22 11:39:44 -0700 | [diff] [blame] | 318 | specifiedDeps.systemSharedLibs = append(specifiedDeps.systemSharedLibs, object.Properties.System_shared_libs...) |
Colin Cross | 137d7da | 2021-06-21 16:41:29 -0700 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | return specifiedDeps |
| 322 | } |
| 323 | |
Jiyong Park | af6d895 | 2019-01-31 12:21:23 +0900 | [diff] [blame] | 324 | func (object *objectLinker) unstrippedOutputFilePath() android.Path { |
| 325 | return nil |
| 326 | } |
Pirama Arumuga Nainar | 65c95ff | 2019-03-25 10:21:31 -0700 | [diff] [blame] | 327 | |
| 328 | func (object *objectLinker) nativeCoverage() bool { |
| 329 | return true |
| 330 | } |
Jiyong Park | ee9a98d | 2019-08-09 14:44:36 +0900 | [diff] [blame] | 331 | |
| 332 | func (object *objectLinker) coverageOutputFilePath() android.OptionalPath { |
| 333 | return android.OptionalPath{} |
| 334 | } |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 335 | |
| 336 | func (object *objectLinker) object() bool { |
| 337 | return true |
| 338 | } |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 339 | |
| 340 | func (object *objectLinker) isCrt() bool { |
| 341 | return Bool(object.Properties.Crt) |
| 342 | } |