blob: 9a67dc49dd2a3f09d503d88cae0e6827b5dadde7 [file] [log] [blame]
Orion Hodsoncbe6d4a2019-05-09 10:29:52 +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#include <dlfcn.h>
20
21#include "globals.h"
22
23namespace art {
24
Martin Stjernholma28438a2020-09-23 01:40:03 +010025#ifndef ART_STATIC_LIBARTBASE
26
Orion Hodsoncbe6d4a2019-05-09 10:29:52 +010027#ifdef __APPLE__
28// dlopen(3) on Linux with just an SO name will search the already
29// opened libraries. On Darwin, we need dlopen(3) needs the SO name
30// qualified with it's path (if the SO is not on the search path). Use
31// linker path when compiling app. See man pages for dlopen(3) and
32// dlyd(1).
33 static constexpr const char kLibArtBaseDebug[] = "@rpath/libartbased.dylib";
34 static constexpr const char kLibArtBaseRelease[] = "@rpath/libartbase.dylib";
35#else
36 static constexpr const char kLibArtBaseDebug[] = "libartbased.so";
37 static constexpr const char kLibArtBaseRelease[] = "libartbase.so";
38#endif // __APPLE__
39
40// Check that we have not loaded both debug and release version of libartbase at the same time.
41//
42// This can be a cascade problem originating from a call to
43// LoadLibdexfileExternal in libdexfile_support: If it was called before any ART
44// libraries were loaded it will default to the non-debug version, which can
45// then clash with a later load of the debug version.
46static struct CheckLoadedBuild {
47 CheckLoadedBuild() {
48 bool debug_build_loaded = (dlopen(kLibArtBaseDebug, RTLD_NOW | RTLD_NOLOAD) != nullptr);
49 bool release_build_loaded = (dlopen(kLibArtBaseRelease, RTLD_NOW | RTLD_NOLOAD) != nullptr);
50 // TODO: The exit calls below are needed as CHECK would cause recursive backtracing. Fix it.
51 if (!(debug_build_loaded || release_build_loaded)) {
52 LOG(FATAL_WITHOUT_ABORT) << "Failed to dlopen "
53 << kLibArtBaseDebug
54 << " or "
55 << kLibArtBaseRelease;
56 exit(1);
57 }
58 if (kIsDebugBuild && release_build_loaded) {
59 LOG(FATAL_WITHOUT_ABORT) << "Loading "
60 << kLibArtBaseDebug
61 << " while "
62 << kLibArtBaseRelease
63 << " is already loaded";
64 exit(1);
65 }
66 if (!kIsDebugBuild && debug_build_loaded) {
67 LOG(FATAL_WITHOUT_ABORT) << "Loading "
68 << kLibArtBaseRelease
69 << " while "
70 << kLibArtBaseDebug
71 << " is already loaded";
72 exit(1);
73 }
74 }
75} g_check_loaded_build;
76
Martin Stjernholma28438a2020-09-23 01:40:03 +010077#endif // !ART_STATIC_LIBARTBASE
78
Orion Hodsoncbe6d4a2019-05-09 10:29:52 +010079} // namespace art