Apply system_shared_libs to static libraries
Even though we aren't doing any linking for static libraries, the default libraries (libc, libm, libdl) are now exporting headers, so we should be using those for both static and shared libraries (especially when re-using objects between the two). Without this we've been in a state where a cc_library will compile differently than a cc_library_shared, as we'd re-use the compilation units from the static variant in the shared library. This does require marking many of libc's dependencies as not using libc with system_shared_libs, otherwise we run into dependency loops. Test: treehugger Change-Id: Ie42edc5184f315f998db953594e425214b810e0e
This commit is contained in:
@@ -32,19 +32,21 @@ type LibraryProperties struct {
|
||||
Srcs []string `android:"arch_variant"`
|
||||
Cflags []string `android:"arch_variant"`
|
||||
|
||||
Enabled *bool `android:"arch_variant"`
|
||||
Whole_static_libs []string `android:"arch_variant"`
|
||||
Static_libs []string `android:"arch_variant"`
|
||||
Shared_libs []string `android:"arch_variant"`
|
||||
Enabled *bool `android:"arch_variant"`
|
||||
Whole_static_libs []string `android:"arch_variant"`
|
||||
Static_libs []string `android:"arch_variant"`
|
||||
Shared_libs []string `android:"arch_variant"`
|
||||
System_shared_libs []string `android:"arch_variant"`
|
||||
} `android:"arch_variant"`
|
||||
Shared struct {
|
||||
Srcs []string `android:"arch_variant"`
|
||||
Cflags []string `android:"arch_variant"`
|
||||
|
||||
Enabled *bool `android:"arch_variant"`
|
||||
Whole_static_libs []string `android:"arch_variant"`
|
||||
Static_libs []string `android:"arch_variant"`
|
||||
Shared_libs []string `android:"arch_variant"`
|
||||
Enabled *bool `android:"arch_variant"`
|
||||
Whole_static_libs []string `android:"arch_variant"`
|
||||
Static_libs []string `android:"arch_variant"`
|
||||
Shared_libs []string `android:"arch_variant"`
|
||||
System_shared_libs []string `android:"arch_variant"`
|
||||
} `android:"arch_variant"`
|
||||
|
||||
// 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 {
|
||||
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)
|
||||
|
||||
if library.static() {
|
||||
@@ -921,8 +933,19 @@ func NewLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator)
|
||||
func reuseStaticLibrary(mctx android.BottomUpMutatorContext, static, shared *Module) {
|
||||
if staticCompiler, ok := static.compiler.(*libraryDecorator); ok {
|
||||
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 &&
|
||||
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)
|
||||
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
|
||||
// shared library and executable modules. If unset, generally defaults to libc,
|
||||
// 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,
|
||||
// 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")
|
||||
}
|
||||
|
||||
if !ctx.static() {
|
||||
systemSharedLibs := linker.Properties.System_shared_libs
|
||||
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 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")
|
||||
var systemSharedLibs []string
|
||||
if !ctx.useSdk() && !ctx.useVndk() {
|
||||
systemSharedLibs = linker.Properties.System_shared_libs
|
||||
}
|
||||
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() {
|
||||
|
Reference in New Issue
Block a user