Dedup version-script handling code.
This is common to binaries and libraries, so move it from library.link and binary.link to baseLinker.linkerFlags and baseLinker.linkerDeps. Test: make checkbuild Bug: None Change-Id: I5fb24118e601673ae0713a6adc773a1565749be8
This commit is contained in:
17
cc/binary.go
17
cc/binary.go
@@ -31,9 +31,6 @@ type BinaryLinkerProperties struct {
|
|||||||
// if set, add an extra objcopy --prefix-symbols= step
|
// if set, add an extra objcopy --prefix-symbols= step
|
||||||
Prefix_symbols *string
|
Prefix_symbols *string
|
||||||
|
|
||||||
// local file name to pass to the linker as --version_script
|
|
||||||
Version_script *string `android:"arch_variant"`
|
|
||||||
|
|
||||||
// if set, install a symlink to the preferred architecture
|
// if set, install a symlink to the preferred architecture
|
||||||
Symlink_preferred_arch *bool
|
Symlink_preferred_arch *bool
|
||||||
|
|
||||||
@@ -163,8 +160,6 @@ func (binary *binaryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
|||||||
"from static libs or set static_executable: true")
|
"from static libs or set static_executable: true")
|
||||||
}
|
}
|
||||||
|
|
||||||
android.ExtractSourceDeps(ctx, binary.Properties.Version_script)
|
|
||||||
|
|
||||||
return deps
|
return deps
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,7 +170,7 @@ func (binary *binaryDecorator) isDependencyRoot() bool {
|
|||||||
func NewBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) {
|
func NewBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) {
|
||||||
module := newModule(hod, android.MultilibFirst)
|
module := newModule(hod, android.MultilibFirst)
|
||||||
binary := &binaryDecorator{
|
binary := &binaryDecorator{
|
||||||
baseLinker: NewBaseLinker(),
|
baseLinker: NewBaseLinker(module.sanitize),
|
||||||
baseInstaller: NewBaseInstaller("bin", "", InstallInSystem),
|
baseInstaller: NewBaseInstaller("bin", "", InstallInSystem),
|
||||||
}
|
}
|
||||||
module.compiler = NewBaseCompiler()
|
module.compiler = NewBaseCompiler()
|
||||||
@@ -281,7 +276,6 @@ func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags
|
|||||||
func (binary *binaryDecorator) link(ctx ModuleContext,
|
func (binary *binaryDecorator) link(ctx ModuleContext,
|
||||||
flags Flags, deps PathDeps, objs Objects) android.Path {
|
flags Flags, deps PathDeps, objs Objects) android.Path {
|
||||||
|
|
||||||
versionScript := ctx.ExpandOptionalSource(binary.Properties.Version_script, "version_script")
|
|
||||||
fileName := binary.getStem(ctx) + flags.Toolchain.ExecutableSuffix()
|
fileName := binary.getStem(ctx) + flags.Toolchain.ExecutableSuffix()
|
||||||
outputFile := android.PathForModuleOut(ctx, fileName)
|
outputFile := android.PathForModuleOut(ctx, fileName)
|
||||||
ret := outputFile
|
ret := outputFile
|
||||||
@@ -291,15 +285,6 @@ func (binary *binaryDecorator) link(ctx ModuleContext,
|
|||||||
sharedLibs := deps.SharedLibs
|
sharedLibs := deps.SharedLibs
|
||||||
sharedLibs = append(sharedLibs, deps.LateSharedLibs...)
|
sharedLibs = append(sharedLibs, deps.LateSharedLibs...)
|
||||||
|
|
||||||
if versionScript.Valid() {
|
|
||||||
if ctx.Darwin() {
|
|
||||||
ctx.PropertyErrorf("version_script", "Not supported on Darwin")
|
|
||||||
} else {
|
|
||||||
flags.LdFlags = append(flags.LdFlags, "-Wl,--version-script,"+versionScript.String())
|
|
||||||
linkerDeps = append(linkerDeps, versionScript.Path())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if deps.LinkerScript.Valid() {
|
if deps.LinkerScript.Valid() {
|
||||||
flags.LdFlags = append(flags.LdFlags, "-Wl,-T,"+deps.LinkerScript.String())
|
flags.LdFlags = append(flags.LdFlags, "-Wl,-T,"+deps.LinkerScript.String())
|
||||||
linkerDeps = append(linkerDeps, deps.LinkerScript.Path())
|
linkerDeps = append(linkerDeps, deps.LinkerScript.Path())
|
||||||
|
@@ -44,8 +44,6 @@ type LibraryProperties struct {
|
|||||||
Shared_libs []string `android:"arch_variant"`
|
Shared_libs []string `android:"arch_variant"`
|
||||||
} `android:"arch_variant"`
|
} `android:"arch_variant"`
|
||||||
|
|
||||||
// local file name to pass to the linker as --version_script
|
|
||||||
Version_script *string `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
|
||||||
Unexported_symbols_list *string `android:"arch_variant"`
|
Unexported_symbols_list *string `android:"arch_variant"`
|
||||||
// local file name to pass to the linker as -force_symbols_not_weak_list
|
// local file name to pass to the linker as -force_symbols_not_weak_list
|
||||||
@@ -65,12 +63,6 @@ type LibraryProperties struct {
|
|||||||
// export headers generated from .proto sources
|
// export headers generated from .proto sources
|
||||||
Export_proto_headers *bool
|
Export_proto_headers *bool
|
||||||
}
|
}
|
||||||
Target struct {
|
|
||||||
Vendor struct {
|
|
||||||
// version script for this vendor variant
|
|
||||||
Version_script *string `android:"arch_variant"`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Static_ndk_lib *bool
|
Static_ndk_lib *bool
|
||||||
}
|
}
|
||||||
@@ -231,8 +223,6 @@ type libraryDecorator struct {
|
|||||||
// shlib suffix.
|
// shlib suffix.
|
||||||
libName string
|
libName string
|
||||||
|
|
||||||
sanitize *sanitize
|
|
||||||
|
|
||||||
sabi *sabi
|
sabi *sabi
|
||||||
|
|
||||||
// Output archive of gcno coverage information files
|
// Output archive of gcno coverage information files
|
||||||
@@ -432,7 +422,7 @@ func (library *libraryDecorator) getLibName(ctx ModuleContext) string {
|
|||||||
|
|
||||||
func (library *libraryDecorator) linkerInit(ctx BaseModuleContext) {
|
func (library *libraryDecorator) linkerInit(ctx BaseModuleContext) {
|
||||||
location := InstallInSystem
|
location := InstallInSystem
|
||||||
if library.sanitize.inSanitizerDir() {
|
if library.baseLinker.sanitize.inSanitizerDir() {
|
||||||
location = InstallInSanitizerDir
|
location = InstallInSanitizerDir
|
||||||
}
|
}
|
||||||
library.baseInstaller.location = location
|
library.baseInstaller.location = location
|
||||||
@@ -483,11 +473,9 @@ func (library *libraryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
|||||||
deps.StaticLibs = removeListFromList(deps.StaticLibs, library.baseLinker.Properties.Target.Recovery.Exclude_static_libs)
|
deps.StaticLibs = removeListFromList(deps.StaticLibs, library.baseLinker.Properties.Target.Recovery.Exclude_static_libs)
|
||||||
}
|
}
|
||||||
|
|
||||||
android.ExtractSourceDeps(ctx, library.Properties.Version_script)
|
|
||||||
android.ExtractSourceDeps(ctx, library.Properties.Unexported_symbols_list)
|
android.ExtractSourceDeps(ctx, library.Properties.Unexported_symbols_list)
|
||||||
android.ExtractSourceDeps(ctx, library.Properties.Force_symbols_not_weak_list)
|
android.ExtractSourceDeps(ctx, library.Properties.Force_symbols_not_weak_list)
|
||||||
android.ExtractSourceDeps(ctx, library.Properties.Force_symbols_weak_list)
|
android.ExtractSourceDeps(ctx, library.Properties.Force_symbols_weak_list)
|
||||||
android.ExtractSourceDeps(ctx, library.Properties.Target.Vendor.Version_script)
|
|
||||||
|
|
||||||
return deps
|
return deps
|
||||||
}
|
}
|
||||||
@@ -526,23 +514,10 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext,
|
|||||||
var linkerDeps android.Paths
|
var linkerDeps android.Paths
|
||||||
linkerDeps = append(linkerDeps, flags.LdFlagsDeps...)
|
linkerDeps = append(linkerDeps, flags.LdFlagsDeps...)
|
||||||
|
|
||||||
versionScript := ctx.ExpandOptionalSource(library.Properties.Version_script, "version_script")
|
|
||||||
unexportedSymbols := ctx.ExpandOptionalSource(library.Properties.Unexported_symbols_list, "unexported_symbols_list")
|
unexportedSymbols := ctx.ExpandOptionalSource(library.Properties.Unexported_symbols_list, "unexported_symbols_list")
|
||||||
forceNotWeakSymbols := ctx.ExpandOptionalSource(library.Properties.Force_symbols_not_weak_list, "force_symbols_not_weak_list")
|
forceNotWeakSymbols := ctx.ExpandOptionalSource(library.Properties.Force_symbols_not_weak_list, "force_symbols_not_weak_list")
|
||||||
forceWeakSymbols := ctx.ExpandOptionalSource(library.Properties.Force_symbols_weak_list, "force_symbols_weak_list")
|
forceWeakSymbols := ctx.ExpandOptionalSource(library.Properties.Force_symbols_weak_list, "force_symbols_weak_list")
|
||||||
if ctx.useVndk() && library.Properties.Target.Vendor.Version_script != nil {
|
|
||||||
versionScript = ctx.ExpandOptionalSource(library.Properties.Target.Vendor.Version_script, "target.vendor.version_script")
|
|
||||||
}
|
|
||||||
if !ctx.Darwin() {
|
if !ctx.Darwin() {
|
||||||
if versionScript.Valid() {
|
|
||||||
flags.LdFlags = append(flags.LdFlags, "-Wl,--version-script,"+versionScript.String())
|
|
||||||
linkerDeps = append(linkerDeps, versionScript.Path())
|
|
||||||
if library.sanitize.isSanitizerEnabled(cfi) {
|
|
||||||
cfiExportsMap := android.PathForSource(ctx, cfiExportsMapPath)
|
|
||||||
flags.LdFlags = append(flags.LdFlags, "-Wl,--version-script,"+cfiExportsMap.String())
|
|
||||||
linkerDeps = append(linkerDeps, cfiExportsMap)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if unexportedSymbols.Valid() {
|
if unexportedSymbols.Valid() {
|
||||||
ctx.PropertyErrorf("unexported_symbols_list", "Only supported on Darwin")
|
ctx.PropertyErrorf("unexported_symbols_list", "Only supported on Darwin")
|
||||||
}
|
}
|
||||||
@@ -553,9 +528,6 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext,
|
|||||||
ctx.PropertyErrorf("force_symbols_weak_list", "Only supported on Darwin")
|
ctx.PropertyErrorf("force_symbols_weak_list", "Only supported on Darwin")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if versionScript.Valid() {
|
|
||||||
ctx.PropertyErrorf("version_script", "Not supported on Darwin")
|
|
||||||
}
|
|
||||||
if unexportedSymbols.Valid() {
|
if unexportedSymbols.Valid() {
|
||||||
flags.LdFlags = append(flags.LdFlags, "-Wl,-unexported_symbols_list,"+unexportedSymbols.String())
|
flags.LdFlags = append(flags.LdFlags, "-Wl,-unexported_symbols_list,"+unexportedSymbols.String())
|
||||||
linkerDeps = append(linkerDeps, unexportedSymbols.Path())
|
linkerDeps = append(linkerDeps, unexportedSymbols.Path())
|
||||||
@@ -768,7 +740,7 @@ func (library *libraryDecorator) install(ctx ModuleContext, file android.Path) {
|
|||||||
|
|
||||||
if Bool(library.Properties.Static_ndk_lib) && library.static() &&
|
if Bool(library.Properties.Static_ndk_lib) && library.static() &&
|
||||||
!ctx.useVndk() && !ctx.inRecovery() && ctx.Device() &&
|
!ctx.useVndk() && !ctx.inRecovery() && ctx.Device() &&
|
||||||
library.sanitize.isUnsanitizedVariant() {
|
library.baseLinker.sanitize.isUnsanitizedVariant() {
|
||||||
installPath := getNdkSysrootBase(ctx).Join(
|
installPath := getNdkSysrootBase(ctx).Join(
|
||||||
ctx, "usr/lib", config.NDKTriple(ctx.toolchain()), file.Base())
|
ctx, "usr/lib", config.NDKTriple(ctx.toolchain()), file.Base())
|
||||||
|
|
||||||
@@ -827,9 +799,8 @@ func NewLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator)
|
|||||||
BuildStatic: true,
|
BuildStatic: true,
|
||||||
},
|
},
|
||||||
baseCompiler: NewBaseCompiler(),
|
baseCompiler: NewBaseCompiler(),
|
||||||
baseLinker: NewBaseLinker(),
|
baseLinker: NewBaseLinker(module.sanitize),
|
||||||
baseInstaller: NewBaseInstaller("lib", "lib64", InstallInSystem),
|
baseInstaller: NewBaseInstaller("lib", "lib64", InstallInSystem),
|
||||||
sanitize: module.sanitize,
|
|
||||||
sabi: module.sabi,
|
sabi: module.sabi,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
48
cc/linker.go
48
cc/linker.go
@@ -127,10 +127,20 @@ type BaseLinkerProperties struct {
|
|||||||
type MoreBaseLinkerProperties struct {
|
type MoreBaseLinkerProperties struct {
|
||||||
// Generate compact dynamic relocation table, default true.
|
// Generate compact dynamic relocation table, default true.
|
||||||
Pack_relocations *bool `android:"arch_variant"`
|
Pack_relocations *bool `android:"arch_variant"`
|
||||||
|
|
||||||
|
// local file name to pass to the linker as --version_script
|
||||||
|
Version_script *string `android:"arch_variant"`
|
||||||
|
|
||||||
|
Target struct {
|
||||||
|
Vendor struct {
|
||||||
|
// version script for this vendor variant
|
||||||
|
Version_script *string `android:"arch_variant"`
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBaseLinker() *baseLinker {
|
func NewBaseLinker(sanitize *sanitize) *baseLinker {
|
||||||
return &baseLinker{}
|
return &baseLinker{sanitize: sanitize}
|
||||||
}
|
}
|
||||||
|
|
||||||
// baseLinker provides support for shared_libs, static_libs, and whole_static_libs properties
|
// baseLinker provides support for shared_libs, static_libs, and whole_static_libs properties
|
||||||
@@ -140,6 +150,8 @@ type baseLinker struct {
|
|||||||
dynamicProperties struct {
|
dynamicProperties struct {
|
||||||
RunPaths []string `blueprint:"mutated"`
|
RunPaths []string `blueprint:"mutated"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sanitize *sanitize
|
||||||
}
|
}
|
||||||
|
|
||||||
func (linker *baseLinker) appendLdflags(flags []string) {
|
func (linker *baseLinker) appendLdflags(flags []string) {
|
||||||
@@ -158,7 +170,7 @@ func (linker *baseLinker) linkerProps() []interface{} {
|
|||||||
return []interface{}{&linker.Properties, &linker.MoreProperties, &linker.dynamicProperties}
|
return []interface{}{&linker.Properties, &linker.MoreProperties, &linker.dynamicProperties}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (linker *baseLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Deps {
|
func (linker *baseLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
||||||
deps.WholeStaticLibs = append(deps.WholeStaticLibs, linker.Properties.Whole_static_libs...)
|
deps.WholeStaticLibs = append(deps.WholeStaticLibs, linker.Properties.Whole_static_libs...)
|
||||||
deps.HeaderLibs = append(deps.HeaderLibs, linker.Properties.Header_libs...)
|
deps.HeaderLibs = append(deps.HeaderLibs, linker.Properties.Header_libs...)
|
||||||
deps.StaticLibs = append(deps.StaticLibs, linker.Properties.Static_libs...)
|
deps.StaticLibs = append(deps.StaticLibs, linker.Properties.Static_libs...)
|
||||||
@@ -237,6 +249,10 @@ func (linker *baseLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Deps {
|
|||||||
deps.LateStaticLibs = append(deps.LateStaticLibs, "libwinpthread")
|
deps.LateStaticLibs = append(deps.LateStaticLibs, "libwinpthread")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
android.ExtractSourceDeps(ctx, linker.MoreProperties.Version_script)
|
||||||
|
android.ExtractSourceDeps(ctx,
|
||||||
|
linker.MoreProperties.Target.Vendor.Version_script)
|
||||||
|
|
||||||
return deps
|
return deps
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -345,6 +361,32 @@ func (linker *baseLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
|||||||
flags.GroupStaticLibs = true
|
flags.GroupStaticLibs = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
versionScript := ctx.ExpandOptionalSource(
|
||||||
|
linker.MoreProperties.Version_script, "version_script")
|
||||||
|
|
||||||
|
if ctx.useVndk() && linker.MoreProperties.Target.Vendor.Version_script != nil {
|
||||||
|
versionScript = ctx.ExpandOptionalSource(
|
||||||
|
linker.MoreProperties.Target.Vendor.Version_script,
|
||||||
|
"target.vendor.version_script")
|
||||||
|
}
|
||||||
|
|
||||||
|
if versionScript.Valid() {
|
||||||
|
if ctx.Darwin() {
|
||||||
|
ctx.PropertyErrorf("version_script", "Not supported on Darwin")
|
||||||
|
} else {
|
||||||
|
flags.LdFlags = append(flags.LdFlags,
|
||||||
|
"-Wl,--version-script,"+versionScript.String())
|
||||||
|
flags.LdFlagsDeps = append(flags.LdFlagsDeps, versionScript.Path())
|
||||||
|
|
||||||
|
if linker.sanitize.isSanitizerEnabled(cfi) {
|
||||||
|
cfiExportsMap := android.PathForSource(ctx, cfiExportsMapPath)
|
||||||
|
flags.LdFlags = append(flags.LdFlags,
|
||||||
|
"-Wl,--version-script,"+cfiExportsMap.String())
|
||||||
|
flags.LdFlagsDeps = append(flags.LdFlagsDeps, cfiExportsMap)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -68,7 +68,7 @@ func ndkPrebuiltObjectFactory() android.Module {
|
|||||||
module := newBaseModule(android.DeviceSupported, android.MultilibBoth)
|
module := newBaseModule(android.DeviceSupported, android.MultilibBoth)
|
||||||
module.linker = &ndkPrebuiltObjectLinker{
|
module.linker = &ndkPrebuiltObjectLinker{
|
||||||
objectLinker: objectLinker{
|
objectLinker: objectLinker{
|
||||||
baseLinker: NewBaseLinker(),
|
baseLinker: NewBaseLinker(nil),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
module.Properties.HideFromMake = true
|
module.Properties.HideFromMake = true
|
||||||
|
@@ -36,7 +36,7 @@ type objectLinker struct {
|
|||||||
func objectFactory() android.Module {
|
func objectFactory() android.Module {
|
||||||
module := newBaseModule(android.HostAndDeviceSupported, android.MultilibBoth)
|
module := newBaseModule(android.HostAndDeviceSupported, android.MultilibBoth)
|
||||||
module.linker = &objectLinker{
|
module.linker = &objectLinker{
|
||||||
baseLinker: NewBaseLinker(),
|
baseLinker: NewBaseLinker(nil),
|
||||||
}
|
}
|
||||||
module.compiler = NewBaseCompiler()
|
module.compiler = NewBaseCompiler()
|
||||||
return module.Init()
|
return module.Init()
|
||||||
|
Reference in New Issue
Block a user