cc: fix host gcc libraries
Host gcc libraries should only apply to static binaries, not all static libraries. Add c.staticBinary(), and rework everything else to use c.static(), removing c.shared(). Change-Id: I8addae9b6848010cef94d873f48e7e358e4f5059
This commit is contained in:
60
cc/cc.go
60
cc/cc.go
@@ -688,6 +688,7 @@ type CCLinked struct {
|
|||||||
dynamicProperties struct {
|
dynamicProperties struct {
|
||||||
VariantIsShared bool `blueprint:"mutated"`
|
VariantIsShared bool `blueprint:"mutated"`
|
||||||
VariantIsStatic bool `blueprint:"mutated"`
|
VariantIsStatic bool `blueprint:"mutated"`
|
||||||
|
VariantIsStaticBinary bool `blueprint:"mutated"`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -732,10 +733,10 @@ func (c *CCLinked) stl(ctx common.AndroidBaseContext) string {
|
|||||||
case "none":
|
case "none":
|
||||||
return ""
|
return ""
|
||||||
case "":
|
case "":
|
||||||
if c.shared() {
|
if c.static() {
|
||||||
return "libc++" // TODO: mingw needs libstdc++
|
|
||||||
} else {
|
|
||||||
return "libc++_static"
|
return "libc++_static"
|
||||||
|
} else {
|
||||||
|
return "libc++" // TODO: mingw needs libstdc++
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
ctx.ModuleErrorf("stl: %q is not a supported STL", c.Properties.Stl)
|
ctx.ModuleErrorf("stl: %q is not a supported STL", c.Properties.Stl)
|
||||||
@@ -762,10 +763,10 @@ func (c *CCLinked) flags(ctx common.AndroidModuleContext, flags CCFlags) CCFlags
|
|||||||
flags.CppFlags = append(flags.CppFlags, "-nostdinc++")
|
flags.CppFlags = append(flags.CppFlags, "-nostdinc++")
|
||||||
flags.LdFlags = append(flags.LdFlags, "-nodefaultlibs")
|
flags.LdFlags = append(flags.LdFlags, "-nodefaultlibs")
|
||||||
flags.LdFlags = append(flags.LdFlags, "-lm", "-lpthread")
|
flags.LdFlags = append(flags.LdFlags, "-lm", "-lpthread")
|
||||||
if c.shared() {
|
if c.staticBinary() {
|
||||||
flags.LdFlags = append(flags.LdFlags, hostDynamicGccLibs...)
|
|
||||||
} else {
|
|
||||||
flags.LdFlags = append(flags.LdFlags, hostStaticGccLibs...)
|
flags.LdFlags = append(flags.LdFlags, hostStaticGccLibs...)
|
||||||
|
} else {
|
||||||
|
flags.LdFlags = append(flags.LdFlags, hostDynamicGccLibs...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "stlport", "stlport_static":
|
case "stlport", "stlport_static":
|
||||||
@@ -795,10 +796,10 @@ func (c *CCLinked) flags(ctx common.AndroidModuleContext, flags CCFlags) CCFlags
|
|||||||
if ctx.Host() {
|
if ctx.Host() {
|
||||||
flags.CppFlags = append(flags.CppFlags, "-nostdinc++")
|
flags.CppFlags = append(flags.CppFlags, "-nostdinc++")
|
||||||
flags.LdFlags = append(flags.LdFlags, "-nodefaultlibs")
|
flags.LdFlags = append(flags.LdFlags, "-nodefaultlibs")
|
||||||
if c.shared() {
|
if c.staticBinary() {
|
||||||
flags.LdFlags = append(flags.LdFlags, hostDynamicGccLibs...)
|
|
||||||
} else {
|
|
||||||
flags.LdFlags = append(flags.LdFlags, hostStaticGccLibs...)
|
flags.LdFlags = append(flags.LdFlags, hostStaticGccLibs...)
|
||||||
|
} else {
|
||||||
|
flags.LdFlags = append(flags.LdFlags, hostDynamicGccLibs...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@@ -851,7 +852,7 @@ func (c *CCLinked) depNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDe
|
|||||||
// libgcc and libatomic have to be last on the command line
|
// libgcc and libatomic have to be last on the command line
|
||||||
depNames.LateStaticLibs = append(depNames.LateStaticLibs, "libgcov", "libatomic", "libgcc")
|
depNames.LateStaticLibs = append(depNames.LateStaticLibs, "libgcov", "libatomic", "libgcc")
|
||||||
|
|
||||||
if c.shared() {
|
if !c.static() {
|
||||||
depNames.SharedLibs = append(depNames.SharedLibs, c.systemSharedLibs(ctx)...)
|
depNames.SharedLibs = append(depNames.SharedLibs, c.systemSharedLibs(ctx)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -874,12 +875,13 @@ type ccLinkedInterface interface {
|
|||||||
buildShared() bool
|
buildShared() bool
|
||||||
|
|
||||||
// Sets whether a specific variant is static or shared
|
// Sets whether a specific variant is static or shared
|
||||||
setStatic()
|
setStatic(bool)
|
||||||
setShared()
|
|
||||||
|
|
||||||
// Returns whether a specific variant is static or shared
|
// Returns whether a specific variant is a static library or binary
|
||||||
static() bool
|
static() bool
|
||||||
shared() bool
|
|
||||||
|
// Returns whether a module is a static binary
|
||||||
|
staticBinary() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ ccLinkedInterface = (*CCLibrary)(nil)
|
var _ ccLinkedInterface = (*CCLibrary)(nil)
|
||||||
@@ -889,16 +891,12 @@ func (c *CCLinked) static() bool {
|
|||||||
return c.dynamicProperties.VariantIsStatic
|
return c.dynamicProperties.VariantIsStatic
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CCLinked) shared() bool {
|
func (c *CCLinked) staticBinary() bool {
|
||||||
return c.dynamicProperties.VariantIsShared
|
return c.dynamicProperties.VariantIsStaticBinary
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CCLinked) setStatic() {
|
func (c *CCLinked) setStatic(static bool) {
|
||||||
c.dynamicProperties.VariantIsStatic = true
|
c.dynamicProperties.VariantIsStatic = static
|
||||||
}
|
|
||||||
|
|
||||||
func (c *CCLinked) setShared() {
|
|
||||||
c.dynamicProperties.VariantIsShared = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ccExportedFlagsProducer interface {
|
type ccExportedFlagsProducer interface {
|
||||||
@@ -973,7 +971,7 @@ func CCLibraryFactory() (blueprint.Module, []interface{}) {
|
|||||||
|
|
||||||
func (c *CCLibrary) depNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps {
|
func (c *CCLibrary) depNames(ctx common.AndroidBaseContext, depNames CCDeps) CCDeps {
|
||||||
depNames = c.CCLinked.depNames(ctx, depNames)
|
depNames = c.CCLinked.depNames(ctx, depNames)
|
||||||
if c.shared() {
|
if !c.static() {
|
||||||
if ctx.Device() {
|
if ctx.Device() {
|
||||||
depNames.CrtBegin = "crtbegin_so"
|
depNames.CrtBegin = "crtbegin_so"
|
||||||
depNames.CrtEnd = "crtend_so"
|
depNames.CrtEnd = "crtend_so"
|
||||||
@@ -1012,7 +1010,7 @@ func (c *CCLibrary) flags(ctx common.AndroidModuleContext, flags CCFlags) CCFlag
|
|||||||
|
|
||||||
flags.CFlags = append(flags.CFlags, "-fPIC")
|
flags.CFlags = append(flags.CFlags, "-fPIC")
|
||||||
|
|
||||||
if c.shared() {
|
if !c.static() {
|
||||||
libName := ctx.ModuleName()
|
libName := ctx.ModuleName()
|
||||||
// GCC for Android assumes that -shared means -Bsymbolic, use -Wl,-shared instead
|
// GCC for Android assumes that -shared means -Bsymbolic, use -Wl,-shared instead
|
||||||
sharedFlag := "-Wl,-shared"
|
sharedFlag := "-Wl,-shared"
|
||||||
@@ -1242,6 +1240,12 @@ func CCBinaryFactory() (blueprint.Module, []interface{}) {
|
|||||||
return NewCCBinary(module, module, common.HostAndDeviceSupported)
|
return NewCCBinary(module, module, common.HostAndDeviceSupported)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *CCBinary) ModifyProperties(ctx common.AndroidBaseContext) {
|
||||||
|
if c.BinaryProperties.Static_executable {
|
||||||
|
c.dynamicProperties.VariantIsStaticBinary = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *CCBinary) flags(ctx common.AndroidModuleContext, flags CCFlags) CCFlags {
|
func (c *CCBinary) flags(ctx common.AndroidModuleContext, flags CCFlags) CCFlags {
|
||||||
flags = c.CCLinked.flags(ctx, flags)
|
flags = c.CCLinked.flags(ctx, flags)
|
||||||
|
|
||||||
@@ -1631,14 +1635,14 @@ func LinkageMutator(mctx blueprint.EarlyMutatorContext) {
|
|||||||
var modules []blueprint.Module
|
var modules []blueprint.Module
|
||||||
if c.buildStatic() && c.buildShared() {
|
if c.buildStatic() && c.buildShared() {
|
||||||
modules = mctx.CreateLocalVariations("static", "shared")
|
modules = mctx.CreateLocalVariations("static", "shared")
|
||||||
modules[0].(ccLinkedInterface).setStatic()
|
modules[0].(ccLinkedInterface).setStatic(true)
|
||||||
modules[1].(ccLinkedInterface).setShared()
|
modules[1].(ccLinkedInterface).setStatic(false)
|
||||||
} else if c.buildStatic() {
|
} else if c.buildStatic() {
|
||||||
modules = mctx.CreateLocalVariations("static")
|
modules = mctx.CreateLocalVariations("static")
|
||||||
modules[0].(ccLinkedInterface).setStatic()
|
modules[0].(ccLinkedInterface).setStatic(true)
|
||||||
} else if c.buildShared() {
|
} else if c.buildShared() {
|
||||||
modules = mctx.CreateLocalVariations("shared")
|
modules = mctx.CreateLocalVariations("shared")
|
||||||
modules[0].(ccLinkedInterface).setShared()
|
modules[0].(ccLinkedInterface).setStatic(false)
|
||||||
} else {
|
} else {
|
||||||
panic(fmt.Errorf("ccLibrary %q not static or shared", mctx.ModuleName()))
|
panic(fmt.Errorf("ccLibrary %q not static or shared", mctx.ModuleName()))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user