| 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" | 
|  | 19 |  | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 20 | "android/soong/android" | 
|  | 21 | ) | 
|  | 22 |  | 
|  | 23 | // | 
|  | 24 | // Objects (for crt*.o) | 
|  | 25 | // | 
|  | 26 |  | 
|  | 27 | func init() { | 
| Colin Cross | e40b4ea | 2018-10-02 22:25:58 -0700 | [diff] [blame] | 28 | android.RegisterModuleType("cc_object", ObjectFactory) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 29 | } | 
|  | 30 |  | 
|  | 31 | type objectLinker struct { | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 32 | *baseLinker | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 33 | Properties ObjectLinkerProperties | 
|  | 34 | } | 
|  | 35 |  | 
| Colin Cross | e40b4ea | 2018-10-02 22:25:58 -0700 | [diff] [blame] | 36 | func ObjectFactory() android.Module { | 
| Dan Willemsen | 967c6a9 | 2016-11-17 00:30:56 -0800 | [diff] [blame] | 37 | module := newBaseModule(android.HostAndDeviceSupported, android.MultilibBoth) | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 38 | module.linker = &objectLinker{ | 
| Dan Albert | 61f3212 | 2018-07-26 14:00:24 -0700 | [diff] [blame] | 39 | baseLinker: NewBaseLinker(nil), | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 40 | } | 
|  | 41 | module.compiler = NewBaseCompiler() | 
| Peter Collingbourne | 486e42c | 2018-10-25 10:53:44 -0700 | [diff] [blame] | 42 |  | 
|  | 43 | // Clang's address-significance tables are incompatible with ld -r. | 
|  | 44 | module.compiler.appendCflags([]string{"-fno-addrsig"}) | 
|  | 45 |  | 
| Colin Cross | 907769f | 2018-09-27 11:02:39 -0700 | [diff] [blame] | 46 | module.stl = &stl{} | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 47 | return module.Init() | 
|  | 48 | } | 
|  | 49 |  | 
|  | 50 | func (object *objectLinker) appendLdflags(flags []string) { | 
| Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 51 | panic(fmt.Errorf("appendLdflags on objectLinker not supported")) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 52 | } | 
|  | 53 |  | 
| Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 54 | func (object *objectLinker) linkerProps() []interface{} { | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 55 | return []interface{}{&object.Properties} | 
|  | 56 | } | 
|  | 57 |  | 
| Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 58 | func (*objectLinker) linkerInit(ctx BaseModuleContext) {} | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 59 |  | 
| Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 60 | func (object *objectLinker) linkerDeps(ctx DepsContext, deps Deps) Deps { | 
| Colin Cross | 87dd963 | 2017-11-03 13:31:05 -0700 | [diff] [blame] | 61 | if ctx.useVndk() && ctx.toolchain().Bionic() { | 
| Dan Willemsen | 0c16293 | 2017-09-18 16:33:37 -0700 | [diff] [blame] | 62 | // Needed for VNDK builds where bionic headers aren't automatically added. | 
|  | 63 | deps.LateSharedLibs = append(deps.LateSharedLibs, "libc") | 
|  | 64 | } | 
|  | 65 |  | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 66 | deps.ObjFiles = append(deps.ObjFiles, object.Properties.Objs...) | 
|  | 67 | return deps | 
|  | 68 | } | 
|  | 69 |  | 
| Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 70 | func (*objectLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags { | 
| Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 71 | flags.LdFlags = append(flags.LdFlags, ctx.toolchain().ToolchainClangLdflags()) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 72 |  | 
|  | 73 | return flags | 
|  | 74 | } | 
|  | 75 |  | 
|  | 76 | func (object *objectLinker) link(ctx ModuleContext, | 
| Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 77 | flags Flags, deps PathDeps, objs Objects) android.Path { | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 78 |  | 
| Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 79 | objs = objs.Append(deps.Objs) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 80 |  | 
|  | 81 | var outputFile android.Path | 
| Dan Willemsen | efb1dd9 | 2017-09-18 22:47:20 -0700 | [diff] [blame] | 82 | builderFlags := flagsToBuilderFlags(flags) | 
|  | 83 |  | 
| Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 84 | if len(objs.objFiles) == 1 { | 
|  | 85 | outputFile = objs.objFiles[0] | 
| Dan Willemsen | efb1dd9 | 2017-09-18 22:47:20 -0700 | [diff] [blame] | 86 |  | 
| Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 87 | if String(object.Properties.Prefix_symbols) != "" { | 
| Dan Willemsen | efb1dd9 | 2017-09-18 22:47:20 -0700 | [diff] [blame] | 88 | output := android.PathForModuleOut(ctx, ctx.ModuleName()+objectExtension) | 
| Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 89 | TransformBinaryPrefixSymbols(ctx, String(object.Properties.Prefix_symbols), outputFile, | 
| Dan Willemsen | efb1dd9 | 2017-09-18 22:47:20 -0700 | [diff] [blame] | 90 | builderFlags, output) | 
|  | 91 | outputFile = output | 
|  | 92 | } | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 93 | } else { | 
|  | 94 | output := android.PathForModuleOut(ctx, ctx.ModuleName()+objectExtension) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 95 | outputFile = output | 
| Dan Willemsen | efb1dd9 | 2017-09-18 22:47:20 -0700 | [diff] [blame] | 96 |  | 
| Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 97 | if String(object.Properties.Prefix_symbols) != "" { | 
| Dan Willemsen | efb1dd9 | 2017-09-18 22:47:20 -0700 | [diff] [blame] | 98 | input := android.PathForModuleOut(ctx, "unprefixed", ctx.ModuleName()+objectExtension) | 
| Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 99 | TransformBinaryPrefixSymbols(ctx, String(object.Properties.Prefix_symbols), input, | 
| Dan Willemsen | efb1dd9 | 2017-09-18 22:47:20 -0700 | [diff] [blame] | 100 | builderFlags, output) | 
|  | 101 | output = input | 
|  | 102 | } | 
|  | 103 |  | 
|  | 104 | TransformObjsToObj(ctx, objs.objFiles, builderFlags, output) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 105 | } | 
|  | 106 |  | 
|  | 107 | ctx.CheckbuildFile(outputFile) | 
|  | 108 | return outputFile | 
|  | 109 | } |