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