1 | /* |
---|
2 | * Copyright (c) 2014 Chris Johns <chrisj@rtems.org>. All rights reserved. |
---|
3 | * |
---|
4 | * The license and distribution terms for this file may be |
---|
5 | * found in the file LICENSE in this distribution or at |
---|
6 | * http://www.rtems.org/license/LICENSE. |
---|
7 | */ |
---|
8 | |
---|
9 | #include <stdio.h> |
---|
10 | |
---|
11 | #include <dlfcn.h> |
---|
12 | |
---|
13 | #include <rtems/rtl/rtl-trace.h> |
---|
14 | |
---|
15 | #include "dl-load.h" |
---|
16 | |
---|
17 | typedef int (*call_t)(int argc, const char* argv[]); |
---|
18 | |
---|
19 | static const char* call_args[] = { "1", "2", "3", "4" }; |
---|
20 | |
---|
21 | static void* dl_load_obj(const char* name) |
---|
22 | { |
---|
23 | void* handle; |
---|
24 | int unresolved; |
---|
25 | char* message = "loaded"; |
---|
26 | |
---|
27 | #if DL06_DEBUG_TRACING |
---|
28 | rtems_rtl_trace_set_mask(RTEMS_RTL_TRACE_ALL); |
---|
29 | #endif |
---|
30 | |
---|
31 | printf("\nload: %s\n", name); |
---|
32 | |
---|
33 | handle = dlopen (name, RTLD_NOW | RTLD_GLOBAL); |
---|
34 | if (!handle) |
---|
35 | { |
---|
36 | printf("dlopen failed: %s\n", dlerror()); |
---|
37 | return NULL; |
---|
38 | } |
---|
39 | |
---|
40 | if (dlinfo (handle, RTLD_DI_UNRESOLVED, &unresolved) < 0) |
---|
41 | message = "dlinfo error checking unresolved status"; |
---|
42 | else if (unresolved) |
---|
43 | message = "has unresolved externals"; |
---|
44 | |
---|
45 | printf ("handle: %p %s\n", handle, message); |
---|
46 | |
---|
47 | return handle; |
---|
48 | } |
---|
49 | |
---|
50 | int dl_load_test(void) |
---|
51 | { |
---|
52 | void* r1; |
---|
53 | call_t call; |
---|
54 | int call_ret; |
---|
55 | int ret; |
---|
56 | |
---|
57 | r1 = dl_load_obj("/dl06.rap"); |
---|
58 | if (!r1) |
---|
59 | return 1; |
---|
60 | |
---|
61 | #if 0 |
---|
62 | { |
---|
63 | char* list[] = { "rtl", "list", NULL }; |
---|
64 | rtems_rtl_shell_command (2, list); |
---|
65 | char* sym[] = { "rtl", "sym", NULL }; |
---|
66 | rtems_rtl_shell_command (2, sym); |
---|
67 | } |
---|
68 | #endif |
---|
69 | |
---|
70 | call = dlsym (r1, "rtems_main"); |
---|
71 | if (call == NULL) |
---|
72 | { |
---|
73 | printf("dlsym failed: symbol not found\n"); |
---|
74 | return 1; |
---|
75 | } |
---|
76 | |
---|
77 | call_ret = call (4, call_args); |
---|
78 | if (call_ret != 4) |
---|
79 | { |
---|
80 | printf("dlsym call failed: ret value bad\n"); |
---|
81 | return 1; |
---|
82 | } |
---|
83 | |
---|
84 | ret = 0; |
---|
85 | |
---|
86 | if (dlclose (r1) < 0) |
---|
87 | { |
---|
88 | printf("dlclose o1 failed: %s\n", dlerror()); |
---|
89 | ret = 1; |
---|
90 | } |
---|
91 | |
---|
92 | printf ("handle: %p closed\n", r1); |
---|
93 | |
---|
94 | return ret; |
---|
95 | } |
---|