blob: b9c57429dd3ff86f32672a93dd687ffb032b799d [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 Crosse40b4ea2018-10-02 22:25:58 -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 Crosse40b4ea2018-10-02 22:25:58 -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{
Dan Albert61f32122018-07-26 14:00:24 -070039 baseLinker: NewBaseLinker(nil),
Colin Crossb916a382016-07-29 17:28:03 -070040 }
41 module.compiler = NewBaseCompiler()
Peter Collingbourne486e42c2018-10-25 10:53:44 -070042
43 // Clang's address-significance tables are incompatible with ld -r.
44 module.compiler.appendCflags([]string{"-fno-addrsig"})
45
Colin Cross907769f2018-09-27 11:02:39 -070046 module.stl = &stl{}
Colin Cross4d9c2d12016-07-29 12:48:20 -070047 return module.Init()
48}
49
50func (object *objectLinker) appendLdflags(flags []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -070051 panic(fmt.Errorf("appendLdflags on objectLinker not supported"))
Colin Cross4d9c2d12016-07-29 12:48:20 -070052}
53
Colin Cross42742b82016-08-01 13:20:05 -070054func (object *objectLinker) linkerProps() []interface{} {
Colin Cross4d9c2d12016-07-29 12:48:20 -070055 return []interface{}{&object.Properties}
56}
57
Colin Cross42742b82016-08-01 13:20:05 -070058func (*objectLinker) linkerInit(ctx BaseModuleContext) {}
Colin Cross4d9c2d12016-07-29 12:48:20 -070059
Colin Cross37047f12016-12-13 17:06:13 -080060func (object *objectLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
Colin Cross87dd9632017-11-03 13:31:05 -070061 if ctx.useVndk() && ctx.toolchain().Bionic() {
Dan Willemsen0c162932017-09-18 16:33:37 -070062 // Needed for VNDK builds where bionic headers aren't automatically added.
63 deps.LateSharedLibs = append(deps.LateSharedLibs, "libc")
64 }
65
Colin Cross4d9c2d12016-07-29 12:48:20 -070066 deps.ObjFiles = append(deps.ObjFiles, object.Properties.Objs...)
67 return deps
68}
69
Colin Cross42742b82016-08-01 13:20:05 -070070func (*objectLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
Dan Willemsen8536d6b2018-10-07 20:54:34 -070071 flags.LdFlags = append(flags.LdFlags, ctx.toolchain().ToolchainClangLdflags())
Colin Cross4d9c2d12016-07-29 12:48:20 -070072
73 return flags
74}
75
76func (object *objectLinker) link(ctx ModuleContext,
Dan Willemsen5cb580f2016-09-26 17:33:01 -070077 flags Flags, deps PathDeps, objs Objects) android.Path {
Colin Cross4d9c2d12016-07-29 12:48:20 -070078
Dan Willemsen5cb580f2016-09-26 17:33:01 -070079 objs = objs.Append(deps.Objs)
Colin Cross4d9c2d12016-07-29 12:48:20 -070080
81 var outputFile android.Path
Dan Willemsenefb1dd92017-09-18 22:47:20 -070082 builderFlags := flagsToBuilderFlags(flags)
83
Dan Willemsen5cb580f2016-09-26 17:33:01 -070084 if len(objs.objFiles) == 1 {
85 outputFile = objs.objFiles[0]
Dan Willemsenefb1dd92017-09-18 22:47:20 -070086
Nan Zhang0007d812017-11-07 10:57:05 -080087 if String(object.Properties.Prefix_symbols) != "" {
Dan Willemsenefb1dd92017-09-18 22:47:20 -070088 output := android.PathForModuleOut(ctx, ctx.ModuleName()+objectExtension)
Nan Zhang0007d812017-11-07 10:57:05 -080089 TransformBinaryPrefixSymbols(ctx, String(object.Properties.Prefix_symbols), outputFile,
Dan Willemsenefb1dd92017-09-18 22:47:20 -070090 builderFlags, output)
91 outputFile = output
92 }
Colin Cross4d9c2d12016-07-29 12:48:20 -070093 } else {
94 output := android.PathForModuleOut(ctx, ctx.ModuleName()+objectExtension)
Colin Cross4d9c2d12016-07-29 12:48:20 -070095 outputFile = output
Dan Willemsenefb1dd92017-09-18 22:47:20 -070096
Nan Zhang0007d812017-11-07 10:57:05 -080097 if String(object.Properties.Prefix_symbols) != "" {
Dan Willemsenefb1dd92017-09-18 22:47:20 -070098 input := android.PathForModuleOut(ctx, "unprefixed", ctx.ModuleName()+objectExtension)
Nan Zhang0007d812017-11-07 10:57:05 -080099 TransformBinaryPrefixSymbols(ctx, String(object.Properties.Prefix_symbols), input,
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700100 builderFlags, output)
101 output = input
102 }
103
104 TransformObjsToObj(ctx, objs.objFiles, builderFlags, output)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700105 }
106
107 ctx.CheckbuildFile(outputFile)
108 return outputFile
109}
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900110
111func (object *objectLinker) unstrippedOutputFilePath() android.Path {
112 return nil
113}