Add version_script property

Add version_script property to cc_library to pass a file to
the linker with --version-script.

Change-Id: Ieefb04e15c8dfa72c2eb63b4349f8860222662b2
This commit is contained in:
Colin Cross 2015-07-06 17:48:31 -07:00
parent 2617316f6c
commit aee540a439
4 changed files with 31 additions and 4 deletions

View File

@ -236,6 +236,19 @@ func prependLocalModule(name string, prop *bpparser.Property, suffix *string) ([
}, nil
}
func versionScript(name string, prop *bpparser.Property, suffix *string) ([]string, error) {
if suffix != nil {
name += "_" + *suffix
}
val, err := valueToString(prop.Value)
if err != nil {
return nil, err
}
return []string{
fmt.Sprintf("%s += -Wl,--version-script,$(LOCAL_PATH)/%s\n", name, val),
}, nil
}
func (w *androidMkWriter) writeModule(moduleRule string, props []string,
disabledBuilds map[string]bool, isHostRule bool) {
disabledConditionals := disabledTargetConditionals

View File

@ -70,6 +70,7 @@ var rewriteProperties = map[string]struct {
"local_include_dirs": {"LOCAL_C_INCLUDES", prependLocalPath},
"export_include_dirs": {"LOCAL_EXPORT_C_INCLUDE_DIRS", prependLocalPath},
"suffix": {"LOCAL_MODULE_STEM", prependLocalModule},
"version_script": {"LOCAL_LDFLAGS", versionScript},
}
var ignoredProperties = map[string]bool{

View File

@ -277,7 +277,7 @@ func TransformDarwinObjToStaticLib(ctx common.AndroidModuleContext, objFiles []s
// Generate a rule for compiling multiple .o files, plus static libraries, whole static libraries,
// and shared libraires, to a shared library (.so) or dynamic executable
func TransformObjToDynamicBinary(ctx common.AndroidModuleContext,
objFiles, sharedLibs, staticLibs, lateStaticLibs, wholeStaticLibs []string,
objFiles, sharedLibs, staticLibs, lateStaticLibs, wholeStaticLibs, deps []string,
crtBegin, crtEnd string, groupLate bool, flags builderFlags, outputFile string) {
var ldCmd string
@ -323,7 +323,7 @@ func TransformObjToDynamicBinary(ctx common.AndroidModuleContext,
libFlagsList = append(libFlagsList, "-Wl,--end-group")
}
deps := []string{ldCmd}
deps = append(deps, ldCmd)
deps = append(deps, sharedLibs...)
deps = append(deps, staticLibs...)
deps = append(deps, lateStaticLibs...)

View File

@ -947,6 +947,9 @@ type CCLibraryProperties struct {
Static_libs []string `android:"arch_variant"`
Shared_libs []string `android:"arch_variant"`
} `android:"arch_variant"`
// local file name to pass to the linker as --version_script
Version_script string `android:"arch_variant"`
}
type CCLibrary struct {
@ -1128,8 +1131,16 @@ func (c *CCLibrary) compileSharedLibrary(ctx common.AndroidModuleContext,
outputFile := filepath.Join(common.ModuleOutDir(ctx), ctx.ModuleName()+sharedLibraryExtension)
var linkerDeps []string
if c.LibraryProperties.Version_script != "" {
versionScript := filepath.Join(common.ModuleSrcDir(ctx), c.LibraryProperties.Version_script)
sharedFlags.LdFlags = append(sharedFlags.LdFlags, "-Wl,--version-script,"+versionScript)
linkerDeps = append(linkerDeps, versionScript)
}
TransformObjToDynamicBinary(ctx, objFiles, deps.SharedLibs, deps.StaticLibs,
deps.LateStaticLibs, deps.WholeStaticLibs, deps.CrtBegin, deps.CrtEnd, false,
deps.LateStaticLibs, deps.WholeStaticLibs, linkerDeps, deps.CrtBegin, deps.CrtEnd, false,
ccFlagsToBuilderFlags(flags), outputFile)
c.out = outputFile
@ -1398,8 +1409,10 @@ func (c *CCBinary) compileModule(ctx common.AndroidModuleContext,
ccFlagsToBuilderFlags(flags), afterPrefixSymbols)
}
var linkerDeps []string
TransformObjToDynamicBinary(ctx, objFiles, deps.SharedLibs, deps.StaticLibs,
deps.LateStaticLibs, deps.WholeStaticLibs, deps.CrtBegin, deps.CrtEnd, true,
deps.LateStaticLibs, deps.WholeStaticLibs, linkerDeps, deps.CrtBegin, deps.CrtEnd, true,
ccFlagsToBuilderFlags(flags), outputFile)
}