1*e5eeaa8eSAndroid Build Coastguard Worker# LinkerConfig 2*e5eeaa8eSAndroid Build Coastguard Worker 3*e5eeaa8eSAndroid Build Coastguard Worker## Introduction 4*e5eeaa8eSAndroid Build Coastguard Worker 5*e5eeaa8eSAndroid Build Coastguard WorkerLinkerconfig is a program to generate linker configuration based on the runtime 6*e5eeaa8eSAndroid Build Coastguard Workerenvironment. Linkerconfig generates one or more ld.config.txt files and some 7*e5eeaa8eSAndroid Build Coastguard Workerother files under /linkerconfig during init. Linker will read this generated 8*e5eeaa8eSAndroid Build Coastguard Workerconfiguration file(s) to find out link relationship between libraries and 9*e5eeaa8eSAndroid Build Coastguard Workerexecutable. 10*e5eeaa8eSAndroid Build Coastguard Worker 11*e5eeaa8eSAndroid Build Coastguard Worker## Inputs 12*e5eeaa8eSAndroid Build Coastguard Worker 13*e5eeaa8eSAndroid Build Coastguard WorkerTODO: explain inputs (e.g. /system/etc/public.libraries.txt, 14*e5eeaa8eSAndroid Build Coastguard Worker/apex/apex-info-list.xml, ..) 15*e5eeaa8eSAndroid Build Coastguard Worker 16*e5eeaa8eSAndroid Build Coastguard Worker### linker.config.json 17*e5eeaa8eSAndroid Build Coastguard Worker 18*e5eeaa8eSAndroid Build Coastguard WorkerLinker configuration file can be used to add extra information while linkerconfig 19*e5eeaa8eSAndroid Build Coastguard Workercreates linker configuration with the module. This module can be defined as 20*e5eeaa8eSAndroid Build Coastguard Worker`linker_config` from Soong, and it will be translated as protobuf file at build 21*e5eeaa8eSAndroid Build Coastguard Workertime. 22*e5eeaa8eSAndroid Build Coastguard Worker 23*e5eeaa8eSAndroid Build Coastguard WorkerA linker configuration file(linker.config.json) is compiled into a protobuf at build time 24*e5eeaa8eSAndroid Build Coastguard Workerby `conv_linker_config`. You can find the compiled file under `<base>/etc/linker.config.pb`. 25*e5eeaa8eSAndroid Build Coastguard WorkerFor example, `/apex/com.android.art/etc/linker.config.pb` is a configuration for the `com.android.art` 26*e5eeaa8eSAndroid Build Coastguard WorkerAPEX. 27*e5eeaa8eSAndroid Build Coastguard Worker 28*e5eeaa8eSAndroid Build Coastguard Worker`/system/etc/linker.config.pb`(or its source module `system_linker_config`) is special because 29*e5eeaa8eSAndroid Build Coastguard Workerits `provideLibs` key is generated at build time. 30*e5eeaa8eSAndroid Build Coastguard Worker 31*e5eeaa8eSAndroid Build Coastguard Worker#### Format 32*e5eeaa8eSAndroid Build Coastguard Worker 33*e5eeaa8eSAndroid Build Coastguard Workerlinker.config.json file is in json format which can contain properties as below. 34*e5eeaa8eSAndroid Build Coastguard Worker 35*e5eeaa8eSAndroid Build Coastguard Worker| Property Name | Type | Description | Allowed module | 36*e5eeaa8eSAndroid Build Coastguard Worker| ------------- | ---- | ---------------------------------------------------- | -------------- | 37*e5eeaa8eSAndroid Build Coastguard Worker| permittedPaths| List<string> | Additional permitted paths | APEX | 38*e5eeaa8eSAndroid Build Coastguard Worker| visible | bool | Force APEX namespace to be visible from all sections if the value is true | APEX | 39*e5eeaa8eSAndroid Build Coastguard Worker| provideLibs | List<string> | Libraries providing from the module | System | 40*e5eeaa8eSAndroid Build Coastguard Worker| requireLibs | List<string> | Libraries required from the module | System | 41*e5eeaa8eSAndroid Build Coastguard Worker 42*e5eeaa8eSAndroid Build Coastguard Worker#### Example 43*e5eeaa8eSAndroid Build Coastguard Worker 44*e5eeaa8eSAndroid Build Coastguard Worker##### APEX module 45*e5eeaa8eSAndroid Build Coastguard Worker``` 46*e5eeaa8eSAndroid Build Coastguard Worker{ 47*e5eeaa8eSAndroid Build Coastguard Worker "permittedPaths" : [ "/a", "/b/c", "/d/e/f"], 48*e5eeaa8eSAndroid Build Coastguard Worker "visible": true 49*e5eeaa8eSAndroid Build Coastguard Worker} 50*e5eeaa8eSAndroid Build Coastguard Worker``` 51*e5eeaa8eSAndroid Build Coastguard Worker 52*e5eeaa8eSAndroid Build Coastguard Worker##### System 53*e5eeaa8eSAndroid Build Coastguard Worker``` 54*e5eeaa8eSAndroid Build Coastguard Worker{ 55*e5eeaa8eSAndroid Build Coastguard Worker "provideLibs" : [ "a.so", "b.so", "c.so" ], 56*e5eeaa8eSAndroid Build Coastguard Worker "requireLibs" : [ "foo.so", "bar.so", "baz.so" ] 57*e5eeaa8eSAndroid Build Coastguard Worker} 58*e5eeaa8eSAndroid Build Coastguard Worker``` 59*e5eeaa8eSAndroid Build Coastguard Worker 60*e5eeaa8eSAndroid Build Coastguard Worker### public.libraries.txt 61*e5eeaa8eSAndroid Build Coastguard Worker 62*e5eeaa8eSAndroid Build Coastguard Worker`linkerconfig` reads both `/system/etc/public.libraries.txt` and `/vendor/etc/public.libraries.txt` to identify 63*e5eeaa8eSAndroid Build Coastguard Workerlibraries that are provided by APEX and accessible from apps via `libnativeloader`. 64*e5eeaa8eSAndroid Build Coastguard Worker 65*e5eeaa8eSAndroid Build Coastguard Worker`linkerconfig` generates `apex.libraries.config.txt` file which lists public libraries provided APEX. `libnativeloader`, then, 66*e5eeaa8eSAndroid Build Coastguard Workerlinks those libraries from classloader-namespace to providing APEXes. 67*e5eeaa8eSAndroid Build Coastguard Worker 68*e5eeaa8eSAndroid Build Coastguard Worker## Outputs 69*e5eeaa8eSAndroid Build Coastguard Worker 70*e5eeaa8eSAndroid Build Coastguard Worker### /linkerconfig/ld.config.txt & /linkerconfig/*/ld.config.txt 71*e5eeaa8eSAndroid Build Coastguard Worker 72*e5eeaa8eSAndroid Build Coastguard WorkerTODO: a few words about the files 73*e5eeaa8eSAndroid Build Coastguard Worker 74*e5eeaa8eSAndroid Build Coastguard WorkerCheck 75*e5eeaa8eSAndroid Build Coastguard Worker[ld.config.format.md](https://android.googlesource.com/platform/bionic/+/master/linker/ld.config.format.md). 76*e5eeaa8eSAndroid Build Coastguard Worker 77*e5eeaa8eSAndroid Build Coastguard Worker### /linkerconfig/apex.libraries.txt 78*e5eeaa8eSAndroid Build Coastguard Worker 79*e5eeaa8eSAndroid Build Coastguard WorkerThe file describes libraries exposed from APEXes. libnativeloader is the main 80*e5eeaa8eSAndroid Build Coastguard Workerconsumer of this file. 81*e5eeaa8eSAndroid Build Coastguard Worker 82*e5eeaa8eSAndroid Build Coastguard Worker``` 83*e5eeaa8eSAndroid Build Coastguard Worker# comment line 84*e5eeaa8eSAndroid Build Coastguard Workerjni com_android_foo libfoo_jni.so 85*e5eeaa8eSAndroid Build Coastguard Workerpublic com_android_bar libbar.so:libbaz.so 86*e5eeaa8eSAndroid Build Coastguard Worker``` 87*e5eeaa8eSAndroid Build Coastguard Worker 88*e5eeaa8eSAndroid Build Coastguard WorkerThe file is line-based and each line consists of `tag apex_namespace 89*e5eeaa8eSAndroid Build Coastguard Workerlibrary_list`. 90*e5eeaa8eSAndroid Build Coastguard Worker 91*e5eeaa8eSAndroid Build Coastguard Worker- `tag` explains what `library_list` is. 92*e5eeaa8eSAndroid Build Coastguard Worker- `apex_namespace` is the namespace of the apex. Note that it is mangled like 93*e5eeaa8eSAndroid Build Coastguard Worker `com_android_foo` for the APEX("com.android.foo"). 94*e5eeaa8eSAndroid Build Coastguard Worker- `library_list` is colon-separated list of library names. 95*e5eeaa8eSAndroid Build Coastguard Worker - if `tag` is `jni`, `library_list` is the list of JNI libraries exposed 96*e5eeaa8eSAndroid Build Coastguard Worker by `apex_namespace`. 97*e5eeaa8eSAndroid Build Coastguard Worker - if `tag` is `public`, `library_list` is the list of public libraries 98*e5eeaa8eSAndroid Build Coastguard Worker exposed by `apex_namespace`. Here, public libraries are the libs listed 99*e5eeaa8eSAndroid Build Coastguard Worker in `/system/etc/public.libraries.txt.`