From 648c8aed4c7d6702c8cfdce02fe514ebd2620686 Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Thu, 21 Jul 2016 16:42:14 -0700 Subject: [PATCH] Support unique_host_soname to add -host for shared libs In order to distinguish our host libraries from system installed libraries, support a flag to automatically append -host to host shared libraries names. Previously, we were implementing this with different modules, but with Soong, we'd really like to share the module definitions. This properly exports the module to make, so that LOCAL_SHARED_LIBRARIES := libcrypto still works, but the final installed name is libcrypto-host.so. Change-Id: I63389469fe1b38078b8bbf4c0fd92e54ef90ae1a --- cc/androidmk.go | 1 + cc/cc.go | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/cc/androidmk.go b/cc/androidmk.go index 70e1f474c..4f76dc9e3 100644 --- a/cc/androidmk.go +++ b/cc/androidmk.go @@ -99,6 +99,7 @@ func (library *libraryLinker) AndroidMk(ctx AndroidMkContext, ret *android.Andro } fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+outputFile.Ext()) + fmt.Fprintln(w, "LOCAL_BUILT_MODULE_STEM := $(LOCAL_MODULE)$(LOCAL_MODULE_SUFFIX)") fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=") diff --git a/cc/cc.go b/cc/cc.go index acc807f46..6054bc4c2 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -402,6 +402,9 @@ type LibraryLinkerProperties struct { // local file name to pass to the linker as -force_symbols_weak_list Force_symbols_weak_list *string `android:"arch_variant"` + // rename host libraries to prevent overlap with system installed libraries + Unique_host_soname *bool + VariantName string `blueprint:"mutated"` } @@ -1605,11 +1608,23 @@ func (library *libraryLinker) props() []interface{} { &library.stripper.StripProperties) } +func (library *libraryLinker) getLibName(ctx ModuleContext) string { + name := ctx.ModuleName() + + if Bool(library.Properties.Unique_host_soname) { + if !strings.HasSuffix(name, "-host") { + name = name + "-host" + } + } + + return name + library.Properties.VariantName +} + func (library *libraryLinker) flags(ctx ModuleContext, flags Flags) Flags { flags = library.baseLinker.flags(ctx, flags) if !library.static() { - libName := ctx.ModuleName() + library.Properties.VariantName + libName := library.getLibName(ctx) // GCC for Android assumes that -shared means -Bsymbolic, use -Wl,-shared instead sharedFlag := "-Wl,-shared" if flags.Clang || ctx.Host() { @@ -1729,7 +1744,7 @@ func (library *libraryLinker) linkShared(ctx ModuleContext, } } - fileName := ctx.ModuleName() + library.Properties.VariantName + flags.Toolchain.ShlibSuffix() + fileName := library.getLibName(ctx) + flags.Toolchain.ShlibSuffix() outputFile := android.PathForModuleOut(ctx, fileName) ret := outputFile