Preserve <uses-library> order in dexpreopt.config files.
Library order is important because it is used to construct class loader context, which is then written into OAT/ODEX files and chacked against class loader context constructed by PackageManager on the device. If the orders are different, dexpreopted code is rejected. Soong avoids using Go maps for class loader context representation precisely for that reason. However, for the modules defined in makefiles dexpreopt configs were serialized to JSON and unmarshaled to Go maps, which resulted in wrong order of libraries. This CL changes Go representation of class loader contexts imported from JSON and makes the order stable. Bug: 132357300 Test: lunch cf_x86_64_phone-userdebug && m && launch_cvd \ adb wait-for-device && adb root && adb logcat \ | grep -E 'ClassLoaderContext [a-z ]+ mismatch' # empty grep output, no errors Change-Id: I15f51617f9573c0bbcb324cf2592daf719cad586
This commit is contained in:
parent
56ca4e4706
commit
65556a87d3
|
@ -489,20 +489,16 @@ func computeClassLoaderContextRec(clcs []*ClassLoaderContext) (string, string, a
|
|||
}
|
||||
|
||||
// Class loader contexts that come from Make via JSON dexpreopt.config. JSON CLC representation is
|
||||
// slightly different: it uses a map of library names to their CLC (instead of a list of structs
|
||||
// that including the name, as in the Soong CLC representation). The difference is insubstantial, it
|
||||
// is caused only by the language differerences between Go and JSON.
|
||||
// the same as Soong representation except that SDK versions and paths are represented with strings.
|
||||
type jsonClassLoaderContext struct {
|
||||
Name string
|
||||
Host string
|
||||
Device string
|
||||
Subcontexts map[string]*jsonClassLoaderContext
|
||||
Subcontexts []*jsonClassLoaderContext
|
||||
}
|
||||
|
||||
// A map of <uses-library> name to its on-host and on-device build paths and CLC.
|
||||
type jsonClassLoaderContexts map[string]*jsonClassLoaderContext
|
||||
|
||||
// A map from SDK version (represented with a JSON string) to JSON CLCs.
|
||||
type jsonClassLoaderContextMap map[string]map[string]*jsonClassLoaderContext
|
||||
type jsonClassLoaderContextMap map[string][]*jsonClassLoaderContext
|
||||
|
||||
// Convert JSON CLC map to Soong represenation.
|
||||
func fromJsonClassLoaderContext(ctx android.PathContext, jClcMap jsonClassLoaderContextMap) ClassLoaderContextMap {
|
||||
|
@ -522,11 +518,11 @@ func fromJsonClassLoaderContext(ctx android.PathContext, jClcMap jsonClassLoader
|
|||
}
|
||||
|
||||
// Recursive helper for fromJsonClassLoaderContext.
|
||||
func fromJsonClassLoaderContextRec(ctx android.PathContext, jClcs map[string]*jsonClassLoaderContext) []*ClassLoaderContext {
|
||||
func fromJsonClassLoaderContextRec(ctx android.PathContext, jClcs []*jsonClassLoaderContext) []*ClassLoaderContext {
|
||||
clcs := make([]*ClassLoaderContext, 0, len(jClcs))
|
||||
for lib, clc := range jClcs {
|
||||
for _, clc := range jClcs {
|
||||
clcs = append(clcs, &ClassLoaderContext{
|
||||
Name: lib,
|
||||
Name: clc.Name,
|
||||
Host: constructPath(ctx, clc.Host),
|
||||
Device: clc.Device,
|
||||
Subcontexts: fromJsonClassLoaderContextRec(ctx, clc.Subcontexts),
|
||||
|
@ -546,14 +542,15 @@ func toJsonClassLoaderContext(clcMap ClassLoaderContextMap) jsonClassLoaderConte
|
|||
}
|
||||
|
||||
// Recursive helper for toJsonClassLoaderContext.
|
||||
func toJsonClassLoaderContextRec(clcs []*ClassLoaderContext) map[string]*jsonClassLoaderContext {
|
||||
jClcs := make(map[string]*jsonClassLoaderContext, len(clcs))
|
||||
func toJsonClassLoaderContextRec(clcs []*ClassLoaderContext) []*jsonClassLoaderContext {
|
||||
jClcs := make([]*jsonClassLoaderContext, len(clcs))
|
||||
for _, clc := range clcs {
|
||||
jClcs[clc.Name] = &jsonClassLoaderContext{
|
||||
jClcs = append(jClcs, &jsonClassLoaderContext{
|
||||
Name: clc.Name,
|
||||
Host: clc.Host.String(),
|
||||
Device: clc.Device,
|
||||
Subcontexts: toJsonClassLoaderContextRec(clc.Subcontexts),
|
||||
}
|
||||
})
|
||||
}
|
||||
return jClcs
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue