David Srbecky | 7711c35 | 2019-04-10 17:50:12 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <android-base/logging.h> |
| 18 | |
| 19 | #if !defined(_WIN32) |
| 20 | #include <dlfcn.h> |
| 21 | #endif |
| 22 | |
| 23 | #include "globals.h" |
| 24 | |
| 25 | namespace art { |
| 26 | |
| 27 | #if !defined(_WIN32) |
| 28 | // Check that we have not loaded both debug and release version of libartbase at the same time. |
Martin Stjernholm | 356864a | 2019-04-30 16:22:17 +0100 | [diff] [blame^] | 29 | // |
| 30 | // This can be a cascade problem originating from a call to |
| 31 | // LoadLibdexfileExternal in libdexfile_support: If it was called before any ART |
| 32 | // libraries were loaded it will default to the non-debug version, which can |
| 33 | // then clash with a later load of the debug version. |
David Srbecky | 7711c35 | 2019-04-10 17:50:12 +0100 | [diff] [blame] | 34 | static struct CheckLoadedBuild { |
| 35 | CheckLoadedBuild() { |
| 36 | bool debug_build_loaded = (dlopen("libartbased.so", RTLD_NOW | RTLD_NOLOAD) != nullptr); |
| 37 | bool release_build_loaded = (dlopen("libartbase.so", RTLD_NOW | RTLD_NOLOAD) != nullptr); |
| 38 | // TODO: The exit calls below are needed as CHECK would cause recursive backtracing. Fix it. |
| 39 | if (!debug_build_loaded && !release_build_loaded) { |
| 40 | LOG(FATAL_WITHOUT_ABORT) << "Failed to dlopen libartbase.so or libartbased.so"; |
| 41 | exit(1); |
| 42 | } |
| 43 | if (kIsDebugBuild && release_build_loaded) { |
| 44 | LOG(FATAL_WITHOUT_ABORT) << "Loading libartbased.so while libartbase.so is already loaded"; |
| 45 | exit(1); |
| 46 | } |
| 47 | if (!kIsDebugBuild && debug_build_loaded) { |
| 48 | LOG(FATAL_WITHOUT_ABORT) << "Loading libartbase.so while libartbased.so is already loaded"; |
| 49 | exit(1); |
| 50 | } |
| 51 | } |
| 52 | } g_check_loaded_build; |
| 53 | #endif |
| 54 | |
| 55 | } // namespace art |