Reuse more of apex stubs implementation for llndk stubs

Use the linker script and exported flags support from apex stubs
for llndk stubs.

Test: no change to build.ninja or Android-${TARGET_PRODUCT}.mk
Change-Id: I9886498dcac7419958d290de99cf5f39f5fdedee
This commit is contained in:
Colin Cross
2020-09-28 18:28:02 -07:00
parent c88c272298
commit 8e21aa54eb
2 changed files with 8 additions and 21 deletions

View File

@@ -346,7 +346,7 @@ type libraryDecorator struct {
// Location of the file that should be copied to dist dir when requested // Location of the file that should be copied to dist dir when requested
distFile android.Path distFile android.Path
versionScriptPath android.ModuleGenPath versionScriptPath android.OptionalPath
post_install_cmds []string post_install_cmds []string
@@ -608,7 +608,7 @@ func (library *libraryDecorator) shouldCreateSourceAbiDump(ctx ModuleContext) bo
func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects { func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects {
if library.buildStubs() { if library.buildStubs() {
objs, versionScript := compileStubLibrary(ctx, flags, String(library.Properties.Stubs.Symbol_file), library.MutatedProperties.StubsVersion, "--apex") objs, versionScript := compileStubLibrary(ctx, flags, String(library.Properties.Stubs.Symbol_file), library.MutatedProperties.StubsVersion, "--apex")
library.versionScriptPath = versionScript library.versionScriptPath = android.OptionalPathForPath(versionScript)
return objs return objs
} }
@@ -928,10 +928,10 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext,
linkerDeps = append(linkerDeps, forceWeakSymbols.Path()) linkerDeps = append(linkerDeps, forceWeakSymbols.Path())
} }
} }
if library.buildStubs() { if library.versionScriptPath.Valid() {
linkerScriptFlags := "-Wl,--version-script," + library.versionScriptPath.String() linkerScriptFlags := "-Wl,--version-script," + library.versionScriptPath.String()
flags.Local.LdFlags = append(flags.Local.LdFlags, linkerScriptFlags) flags.Local.LdFlags = append(flags.Local.LdFlags, linkerScriptFlags)
linkerDeps = append(linkerDeps, library.versionScriptPath) linkerDeps = append(linkerDeps, library.versionScriptPath.Path())
} }
fileName := library.getLibName(ctx) + flags.Toolchain.ShlibSuffix() fileName := library.getLibName(ctx) + flags.Toolchain.ShlibSuffix()
@@ -1198,7 +1198,7 @@ func (library *libraryDecorator) link(ctx ModuleContext,
} }
if library.buildStubs() { if library.buildStubs() {
library.reexportFlags("-D" + versioningMacroName(ctx.ModuleName()) + "=" + library.stubsVersion()) library.reexportFlags("-D" + versioningMacroName(ctx.baseModuleName()) + "=" + library.stubsVersion())
} }
library.flagExporter.setProvider(ctx) library.flagExporter.setProvider(ctx)

View File

@@ -68,9 +68,6 @@ type llndkStubDecorator struct {
Properties llndkLibraryProperties Properties llndkLibraryProperties
exportHeadersTimestamp android.OptionalPath
versionScriptPath android.ModuleGenPath
movedToApex bool movedToApex bool
} }
@@ -89,7 +86,9 @@ func (stub *llndkStubDecorator) compile(ctx ModuleContext, flags Flags, deps Pat
vndkVer = stub.stubsVersion() vndkVer = stub.stubsVersion()
} }
objs, versionScript := compileStubLibrary(ctx, flags, String(stub.Properties.Symbol_file), vndkVer, "--llndk") objs, versionScript := compileStubLibrary(ctx, flags, String(stub.Properties.Symbol_file), vndkVer, "--llndk")
stub.versionScriptPath = versionScript if !Bool(stub.Properties.Unversioned) {
stub.versionScriptPath = android.OptionalPathForPath(versionScript)
}
return objs return objs
} }
@@ -138,12 +137,6 @@ func (stub *llndkStubDecorator) link(ctx ModuleContext, flags Flags, deps PathDe
stub.movedToApex = implApexModule.DirectlyInAnyApex() stub.movedToApex = implApexModule.DirectlyInAnyApex()
} }
if !Bool(stub.Properties.Unversioned) {
linkerScriptFlag := "-Wl,--version-script," + stub.versionScriptPath.String()
flags.Local.LdFlags = append(flags.Local.LdFlags, linkerScriptFlag)
flags.LdFlagsDeps = append(flags.LdFlagsDeps, stub.versionScriptPath)
}
if len(stub.Properties.Export_preprocessed_headers) > 0 { if len(stub.Properties.Export_preprocessed_headers) > 0 {
genHeaderOutDir := android.PathForModuleGen(ctx, "include") genHeaderOutDir := android.PathForModuleGen(ctx, "include")
@@ -166,10 +159,6 @@ func (stub *llndkStubDecorator) link(ctx ModuleContext, flags Flags, deps PathDe
stub.libraryDecorator.flagExporter.Properties.Export_include_dirs = []string{} stub.libraryDecorator.flagExporter.Properties.Export_include_dirs = []string{}
} }
if stub.stubsVersion() != "" {
stub.reexportFlags("-D" + versioningMacroName(ctx.baseModuleName()) + "=" + stub.stubsVersion())
}
return stub.libraryDecorator.link(ctx, flags, deps, objs) return stub.libraryDecorator.link(ctx, flags, deps, objs)
} }
@@ -181,8 +170,6 @@ func (stub *llndkStubDecorator) buildStubs() bool {
return true return true
} }
func (stub *llndkStubDecorator) setBuildStubs() {}
func NewLLndkStubLibrary() *Module { func NewLLndkStubLibrary() *Module {
module, library := NewLibrary(android.DeviceSupported) module, library := NewLibrary(android.DeviceSupported)
library.BuildOnlyShared() library.BuildOnlyShared()