Merge "Ignore shared libs for static executables."
This commit is contained in:
14
cc/binary.go
14
cc/binary.go
@@ -299,9 +299,6 @@ func (binary *binaryDecorator) link(ctx ModuleContext,
|
|||||||
|
|
||||||
var linkerDeps android.Paths
|
var linkerDeps android.Paths
|
||||||
|
|
||||||
sharedLibs := deps.SharedLibs
|
|
||||||
sharedLibs = append(sharedLibs, deps.LateSharedLibs...)
|
|
||||||
|
|
||||||
if deps.LinkerFlagsFile.Valid() {
|
if deps.LinkerFlagsFile.Valid() {
|
||||||
flags.LdFlags = append(flags.LdFlags, "$$(cat "+deps.LinkerFlagsFile.String()+")")
|
flags.LdFlags = append(flags.LdFlags, "$$(cat "+deps.LinkerFlagsFile.String()+")")
|
||||||
linkerDeps = append(linkerDeps, deps.LinkerFlagsFile.Path())
|
linkerDeps = append(linkerDeps, deps.LinkerFlagsFile.Path())
|
||||||
@@ -363,8 +360,15 @@ func (binary *binaryDecorator) link(ctx ModuleContext,
|
|||||||
binary.injectHostBionicLinkerSymbols(ctx, outputFile, deps.DynamicLinker.Path(), injectedOutputFile)
|
binary.injectHostBionicLinkerSymbols(ctx, outputFile, deps.DynamicLinker.Path(), injectedOutputFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
linkerDeps = append(linkerDeps, deps.SharedLibsDeps...)
|
var sharedLibs android.Paths
|
||||||
linkerDeps = append(linkerDeps, deps.LateSharedLibsDeps...)
|
// Ignore shared libs for static executables.
|
||||||
|
if !binary.static() {
|
||||||
|
sharedLibs = deps.SharedLibs
|
||||||
|
sharedLibs = append(sharedLibs, deps.LateSharedLibs...)
|
||||||
|
linkerDeps = append(linkerDeps, deps.SharedLibsDeps...)
|
||||||
|
linkerDeps = append(linkerDeps, deps.LateSharedLibsDeps...)
|
||||||
|
}
|
||||||
|
|
||||||
linkerDeps = append(linkerDeps, objs.tidyFiles...)
|
linkerDeps = append(linkerDeps, objs.tidyFiles...)
|
||||||
linkerDeps = append(linkerDeps, flags.LdFlagsDeps...)
|
linkerDeps = append(linkerDeps, flags.LdFlagsDeps...)
|
||||||
|
|
||||||
|
@@ -53,6 +53,7 @@ func TestMain(m *testing.M) {
|
|||||||
|
|
||||||
func createTestContext(t *testing.T, config android.Config, bp string) *android.TestContext {
|
func createTestContext(t *testing.T, config android.Config, bp string) *android.TestContext {
|
||||||
ctx := android.NewTestArchContext()
|
ctx := android.NewTestArchContext()
|
||||||
|
ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(binaryFactory))
|
||||||
ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(LibraryFactory))
|
ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(LibraryFactory))
|
||||||
ctx.RegisterModuleType("cc_library_shared", android.ModuleFactoryAdaptor(LibrarySharedFactory))
|
ctx.RegisterModuleType("cc_library_shared", android.ModuleFactoryAdaptor(LibrarySharedFactory))
|
||||||
ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(LibraryHeaderFactory))
|
ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(LibraryHeaderFactory))
|
||||||
@@ -193,12 +194,24 @@ func createTestContext(t *testing.T, config android.Config, bp string) *android.
|
|||||||
vendor_available: true,
|
vendor_available: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cc_object {
|
||||||
|
name: "crtbegin_static",
|
||||||
|
recovery_available: true,
|
||||||
|
vendor_available: true,
|
||||||
|
}
|
||||||
|
|
||||||
cc_object {
|
cc_object {
|
||||||
name: "crtend_so",
|
name: "crtend_so",
|
||||||
recovery_available: true,
|
recovery_available: true,
|
||||||
vendor_available: true,
|
vendor_available: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cc_object {
|
||||||
|
name: "crtend_android",
|
||||||
|
recovery_available: true,
|
||||||
|
vendor_available: true,
|
||||||
|
}
|
||||||
|
|
||||||
cc_library {
|
cc_library {
|
||||||
name: "libprotobuf-cpp-lite",
|
name: "libprotobuf-cpp-lite",
|
||||||
}
|
}
|
||||||
@@ -1845,3 +1858,28 @@ func TestVersionedStubs(t *testing.T) {
|
|||||||
t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags)
|
t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStaticExecutable(t *testing.T) {
|
||||||
|
ctx := testCc(t, `
|
||||||
|
cc_binary {
|
||||||
|
name: "static_test",
|
||||||
|
srcs: ["foo.c"],
|
||||||
|
static_executable: true,
|
||||||
|
}`)
|
||||||
|
|
||||||
|
variant := "android_arm64_armv8-a_core"
|
||||||
|
binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld")
|
||||||
|
libFlags := binModuleRule.Args["libFlags"]
|
||||||
|
systemStaticLibs := []string{"libc.a", "libm.a", "libdl.a"}
|
||||||
|
for _, lib := range systemStaticLibs {
|
||||||
|
if !strings.Contains(libFlags, lib) {
|
||||||
|
t.Errorf("Static lib %q was not found in %q", lib, libFlags)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"}
|
||||||
|
for _, lib := range systemSharedLibs {
|
||||||
|
if strings.Contains(libFlags, lib) {
|
||||||
|
t.Errorf("Shared lib %q was found in %q", lib, libFlags)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user