fix handling of SP Hal libs in virtual odm partion

LinkerConfig checks for SP Hal libs in sphal namespace search
and permitted path locations. This works fine for cases until the
SP Hal lib is located in a virutal ODM partition (/vendor/odm/lib{64})
In this case the paths /odm/lib* are softlinks into /vendor dir. The
softlinks (/odm/lib*) are processed with libc realpath(), which gives
back canonicalized abs path, which here becomes /vendor/odm/lib*, and
are currently not part of the LinkerConfig's SP Hal namespace's
permitted paths list. Resulting in failure to load SP Hal libs from
virtual ODM partitions.

This diff provides a fix for above situation, and adds /vendor/odm/lib{64}
to sphal permitted paths list, to handle above mentioned cases properly.

Test: backward_compatibility CTS test and golden_output data are updated
      using rundiff.sh. Following 5 CTS tests fully pass:
        atest linkerconfig_modules_unittest
        atest linkerconfig_backward_compatibility_test
        atest linkerconfig_generator_unittest
        atest linkerconfig_contents_fulltest
        atest linkerconfig_diff_test

Change-Id: I5022bbdc2664f93e04568d17e0549aaf82c251cc
43 files changed
tree: 42aeabca600de4f326f48435fc4999076e58fcd4
  1. contents/
  2. generator/
  3. modules/
  4. testdata/
  5. testmodules/
  6. .clang-format
  7. .gitignore
  8. Android.bp
  9. linkerconfig_diff_test.xml
  10. main.cc
  11. OWNERS
  12. PREUPLOAD.cfg
  13. README.md
  14. rundiff.sh
  15. TEST_MAPPING
README.md

LinkerConfig

Introduction

Linkerconfig is a program to generate linker configuration based on the runtime environment. Linkerconfig generates one or more ld.config.txt files and some other files under /linkerconfig during init. Linker will read this generated configuration file(s) to find out link relationship between libraries and executable.

Inputs

TODO: explain inputs (e.g. /system/etc/public.libraries.txt, /apex/apex-info-list.xml, ..)

linker.config.json

Linker configuration file can be used to add extra information while linkerconfig creates linker configuration with the module. This module can be defined as linker_config from Soong, and it will be translated as protobuf file at build time.

A linker configuration file(linker.config.json) is compiled into a protobuf at build time by conv_linker_config. You can find the compiled file under <base>/etc/linker.config.pb. For example, /apex/com.android.art/etc/linker.config.pb is a configuration for the com.android.art APEX.

/system/etc/linker.config.pb(or its source module system_linker_config) is special because its provideLibs key is generated at build time.

Format

linker.config.json file is in json format which can contain properties as below.

Property NameTypeDescriptionAllowed module
permittedPathsListAdditional permitted pathsAPEX
visibleboolForce APEX namespace to be visible from all sections if the value is trueAPEX
provideLibsListLibraries providing from the moduleSystem
requireLibsListLibraries required from the moduleSystem

Example

APEX module
{
    "permittedPaths" : [ "/a", "/b/c", "/d/e/f"],
    "visible": true
}
System
{
    "provideLibs" : [ "a.so", "b.so", "c.so" ],
    "requireLibs" : [ "foo.so", "bar.so", "baz.so" ]
}

Outputs

/linkerconfig/ld.config.txt & /linkerconfig/*/ld.config.txt

TODO: a few words about the files

Check ld.config.format.md.

/linkerconfig/apex.libraries.txt

The file describes libraries exposed from APEXes. libnativeloader is the main consumer of this file.

# comment line
jni com_android_foo libfoo_jni.so
public com_android_bar libbar.so:libbaz.so

The file is line-based and each line consists of tag apex_namespace library_list.

  • tag explains what library_list is.
  • apex_namespace is the namespace of the apex. Note that it is mangled like com_android_foo for the APEX(“com.android.foo”).
  • library_list is colon-separated list of library names.
    • if tag is jni, library_list is the list of JNI libraries exposed by apex_namespace.
    • if tag is public, library_list is the list of public libraries exposed by apex_namespace. Here, public libraries are the libs listed in /system/etc/public.libraries.txt.