-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetsections_dl.c
More file actions
70 lines (58 loc) · 1.44 KB
/
Copy pathgetsections_dl.c
File metadata and controls
70 lines (58 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <dlfcn.h>
#define RDTSC(var) \
{ \
unsigned long var##_lo, var##_hi; \
asm volatile("lfence\n\trdtsc" : "=a"(var##_lo), "=d"(var##_hi)); \
var = var##_hi; \
var <<= 32; \
var |= var##_lo; \
}
extern int get_objsect (const char* infile);
int (*get_objsect_ptr) (const char* infile);
int main (int argc, char *argv[])
{
int dl_mode = 0;
unsigned long long start, finish;
if(argc != 3)
{
printf("usage: %s <filename> (RTLD_LAZY | RTLD_NOW)\n", argv[0]);
return -1;
}
if(strcmp(argv[2], "RTLD_LAZY") == 0)
dl_mode = RTLD_LAZY;
else if (strcmp(argv[2], "RTLD_NOW") == 0)
dl_mode = RTLD_NOW;
else
{
printf("usage: %s <filename> (RTLD_LAZY | RTLD_NOW)\n", argv[0]);
return -1;
}
void* lib_handle;
RDTSC(start);
lib_handle = dlopen("libobjdata.so", dl_mode | RTLD_GLOBAL);
RDTSC(finish);
if(!lib_handle)
{
printf("dlopen error - %s\n", dlerror());
return -1;
}
const char* err_msg;
get_objsect_ptr = dlsym(lib_handle, "get_objsect");
err_msg = dlerror();
if(err_msg)
{
printf("dlsym error - %s\n", err_msg);
return -1;
}
(*get_objsect_ptr) (argv[1]);
dlclose(lib_handle);
//cpu MHz : 2194.918
unsigned long long cpu_mhz = 2195;
unsigned long long dlopen_cycles = (finish - start);
printf("dlopen_usecs %llu\n", dlopen_cycles/cpu_mhz);
return 0;
}