blob: 12491218098ec05ec671762a94dd5a50f8059101 [file] [log] [blame]
Jiyong Park02586a22017-05-20 01:01:24 +09001/*
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
dimitry69c68c42018-05-09 15:22:38 +020017#include <dlfcn.h>
Jiyong Park02586a22017-05-20 01:01:24 +090018#include <errno.h>
19#include <stdio.h>
dimitry69c68c42018-05-09 15:22:38 +020020#if __has_include(<sys/auxv.h>)
21#include <sys/auxv.h>
22#endif
Jiyong Park02586a22017-05-20 01:01:24 +090023#include <unistd.h>
24
Ryan Prichard058eb8f2020-12-17 22:59:04 -080025extern "C" void foo();
26void lib1_call_funcs();
27__attribute__((weak)) void lib3_call_funcs();
Jiyong Park02586a22017-05-20 01:01:24 +090028
29int main() {
dimitry69c68c42018-05-09 15:22:38 +020030 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 Prichard058eb8f2020-12-17 22:59:04 -080050 foo();
51 lib1_call_funcs();
52 if (lib3_call_funcs) lib3_call_funcs();
53
Jiyong Park02586a22017-05-20 01:01:24 +090054 return 0;
55}