Merge "Apply system_shared_libs to static libraries"
This commit is contained in:
@@ -32,19 +32,21 @@ type LibraryProperties struct {
|
|||||||
Srcs []string `android:"arch_variant"`
|
Srcs []string `android:"arch_variant"`
|
||||||
Cflags []string `android:"arch_variant"`
|
Cflags []string `android:"arch_variant"`
|
||||||
|
|
||||||
Enabled *bool `android:"arch_variant"`
|
Enabled *bool `android:"arch_variant"`
|
||||||
Whole_static_libs []string `android:"arch_variant"`
|
Whole_static_libs []string `android:"arch_variant"`
|
||||||
Static_libs []string `android:"arch_variant"`
|
Static_libs []string `android:"arch_variant"`
|
||||||
Shared_libs []string `android:"arch_variant"`
|
Shared_libs []string `android:"arch_variant"`
|
||||||
|
System_shared_libs []string `android:"arch_variant"`
|
||||||
} `android:"arch_variant"`
|
} `android:"arch_variant"`
|
||||||
Shared struct {
|
Shared struct {
|
||||||
Srcs []string `android:"arch_variant"`
|
Srcs []string `android:"arch_variant"`
|
||||||
Cflags []string `android:"arch_variant"`
|
Cflags []string `android:"arch_variant"`
|
||||||
|
|
||||||
Enabled *bool `android:"arch_variant"`
|
Enabled *bool `android:"arch_variant"`
|
||||||
Whole_static_libs []string `android:"arch_variant"`
|
Whole_static_libs []string `android:"arch_variant"`
|
||||||
Static_libs []string `android:"arch_variant"`
|
Static_libs []string `android:"arch_variant"`
|
||||||
Shared_libs []string `android:"arch_variant"`
|
Shared_libs []string `android:"arch_variant"`
|
||||||
|
System_shared_libs []string `android:"arch_variant"`
|
||||||
} `android:"arch_variant"`
|
} `android:"arch_variant"`
|
||||||
|
|
||||||
// local file name to pass to the linker as -unexported_symbols_list
|
// local file name to pass to the linker as -unexported_symbols_list
|
||||||
@@ -488,6 +490,16 @@ func (library *libraryDecorator) linkerInit(ctx BaseModuleContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (library *libraryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
func (library *libraryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
||||||
|
if library.static() {
|
||||||
|
if library.Properties.Static.System_shared_libs != nil {
|
||||||
|
library.baseLinker.Properties.System_shared_libs = library.Properties.Static.System_shared_libs
|
||||||
|
}
|
||||||
|
} else if library.shared() {
|
||||||
|
if library.Properties.Shared.System_shared_libs != nil {
|
||||||
|
library.baseLinker.Properties.System_shared_libs = library.Properties.Shared.System_shared_libs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
deps = library.baseLinker.linkerDeps(ctx, deps)
|
deps = library.baseLinker.linkerDeps(ctx, deps)
|
||||||
|
|
||||||
if library.static() {
|
if library.static() {
|
||||||
@@ -921,8 +933,19 @@ func NewLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator)
|
|||||||
func reuseStaticLibrary(mctx android.BottomUpMutatorContext, static, shared *Module) {
|
func reuseStaticLibrary(mctx android.BottomUpMutatorContext, static, shared *Module) {
|
||||||
if staticCompiler, ok := static.compiler.(*libraryDecorator); ok {
|
if staticCompiler, ok := static.compiler.(*libraryDecorator); ok {
|
||||||
sharedCompiler := shared.compiler.(*libraryDecorator)
|
sharedCompiler := shared.compiler.(*libraryDecorator)
|
||||||
|
|
||||||
|
// Check libraries in addition to cflags, since libraries may be exporting different
|
||||||
|
// include directories.
|
||||||
if len(staticCompiler.Properties.Static.Cflags) == 0 &&
|
if len(staticCompiler.Properties.Static.Cflags) == 0 &&
|
||||||
len(sharedCompiler.Properties.Shared.Cflags) == 0 {
|
len(sharedCompiler.Properties.Shared.Cflags) == 0 &&
|
||||||
|
len(staticCompiler.Properties.Static.Whole_static_libs) == 0 &&
|
||||||
|
len(sharedCompiler.Properties.Shared.Whole_static_libs) == 0 &&
|
||||||
|
len(staticCompiler.Properties.Static.Static_libs) == 0 &&
|
||||||
|
len(sharedCompiler.Properties.Shared.Static_libs) == 0 &&
|
||||||
|
len(staticCompiler.Properties.Static.Shared_libs) == 0 &&
|
||||||
|
len(sharedCompiler.Properties.Shared.Shared_libs) == 0 &&
|
||||||
|
staticCompiler.Properties.Static.System_shared_libs == nil &&
|
||||||
|
sharedCompiler.Properties.Shared.System_shared_libs == nil {
|
||||||
|
|
||||||
mctx.AddInterVariantDependency(reuseObjTag, shared, static)
|
mctx.AddInterVariantDependency(reuseObjTag, shared, static)
|
||||||
sharedCompiler.baseCompiler.Properties.OriginalSrcs =
|
sharedCompiler.baseCompiler.Properties.OriginalSrcs =
|
||||||
|
57
cc/linker.go
57
cc/linker.go
@@ -49,7 +49,7 @@ type BaseLinkerProperties struct {
|
|||||||
// list of system libraries that will be dynamically linked to
|
// list of system libraries that will be dynamically linked to
|
||||||
// shared library and executable modules. If unset, generally defaults to libc,
|
// shared library and executable modules. If unset, generally defaults to libc,
|
||||||
// libm, and libdl. Set to [] to prevent linking against the defaults.
|
// libm, and libdl. Set to [] to prevent linking against the defaults.
|
||||||
System_shared_libs []string
|
System_shared_libs []string `android:"arch_variant"`
|
||||||
|
|
||||||
// allow the module to contain undefined symbols. By default,
|
// allow the module to contain undefined symbols. By default,
|
||||||
// modules cannot contain undefined symbols that are not satisified by their immediate
|
// modules cannot contain undefined symbols that are not satisified by their immediate
|
||||||
@@ -237,35 +237,34 @@ func (linker *baseLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
|||||||
deps.LateStaticLibs = append(deps.LateStaticLibs, "libgcc")
|
deps.LateStaticLibs = append(deps.LateStaticLibs, "libgcc")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.static() {
|
var systemSharedLibs []string
|
||||||
systemSharedLibs := linker.Properties.System_shared_libs
|
if !ctx.useSdk() && !ctx.useVndk() {
|
||||||
if systemSharedLibs == nil {
|
systemSharedLibs = linker.Properties.System_shared_libs
|
||||||
systemSharedLibs = []string{"libc", "libm", "libdl"}
|
|
||||||
}
|
|
||||||
|
|
||||||
if inList("libdl", deps.SharedLibs) {
|
|
||||||
// If system_shared_libs has libc but not libdl, make sure shared_libs does not
|
|
||||||
// have libdl to avoid loading libdl before libc.
|
|
||||||
if inList("libc", systemSharedLibs) {
|
|
||||||
if !inList("libdl", systemSharedLibs) {
|
|
||||||
ctx.PropertyErrorf("shared_libs",
|
|
||||||
"libdl must be in system_shared_libs, not shared_libs")
|
|
||||||
}
|
|
||||||
_, deps.SharedLibs = removeFromList("libdl", deps.SharedLibs)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If libc and libdl are both in system_shared_libs make sure libd comes after libc
|
|
||||||
// to avoid loading libdl before libc.
|
|
||||||
if inList("libdl", systemSharedLibs) && inList("libc", systemSharedLibs) &&
|
|
||||||
indexList("libdl", systemSharedLibs) < indexList("libc", systemSharedLibs) {
|
|
||||||
ctx.PropertyErrorf("system_shared_libs", "libdl must be after libc")
|
|
||||||
}
|
|
||||||
|
|
||||||
deps.LateSharedLibs = append(deps.LateSharedLibs, systemSharedLibs...)
|
|
||||||
} else if ctx.useSdk() || ctx.useVndk() {
|
|
||||||
deps.LateSharedLibs = append(deps.LateSharedLibs, "libc", "libm", "libdl")
|
|
||||||
}
|
}
|
||||||
|
if systemSharedLibs == nil {
|
||||||
|
systemSharedLibs = []string{"libc", "libm", "libdl"}
|
||||||
|
}
|
||||||
|
|
||||||
|
if inList("libdl", deps.SharedLibs) {
|
||||||
|
// If system_shared_libs has libc but not libdl, make sure shared_libs does not
|
||||||
|
// have libdl to avoid loading libdl before libc.
|
||||||
|
if inList("libc", systemSharedLibs) {
|
||||||
|
if !inList("libdl", systemSharedLibs) {
|
||||||
|
ctx.PropertyErrorf("shared_libs",
|
||||||
|
"libdl must be in system_shared_libs, not shared_libs")
|
||||||
|
}
|
||||||
|
_, deps.SharedLibs = removeFromList("libdl", deps.SharedLibs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If libc and libdl are both in system_shared_libs make sure libdl comes after libc
|
||||||
|
// to avoid loading libdl before libc.
|
||||||
|
if inList("libdl", systemSharedLibs) && inList("libc", systemSharedLibs) &&
|
||||||
|
indexList("libdl", systemSharedLibs) < indexList("libc", systemSharedLibs) {
|
||||||
|
ctx.PropertyErrorf("system_shared_libs", "libdl must be after libc")
|
||||||
|
}
|
||||||
|
|
||||||
|
deps.LateSharedLibs = append(deps.LateSharedLibs, systemSharedLibs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Windows() {
|
if ctx.Windows() {
|
||||||
|
Reference in New Issue
Block a user