blob: e6203a241972bc3617042f7dc000b69a175084a3 [file] [log] [blame]
David Srbecky7711c352019-04-10 17:50:12 +01001/*
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
25namespace art {
26
27#if !defined(_WIN32)
28// Check that we have not loaded both debug and release version of libartbase at the same time.
29static struct CheckLoadedBuild {
30 CheckLoadedBuild() {
31 bool debug_build_loaded = (dlopen("libartbased.so", RTLD_NOW | RTLD_NOLOAD) != nullptr);
32 bool release_build_loaded = (dlopen("libartbase.so", RTLD_NOW | RTLD_NOLOAD) != nullptr);
33 // TODO: The exit calls below are needed as CHECK would cause recursive backtracing. Fix it.
34 if (!debug_build_loaded && !release_build_loaded) {
35 LOG(FATAL_WITHOUT_ABORT) << "Failed to dlopen libartbase.so or libartbased.so";
36 exit(1);
37 }
38 if (kIsDebugBuild && release_build_loaded) {
39 LOG(FATAL_WITHOUT_ABORT) << "Loading libartbased.so while libartbase.so is already loaded";
40 exit(1);
41 }
42 if (!kIsDebugBuild && debug_build_loaded) {
43 LOG(FATAL_WITHOUT_ABORT) << "Loading libartbase.so while libartbased.so is already loaded";
44 exit(1);
45 }
46 }
47} g_check_loaded_build;
48#endif
49
50} // namespace art