Victor Khimenko | d15229d | 2020-05-14 22:14:45 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 The Android Open Source Project |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in |
| 12 | * the documentation and/or other materials provided with the |
| 13 | * distribution. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 16 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 17 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 18 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 19 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 22 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 25 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 26 | * SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #include "linker.h" |
| 30 | #include "linker_translate_path.h" |
| 31 | #include "linker_utils.h" |
| 32 | |
| 33 | #if defined(__LP64__) |
| 34 | static const char* const kSystemLibDir = "/system/lib64"; |
| 35 | static const char* const kI18nApexLibDir = "/apex/com.android.i18n/lib64"; |
| 36 | #else |
| 37 | static const char* const kSystemLibDir = "/system/lib"; |
| 38 | static const char* const kI18nApexLibDir = "/apex/com.android.i18n/lib"; |
| 39 | #endif |
| 40 | |
| 41 | // Workaround for dlopen(/system/lib(64)/<soname>) when .so is in /apex. http://b/121248172 |
| 42 | /** |
| 43 | * Translate /system path to /apex path if needed |
| 44 | * The workaround should work only when targetSdkVersion < Q. |
| 45 | * |
| 46 | * param out_name_to_apex pointing to /apex path |
| 47 | * return true if translation is needed |
| 48 | */ |
| 49 | bool translateSystemPathToApexPath(const char* name, std::string* out_name_to_apex) { |
| 50 | static const char* const kSystemToArtApexLibs[] = { |
| 51 | "libicuuc.so", |
| 52 | "libicui18n.so", |
| 53 | }; |
| 54 | // New mapping for new apex should be added below |
| 55 | |
| 56 | // Nothing to do if target sdk version is Q or above |
| 57 | if (get_application_target_sdk_version() >= 29) { |
| 58 | return false; |
| 59 | } |
| 60 | |
| 61 | // If the path isn't /system/lib, there's nothing to do. |
| 62 | if (name == nullptr || dirname(name) != kSystemLibDir) { |
| 63 | return false; |
| 64 | } |
| 65 | |
| 66 | const char* base_name = basename(name); |
| 67 | |
| 68 | for (const char* soname : kSystemToArtApexLibs) { |
| 69 | if (strcmp(base_name, soname) == 0) { |
| 70 | *out_name_to_apex = std::string(kI18nApexLibDir) + "/" + base_name; |
| 71 | return true; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | return false; |
| 76 | } |
| 77 | // End Workaround for dlopen(/system/lib/<soname>) when .so is in /apex. |