summaryrefslogtreecommitdiff
path: root/cc/binary.go
diff options
context:
space:
mode:
Diffstat (limited to 'cc/binary.go')
-rw-r--r--cc/binary.go73
1 files changed, 48 insertions, 25 deletions
diff --git a/cc/binary.go b/cc/binary.go
index 2a6ceb821..251b7f0c4 100644
--- a/cc/binary.go
+++ b/cc/binary.go
@@ -50,11 +50,18 @@ type BinaryLinkerProperties struct {
// binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
// from PRODUCT_PACKAGES.
Overrides []string
+
+ // Inject boringssl hash into the shared library. This is only intended for use by external/boringssl.
+ Inject_bssl_hash *bool `android:"arch_variant"`
}
func init() {
- android.RegisterModuleType("cc_binary", BinaryFactory)
- android.RegisterModuleType("cc_binary_host", binaryHostFactory)
+ RegisterBinaryBuildComponents(android.InitRegistrationContext)
+}
+
+func RegisterBinaryBuildComponents(ctx android.RegistrationContext) {
+ ctx.RegisterModuleType("cc_binary", BinaryFactory)
+ ctx.RegisterModuleType("cc_binary_host", binaryHostFactory)
}
// cc_binary produces a binary that is runnable on a device.
@@ -106,13 +113,17 @@ func (binary *binaryDecorator) linkerProps() []interface{} {
}
-func (binary *binaryDecorator) getStem(ctx BaseModuleContext) string {
+func (binary *binaryDecorator) getStemWithoutSuffix(ctx BaseModuleContext) string {
stem := ctx.baseModuleName()
if String(binary.Properties.Stem) != "" {
stem = String(binary.Properties.Stem)
}
- return stem + String(binary.Properties.Suffix)
+ return stem
+}
+
+func (binary *binaryDecorator) getStem(ctx BaseModuleContext) string {
+ return binary.getStemWithoutSuffix(ctx) + String(binary.Properties.Suffix)
}
func (binary *binaryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
@@ -151,7 +162,7 @@ func (binary *binaryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
if binary.static() {
if ctx.selectedStl() == "libc++_static" {
- deps.StaticLibs = append(deps.StaticLibs, "libm", "libc", "libdl")
+ deps.StaticLibs = append(deps.StaticLibs, "libm", "libc")
}
// static libraries libcompiler_rt, libc and libc_nomalloc need to be linked with
// --start-group/--end-group along with libgcc. If they are in deps.StaticLibs,
@@ -189,6 +200,11 @@ func NewBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) {
module.compiler = NewBaseCompiler()
module.linker = binary
module.installer = binary
+
+ // Allow module to be added as member of an sdk/module_exports.
+ module.sdkMemberTypes = []android.SdkMemberType{
+ ccBinarySdkMemberType,
+ }
return module, binary
}
@@ -215,12 +231,16 @@ func (binary *binaryDecorator) staticBinary() bool {
return binary.static()
}
+func (binary *binaryDecorator) binary() bool {
+ return true
+}
+
func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
flags = binary.baseLinker.linkerFlags(ctx, flags)
if ctx.Host() && !ctx.Windows() && !binary.static() {
if !ctx.Config().IsEnvTrue("DISABLE_HOST_PIE") {
- flags.LdFlags = append(flags.LdFlags, "-pie")
+ flags.Global.LdFlags = append(flags.Global.LdFlags, "-pie")
}
}
@@ -228,7 +248,7 @@ func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags
// all code is position independent, and then those warnings get promoted to
// errors.
if !ctx.Windows() {
- flags.CFlags = append(flags.CFlags, "-fPIE")
+ flags.Global.CFlags = append(flags.Global.CFlags, "-fPIE")
}
if ctx.toolchain().Bionic() {
@@ -237,11 +257,11 @@ func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags
// However, bionic/linker uses -shared to overwrite.
// Linker for x86 targets does not allow coexistance of -static and -shared,
// so we add -static only if -shared is not used.
- if !inList("-shared", flags.LdFlags) {
- flags.LdFlags = append(flags.LdFlags, "-static")
+ if !inList("-shared", flags.Local.LdFlags) {
+ flags.Global.LdFlags = append(flags.Global.LdFlags, "-static")
}
- flags.LdFlags = append(flags.LdFlags,
+ flags.Global.LdFlags = append(flags.Global.LdFlags,
"-nostdlib",
"-Bstatic",
"-Wl,--gc-sections",
@@ -253,7 +273,7 @@ func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags
} else {
switch ctx.Os() {
case android.Android:
- if ctx.bootstrap() && !ctx.inRecovery() {
+ if ctx.bootstrap() && !ctx.inRecovery() && !ctx.inRamdisk() {
flags.DynamicLinker = "/system/bin/bootstrap/linker"
} else {
flags.DynamicLinker = "/system/bin/linker"
@@ -271,14 +291,14 @@ func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags
if ctx.Os() == android.LinuxBionic {
// Use the dlwrap entry point, but keep _start around so
// that it can be used by host_bionic_inject
- flags.LdFlags = append(flags.LdFlags,
+ flags.Global.LdFlags = append(flags.Global.LdFlags,
"-Wl,--entry=__dlwrap__start",
"-Wl,--undefined=_start",
)
}
}
- flags.LdFlags = append(flags.LdFlags,
+ flags.Global.LdFlags = append(flags.Global.LdFlags,
"-pie",
"-nostdlib",
"-Bdynamic",
@@ -288,10 +308,10 @@ func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags
}
} else {
if binary.static() {
- flags.LdFlags = append(flags.LdFlags, "-static")
+ flags.Global.LdFlags = append(flags.Global.LdFlags, "-static")
}
if ctx.Darwin() {
- flags.LdFlags = append(flags.LdFlags, "-Wl,-headerpad_max_install_names")
+ flags.Global.LdFlags = append(flags.Global.LdFlags, "-Wl,-headerpad_max_install_names")
}
}
@@ -308,14 +328,14 @@ func (binary *binaryDecorator) link(ctx ModuleContext,
var linkerDeps android.Paths
if deps.LinkerFlagsFile.Valid() {
- flags.LdFlags = append(flags.LdFlags, "$$(cat "+deps.LinkerFlagsFile.String()+")")
+ flags.Local.LdFlags = append(flags.Local.LdFlags, "$$(cat "+deps.LinkerFlagsFile.String()+")")
linkerDeps = append(linkerDeps, deps.LinkerFlagsFile.Path())
}
if flags.DynamicLinker != "" {
- flags.LdFlags = append(flags.LdFlags, "-Wl,-dynamic-linker,"+flags.DynamicLinker)
+ flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,-dynamic-linker,"+flags.DynamicLinker)
} else if ctx.toolchain().Bionic() && !binary.static() {
- flags.LdFlags = append(flags.LdFlags, "-Wl,--no-dynamic-linker")
+ flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--no-dynamic-linker")
}
builderFlags := flagsToBuilderFlags(flags)
@@ -326,7 +346,7 @@ func (binary *binaryDecorator) link(ctx ModuleContext,
}
strippedOutputFile := outputFile
outputFile = android.PathForModuleOut(ctx, "unstripped", fileName)
- binary.stripper.strip(ctx, outputFile, strippedOutputFile, builderFlags)
+ binary.stripper.stripExecutableOrSharedLib(ctx, outputFile, strippedOutputFile, builderFlags)
}
binary.unstrippedOutputFile = outputFile
@@ -338,6 +358,8 @@ func (binary *binaryDecorator) link(ctx ModuleContext,
flagsToBuilderFlags(flags), afterPrefixSymbols)
}
+ outputFile = maybeInjectBoringSSLHash(ctx, outputFile, binary.Properties.Inject_bssl_hash, fileName)
+
if Bool(binary.baseLinker.Properties.Use_version_lib) {
if ctx.Host() {
versionedOutputFile := outputFile
@@ -350,7 +372,7 @@ func (binary *binaryDecorator) link(ctx ModuleContext,
if binary.stripper.needsStrip(ctx) {
out := android.PathForModuleOut(ctx, "versioned-stripped", fileName)
binary.distFile = android.OptionalPathForPath(out)
- binary.stripper.strip(ctx, versionedOutputFile, out, builderFlags)
+ binary.stripper.stripExecutableOrSharedLib(ctx, versionedOutputFile, out, builderFlags)
}
binary.injectVersionSymbol(ctx, outputFile, versionedOutputFile)
@@ -384,7 +406,7 @@ func (binary *binaryDecorator) link(ctx ModuleContext,
TransformObjToDynamicBinary(ctx, objs.objFiles, sharedLibs, deps.StaticLibs,
deps.LateStaticLibs, deps.WholeStaticLibs, linkerDeps, deps.CrtBegin, deps.CrtEnd, true,
- builderFlags, outputFile)
+ builderFlags, outputFile, nil)
objs.coverageFiles = append(objs.coverageFiles, deps.StaticLibObjs.coverageFiles...)
objs.coverageFiles = append(objs.coverageFiles, deps.WholeStaticLibObjs.coverageFiles...)
@@ -398,11 +420,11 @@ func (binary *binaryDecorator) link(ctx ModuleContext,
}
if Bool(binary.Properties.Symlink_preferred_arch) {
- if String(binary.Properties.Stem) == "" && String(binary.Properties.Suffix) == "" {
- ctx.PropertyErrorf("symlink_preferred_arch", "must also specify stem or suffix")
+ if String(binary.Properties.Suffix) == "" {
+ ctx.PropertyErrorf("symlink_preferred_arch", "must also specify suffix")
}
if ctx.TargetPrimary() {
- binary.symlinks = append(binary.symlinks, ctx.baseModuleName())
+ binary.symlinks = append(binary.symlinks, binary.getStemWithoutSuffix(ctx))
}
}
@@ -444,7 +466,8 @@ func (binary *binaryDecorator) install(ctx ModuleContext, file android.Path) {
// Bionic binaries (e.g. linker) is installed to the bootstrap subdirectory.
// The original path becomes a symlink to the corresponding file in the
// runtime APEX.
- if installToBootstrap(ctx.baseModuleName(), ctx.Config()) && ctx.Arch().Native && ctx.apexName() == "" && !ctx.inRecovery() {
+ translatedArch := ctx.Target().NativeBridge == android.NativeBridgeEnabled
+ if InstallToBootstrap(ctx.baseModuleName(), ctx.Config()) && !translatedArch && ctx.apexName() == "" && !ctx.inRamdisk() && !ctx.inRecovery() {
if ctx.Device() && isBionic(ctx.baseModuleName()) {
binary.installSymlinkToRuntimeApex(ctx, file)
}