aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Albert <danalbert@google.com>2018-07-26 14:00:24 -0700
committerDan Albert <danalbert@google.com>2018-08-08 14:36:34 -0700
commit61f32128aa8e5dcd64a94b932575e161639a7e1c (patch)
tree8d6bbec99989ee44dd971748d60bd491a620a3d6
parent0981b5c30f31ba8caa38fde9540e85f61799d052 (diff)
downloadbuild_soong-61f32128aa8e5dcd64a94b932575e161639a7e1c.tar.gz
build_soong-61f32128aa8e5dcd64a94b932575e161639a7e1c.tar.bz2
build_soong-61f32128aa8e5dcd64a94b932575e161639a7e1c.zip
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
-rw-r--r--cc/binary.go17
-rw-r--r--cc/library.go35
-rw-r--r--cc/linker.go48
-rw-r--r--cc/ndk_prebuilt.go2
-rw-r--r--cc/object.go2
5 files changed, 51 insertions, 53 deletions
diff --git a/cc/binary.go b/cc/binary.go
index 82e1941f..be790325 100644
--- a/cc/binary.go
+++ b/cc/binary.go
@@ -31,9 +31,6 @@ type BinaryLinkerProperties struct {
// if set, add an extra objcopy --prefix-symbols= step
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
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")
}
- android.ExtractSourceDeps(ctx, binary.Properties.Version_script)
-
return deps
}
@@ -175,7 +170,7 @@ func (binary *binaryDecorator) isDependencyRoot() bool {
func NewBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) {
module := newModule(hod, android.MultilibFirst)
binary := &binaryDecorator{
- baseLinker: NewBaseLinker(),
+ baseLinker: NewBaseLinker(module.sanitize),
baseInstaller: NewBaseInstaller("bin", "", InstallInSystem),
}
module.compiler = NewBaseCompiler()
@@ -281,7 +276,6 @@ func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags
func (binary *binaryDecorator) link(ctx ModuleContext,
flags Flags, deps PathDeps, objs Objects) android.Path {
- versionScript := ctx.ExpandOptionalSource(binary.Properties.Version_script, "version_script")
fileName := binary.getStem(ctx) + flags.Toolchain.ExecutableSuffix()
outputFile := android.PathForModuleOut(ctx, fileName)
ret := outputFile
@@ -291,15 +285,6 @@ func (binary *binaryDecorator) link(ctx ModuleContext,
sharedLibs := deps.SharedLibs
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() {
flags.LdFlags = append(flags.LdFlags, "-Wl,-T,"+deps.LinkerScript.String())
linkerDeps = append(linkerDeps, deps.LinkerScript.Path())
diff --git a/cc/library.go b/cc/library.go
index 5da36dc6..147dd8e0 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -44,8 +44,6 @@ type LibraryProperties struct {
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"`
// local file name to pass to the linker as -unexported_symbols_list
Unexported_symbols_list *string `android:"arch_variant"`
// 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_proto_headers *bool
}
- Target struct {
- Vendor struct {
- // version script for this vendor variant
- Version_script *string `android:"arch_variant"`
- }
- }
Static_ndk_lib *bool
}
@@ -231,8 +223,6 @@ type libraryDecorator struct {
// shlib suffix.
libName string
- sanitize *sanitize
-
sabi *sabi
// Output archive of gcno coverage information files
@@ -432,7 +422,7 @@ func (library *libraryDecorator) getLibName(ctx ModuleContext) string {
func (library *libraryDecorator) linkerInit(ctx BaseModuleContext) {
location := InstallInSystem
- if library.sanitize.inSanitizerDir() {
+ if library.baseLinker.sanitize.inSanitizerDir() {
location = InstallInSanitizerDir
}
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)
}
- android.ExtractSourceDeps(ctx, library.Properties.Version_script)
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_weak_list)
- android.ExtractSourceDeps(ctx, library.Properties.Target.Vendor.Version_script)
return deps
}
@@ -526,23 +514,10 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext,
var linkerDeps android.Paths
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")
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")
- 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 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() {
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")
}
} else {
- if versionScript.Valid() {
- ctx.PropertyErrorf("version_script", "Not supported on Darwin")
- }
if unexportedSymbols.Valid() {
flags.LdFlags = append(flags.LdFlags, "-Wl,-unexported_symbols_list,"+unexportedSymbols.String())
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() &&
!ctx.useVndk() && !ctx.inRecovery() && ctx.Device() &&
- library.sanitize.isUnsanitizedVariant() {
+ library.baseLinker.sanitize.isUnsanitizedVariant() {
installPath := getNdkSysrootBase(ctx).Join(
ctx, "usr/lib", config.NDKTriple(ctx.toolchain()), file.Base())
@@ -827,9 +799,8 @@ func NewLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator)
BuildStatic: true,
},
baseCompiler: NewBaseCompiler(),
- baseLinker: NewBaseLinker(),
+ baseLinker: NewBaseLinker(module.sanitize),
baseInstaller: NewBaseInstaller("lib", "lib64", InstallInSystem),
- sanitize: module.sanitize,
sabi: module.sabi,
}
diff --git a/cc/linker.go b/cc/linker.go
index 6bbf0154..29720068 100644
--- a/cc/linker.go
+++ b/cc/linker.go
@@ -127,10 +127,20 @@ type BaseLinkerProperties struct {
type MoreBaseLinkerProperties struct {
// Generate compact dynamic relocation table, default true.
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 {
- return &baseLinker{}
+func NewBaseLinker(sanitize *sanitize) *baseLinker {
+ return &baseLinker{sanitize: sanitize}
}
// baseLinker provides support for shared_libs, static_libs, and whole_static_libs properties
@@ -140,6 +150,8 @@ type baseLinker struct {
dynamicProperties struct {
RunPaths []string `blueprint:"mutated"`
}
+
+ sanitize *sanitize
}
func (linker *baseLinker) appendLdflags(flags []string) {
@@ -158,7 +170,7 @@ func (linker *baseLinker) linkerProps() []interface{} {
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.HeaderLibs = append(deps.HeaderLibs, linker.Properties.Header_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")
}
+ android.ExtractSourceDeps(ctx, linker.MoreProperties.Version_script)
+ android.ExtractSourceDeps(ctx,
+ linker.MoreProperties.Target.Vendor.Version_script)
+
return deps
}
@@ -345,6 +361,32 @@ func (linker *baseLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
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
}
diff --git a/cc/ndk_prebuilt.go b/cc/ndk_prebuilt.go
index 4c633c24..258d6bd9 100644
--- a/cc/ndk_prebuilt.go
+++ b/cc/ndk_prebuilt.go
@@ -68,7 +68,7 @@ func ndkPrebuiltObjectFactory() android.Module {
module := newBaseModule(android.DeviceSupported, android.MultilibBoth)
module.linker = &ndkPrebuiltObjectLinker{
objectLinker: objectLinker{
- baseLinker: NewBaseLinker(),
+ baseLinker: NewBaseLinker(nil),
},
}
module.Properties.HideFromMake = true
diff --git a/cc/object.go b/cc/object.go
index d0f4f207..b5fd835e 100644
--- a/cc/object.go
+++ b/cc/object.go
@@ -36,7 +36,7 @@ type objectLinker struct {
func objectFactory() android.Module {
module := newBaseModule(android.HostAndDeviceSupported, android.MultilibBoth)
module.linker = &objectLinker{
- baseLinker: NewBaseLinker(),
+ baseLinker: NewBaseLinker(nil),
}
module.compiler = NewBaseCompiler()
return module.Init()