Jiyong Park | 02586a2 | 2017-05-20 01:01:24 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | |
dimitry | 69c68c4 | 2018-05-09 15:22:38 +0200 | [diff] [blame] | 17 | #include <dlfcn.h> |
Jiyong Park | 02586a2 | 2017-05-20 01:01:24 +0900 | [diff] [blame] | 18 | #include <errno.h> |
| 19 | #include <stdio.h> |
dimitry | 69c68c4 | 2018-05-09 15:22:38 +0200 | [diff] [blame] | 20 | #if __has_include(<sys/auxv.h>) |
| 21 | #include <sys/auxv.h> |
| 22 | #endif |
Jiyong Park | 02586a2 | 2017-05-20 01:01:24 +0900 | [diff] [blame] | 23 | #include <unistd.h> |
| 24 | |
Ryan Prichard | 058eb8f | 2020-12-17 22:59:04 -0800 | [diff] [blame] | 25 | extern "C" void foo(); |
| 26 | void lib1_call_funcs(); |
| 27 | __attribute__((weak)) void lib3_call_funcs(); |
Jiyong Park | 02586a2 | 2017-05-20 01:01:24 +0900 | [diff] [blame] | 28 | |
| 29 | int main() { |
dimitry | 69c68c4 | 2018-05-09 15:22:38 +0200 | [diff] [blame] | 30 | bool skip_vdso_check = false; |
| 31 | #if __has_include(<sys/auxv.h>) |
| 32 | if (getauxval(AT_SYSINFO_EHDR) == 0) { |
| 33 | skip_vdso_check = true; |
| 34 | } |
| 35 | #endif |
| 36 | |
| 37 | if (!skip_vdso_check) { |
| 38 | const char* vdso_name = "linux-vdso.so.1"; |
| 39 | #if defined(__i386__) |
| 40 | vdso_name = "linux-gate.so.1"; |
| 41 | #endif |
| 42 | void* handle = dlopen(vdso_name, RTLD_NOW); |
| 43 | if (handle == nullptr) { |
| 44 | printf("%s", dlerror()); |
| 45 | return 1; |
| 46 | } |
| 47 | dlclose(handle); |
| 48 | } |
| 49 | |
Ryan Prichard | 058eb8f | 2020-12-17 22:59:04 -0800 | [diff] [blame] | 50 | foo(); |
| 51 | lib1_call_funcs(); |
| 52 | if (lib3_call_funcs) lib3_call_funcs(); |
| 53 | |
Jiyong Park | 02586a2 | 2017-05-20 01:01:24 +0900 | [diff] [blame] | 54 | return 0; |
| 55 | } |