blob: 1ee401289fba8fd3fe28640ea3002d80a2ff7c03 [file] [log] [blame]
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -07001/*
2 * Copyright (C) 2007 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
Matt Fischere2a8b1f2009-12-31 12:17:40 -060017#include <dlfcn.h>
Elliott Hughes7ac97512014-01-14 17:25:13 -080018#include <link.h>
Elliott Hughesa4aafd12014-01-13 16:37:47 -080019#include <stdlib.h>
Torne (Richard Coles)012cb452014-02-06 14:34:21 +000020#include <android/dlext.h>
Elliott Hughesa4aafd12014-01-13 16:37:47 -080021
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080022// These functions are exported by the loader
23// TODO(dimitry): replace these with reference to libc.so
The Android Open Source Project4e468ed2008-12-17 18:03:48 -080024
Josh Gaodfcc6e42017-10-13 11:56:55 -070025extern "C" {
26
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080027__attribute__((__weak__, visibility("default")))
dimitryce584e42019-03-29 05:34:33 +010028void __loader_android_get_LD_LIBRARY_PATH(char* buffer, size_t buffer_size);
29
30__attribute__((__weak__, visibility("default")))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080031void* __loader_dlopen(const char* filename, int flags, const void* caller_addr);
Dimitry Ivanov9cf99cb2015-12-11 14:22:24 -080032
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080033__attribute__((__weak__, visibility("default")))
Josh Gaodfcc6e42017-10-13 11:56:55 -070034char* __loader_dlerror();
Dimitry Ivanov9cf99cb2015-12-11 14:22:24 -080035
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080036__attribute__((__weak__, visibility("default")))
37void* __loader_dlsym(void* handle, const char* symbol, const void* caller_addr);
Dimitry Ivanov9cf99cb2015-12-11 14:22:24 -080038
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080039__attribute__((__weak__, visibility("default")))
40void* __loader_dlvsym(void* handle,
41 const char* symbol,
42 const char* version,
43 const void* caller_addr);
Dimitry Ivanov9cf99cb2015-12-11 14:22:24 -080044
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080045__attribute__((__weak__, visibility("default")))
46int __loader_dladdr(const void* addr, Dl_info* info);
Dimitry Ivanov9cf99cb2015-12-11 14:22:24 -080047
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080048__attribute__((__weak__, visibility("default")))
49int __loader_dlclose(void* handle);
Elliott Hughes7ac97512014-01-14 17:25:13 -080050
Elliott Hughes22d62922012-10-12 10:50:21 -070051#if defined(__arm__)
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080052__attribute__((__weak__, visibility("default")))
53_Unwind_Ptr __loader_dl_unwind_find_exidx(_Unwind_Ptr pc, int* pcount);
Christopher Ferris24053a42013-08-19 17:45:09 -070054#endif
Elliott Hughes22d62922012-10-12 10:50:21 -070055
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080056__attribute__((__weak__, visibility("default")))
57int __loader_dl_iterate_phdr(int (*cb)(struct dl_phdr_info* info, size_t size, void* data),
58 void* data);
59
60__attribute__((__weak__, visibility("default")))
61void __loader_android_get_LD_LIBRARY_PATH(char* buffer, size_t buffer_size);
62
63__attribute__((__weak__, visibility("default")))
64void __loader_android_update_LD_LIBRARY_PATH(const char* ld_library_path);
65
66__attribute__((__weak__, visibility("default")))
67void* __loader_android_dlopen_ext(const char* filename,
68 int flag,
69 const android_dlextinfo* extinfo,
70 const void* caller_addr);
71
72__attribute__((__weak__, visibility("default")))
Elliott Hughesff1428a2018-11-12 16:01:37 -080073int __loader_android_get_application_target_sdk_version();
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080074
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080075// Proxy calls to bionic loader
dimitryc5ea3eb2017-10-05 17:23:10 +020076__attribute__((__weak__))
dimitryce584e42019-03-29 05:34:33 +010077void android_get_LD_LIBRARY_PATH(char* buffer, size_t buffer_size) {
78 __loader_android_get_LD_LIBRARY_PATH(buffer, buffer_size);
79}
80
81__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080082void* dlopen(const char* filename, int flag) {
83 const void* caller_addr = __builtin_return_address(0);
84 return __loader_dlopen(filename, flag, caller_addr);
Dmitriy Ivanov42d5fcb2015-10-29 17:01:24 -070085}
Torne (Richard Coles)012cb452014-02-06 14:34:21 +000086
dimitryc5ea3eb2017-10-05 17:23:10 +020087__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080088char* dlerror() {
89 return __loader_dlerror();
Dmitriy Ivanov42d5fcb2015-10-29 17:01:24 -070090}
Dmitriy Ivanov79fd6682015-05-21 17:43:49 -070091
dimitryc5ea3eb2017-10-05 17:23:10 +020092__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080093void* dlsym(void* handle, const char* symbol) {
94 const void* caller_addr = __builtin_return_address(0);
95 return __loader_dlsym(handle, symbol, caller_addr);
Dmitriy Ivanov1ffec1c2015-11-23 11:26:35 -080096}
97
dimitryc5ea3eb2017-10-05 17:23:10 +020098__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080099void* dlvsym(void* handle, const char* symbol, const char* version) {
100 const void* caller_addr = __builtin_return_address(0);
101 return __loader_dlvsym(handle, symbol, version, caller_addr);
102}
103
dimitryc5ea3eb2017-10-05 17:23:10 +0200104__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -0800105int dladdr(const void* addr, Dl_info* info) {
106 return __loader_dladdr(addr, info);
107}
108
dimitryc5ea3eb2017-10-05 17:23:10 +0200109__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -0800110int dlclose(void* handle) {
111 return __loader_dlclose(handle);
112}
113
114#if defined(__arm__)
dimitryc5ea3eb2017-10-05 17:23:10 +0200115__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -0800116_Unwind_Ptr dl_unwind_find_exidx(_Unwind_Ptr pc, int* pcount) {
117 return __loader_dl_unwind_find_exidx(pc, pcount);
118}
119#endif
120
Dan Albertdb98fed2017-04-25 15:42:42 -0700121/*
122 * This needs to be defined as weak because it is also defined in libc.a.
123 * Without this, static executables will have a multiple definition error.
124 */
125__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -0800126int dl_iterate_phdr(int (*cb)(struct dl_phdr_info* info, size_t size, void* data), void* data) {
127 return __loader_dl_iterate_phdr(cb, data);
128}
129
dimitryc5ea3eb2017-10-05 17:23:10 +0200130__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -0800131void* android_dlopen_ext(const char* filename, int flag, const android_dlextinfo* extinfo) {
132 const void* caller_addr = __builtin_return_address(0);
133 return __loader_android_dlopen_ext(filename, flag, extinfo, caller_addr);
134}
135
dimitryc5ea3eb2017-10-05 17:23:10 +0200136__attribute__((__weak__))
Elliott Hughesff1428a2018-11-12 16:01:37 -0800137int android_get_application_target_sdk_version() {
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -0800138 return __loader_android_get_application_target_sdk_version();
139}
140
Ryan Prichard470b6662018-03-27 22:10:55 -0700141#if defined(__arm__)
142// An arm32 unwinding table has an R_ARM_NONE relocation to
143// __aeabi_unwind_cpp_pr0. This shared library will never invoke the unwinder,
144// so it doesn't actually need the routine. Define a dummy version here,
145// because the real version calls libc functions (e.g. memcpy, abort), which
146// would create a dependency cycle with libc.so.
147__attribute__((visibility("hidden")))
148void __aeabi_unwind_cpp_pr0() {
149 __builtin_trap();
150}
151#endif
152
Josh Gaodfcc6e42017-10-13 11:56:55 -0700153} // extern "C"