blob: d0f4f207aa10895b207701624b335ea58e1551c3 [file] [log] [blame]
Colin Cross4d9c2d12016-07-29 12:48:20 -07001// Copyright 2016 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17import (
18 "fmt"
19
Colin Cross4d9c2d12016-07-29 12:48:20 -070020 "android/soong/android"
21)
22
23//
24// Objects (for crt*.o)
25//
26
27func init() {
Colin Cross798bfce2016-10-12 14:28:16 -070028 android.RegisterModuleType("cc_object", objectFactory)
Colin Cross4d9c2d12016-07-29 12:48:20 -070029}
30
31type objectLinker struct {
Colin Crossb916a382016-07-29 17:28:03 -070032 *baseLinker
Colin Cross4d9c2d12016-07-29 12:48:20 -070033 Properties ObjectLinkerProperties
34}
35
Colin Cross36242852017-06-23 15:06:31 -070036func objectFactory() android.Module {
Dan Willemsen967c6a92016-11-17 00:30:56 -080037 module := newBaseModule(android.HostAndDeviceSupported, android.MultilibBoth)
Colin Crossb916a382016-07-29 17:28:03 -070038 module.linker = &objectLinker{
39 baseLinker: NewBaseLinker(),
40 }
41 module.compiler = NewBaseCompiler()
Colin Cross4d9c2d12016-07-29 12:48:20 -070042 return module.Init()
43}
44
45func (object *objectLinker) appendLdflags(flags []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -070046 panic(fmt.Errorf("appendLdflags on objectLinker not supported"))
Colin Cross4d9c2d12016-07-29 12:48:20 -070047}
48
Colin Cross42742b82016-08-01 13:20:05 -070049func (object *objectLinker) linkerProps() []interface{} {
Colin Cross4d9c2d12016-07-29 12:48:20 -070050 return []interface{}{&object.Properties}
51}
52
Colin Cross42742b82016-08-01 13:20:05 -070053func (*objectLinker) linkerInit(ctx BaseModuleContext) {}
Colin Cross4d9c2d12016-07-29 12:48:20 -070054
Colin Cross37047f12016-12-13 17:06:13 -080055func (object *objectLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
Colin Cross87dd9632017-11-03 13:31:05 -070056 if ctx.useVndk() && ctx.toolchain().Bionic() {
Dan Willemsen0c162932017-09-18 16:33:37 -070057 // Needed for VNDK builds where bionic headers aren't automatically added.
58 deps.LateSharedLibs = append(deps.LateSharedLibs, "libc")
59 }
60
Colin Cross4d9c2d12016-07-29 12:48:20 -070061 deps.ObjFiles = append(deps.ObjFiles, object.Properties.Objs...)
62 return deps
63}
64
Colin Cross42742b82016-08-01 13:20:05 -070065func (*objectLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
Colin Cross4d9c2d12016-07-29 12:48:20 -070066 if flags.Clang {
67 flags.LdFlags = append(flags.LdFlags, ctx.toolchain().ToolchainClangLdflags())
68 } else {
69 flags.LdFlags = append(flags.LdFlags, ctx.toolchain().ToolchainLdflags())
70 }
71
72 return flags
73}
74
75func (object *objectLinker) link(ctx ModuleContext,
Dan Willemsen5cb580f2016-09-26 17:33:01 -070076 flags Flags, deps PathDeps, objs Objects) android.Path {
Colin Cross4d9c2d12016-07-29 12:48:20 -070077
Dan Willemsen5cb580f2016-09-26 17:33:01 -070078 objs = objs.Append(deps.Objs)
Colin Cross4d9c2d12016-07-29 12:48:20 -070079
80 var outputFile android.Path
Dan Willemsenefb1dd92017-09-18 22:47:20 -070081 builderFlags := flagsToBuilderFlags(flags)
82
Dan Willemsen5cb580f2016-09-26 17:33:01 -070083 if len(objs.objFiles) == 1 {
84 outputFile = objs.objFiles[0]
Dan Willemsenefb1dd92017-09-18 22:47:20 -070085
Nan Zhang0007d812017-11-07 10:57:05 -080086 if String(object.Properties.Prefix_symbols) != "" {
Dan Willemsenefb1dd92017-09-18 22:47:20 -070087 output := android.PathForModuleOut(ctx, ctx.ModuleName()+objectExtension)
Nan Zhang0007d812017-11-07 10:57:05 -080088 TransformBinaryPrefixSymbols(ctx, String(object.Properties.Prefix_symbols), outputFile,
Dan Willemsenefb1dd92017-09-18 22:47:20 -070089 builderFlags, output)
90 outputFile = output
91 }
Colin Cross4d9c2d12016-07-29 12:48:20 -070092 } else {
93 output := android.PathForModuleOut(ctx, ctx.ModuleName()+objectExtension)
Colin Cross4d9c2d12016-07-29 12:48:20 -070094 outputFile = output
Dan Willemsenefb1dd92017-09-18 22:47:20 -070095
Nan Zhang0007d812017-11-07 10:57:05 -080096 if String(object.Properties.Prefix_symbols) != "" {
Dan Willemsenefb1dd92017-09-18 22:47:20 -070097 input := android.PathForModuleOut(ctx, "unprefixed", ctx.ModuleName()+objectExtension)
Nan Zhang0007d812017-11-07 10:57:05 -080098 TransformBinaryPrefixSymbols(ctx, String(object.Properties.Prefix_symbols), input,
Dan Willemsenefb1dd92017-09-18 22:47:20 -070099 builderFlags, output)
100 output = input
101 }
102
103 TransformObjsToObj(ctx, objs.objFiles, builderFlags, output)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700104 }
105
106 ctx.CheckbuildFile(outputFile)
107 return outputFile
108}