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 
17 #include <dlfcn.h>
18 #include <errno.h>
19 #include <stdio.h>
20 #if __has_include(<sys/auxv.h>)
21 #include <sys/auxv.h>
22 #endif
23 #include <unistd.h>
24 
25 extern "C" void foo();
26 void lib1_call_funcs();
27 __attribute__((weak)) void lib3_call_funcs();
28 
main()29 int main() {
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 
50   foo();
51   lib1_call_funcs();
52   if (lib3_call_funcs) lib3_call_funcs();
53 
54   return 0;
55 }
56