1 | /* |
---|
2 | * Copyright (c) 2016 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 | #ifdef HAVE_CONFIG_H |
---|
10 | #include "config.h" |
---|
11 | #endif |
---|
12 | |
---|
13 | #include "tmacros.h" |
---|
14 | |
---|
15 | #include <stdio.h> |
---|
16 | |
---|
17 | #include <dlfcn.h> |
---|
18 | |
---|
19 | #include <rtems/rtl/rtl-trace.h> |
---|
20 | |
---|
21 | #include "dl-load.h" |
---|
22 | |
---|
23 | #define TEST_TRACE 0 |
---|
24 | #if TEST_TRACE |
---|
25 | #define DEBUG_TRACE (RTEMS_RTL_TRACE_DETAIL | \ |
---|
26 | RTEMS_RTL_TRACE_WARNING | \ |
---|
27 | RTEMS_RTL_TRACE_LOAD | \ |
---|
28 | RTEMS_RTL_TRACE_UNLOAD | \ |
---|
29 | RTEMS_RTL_TRACE_SYMBOL | \ |
---|
30 | RTEMS_RTL_TRACE_RELOC | \ |
---|
31 | RTEMS_RTL_TRACE_ALLOCATOR | \ |
---|
32 | RTEMS_RTL_TRACE_UNRESOLVED | \ |
---|
33 | RTEMS_RTL_TRACE_ARCHIVES | \ |
---|
34 | RTEMS_RTL_TRACE_GLOBAL_SYM | \ |
---|
35 | RTEMS_RTL_TRACE_DEPENDENCY) |
---|
36 | #define DL_DEBUG_TRACE DEBUG_TRACE /* RTEMS_RTL_TRACE_ALL */ |
---|
37 | #else |
---|
38 | #define DL_DEBUG_TRACE 0 |
---|
39 | #endif |
---|
40 | |
---|
41 | int dl_load_test(void) |
---|
42 | { |
---|
43 | void* handle; |
---|
44 | const char* err; |
---|
45 | void (*func)(bool ); |
---|
46 | #if __i386__ |
---|
47 | /* |
---|
48 | * std::runtime_error destructor locks up in atomics. |
---|
49 | */ |
---|
50 | bool throw_runtime = false; |
---|
51 | #else |
---|
52 | bool throw_runtime = true; |
---|
53 | #endif |
---|
54 | |
---|
55 | #if DL_DEBUG_TRACE |
---|
56 | rtems_rtl_trace_set_mask (DL_DEBUG_TRACE); |
---|
57 | #endif |
---|
58 | |
---|
59 | handle = dlopen("/dl05-o5.o", RTLD_GLOBAL | RTLD_NOW); |
---|
60 | if (handle == NULL) |
---|
61 | { |
---|
62 | err = dlerror(); |
---|
63 | if (err != NULL) |
---|
64 | printf("dlopen: %s\n", err); |
---|
65 | } |
---|
66 | rtems_test_assert(handle != NULL); |
---|
67 | |
---|
68 | func = dlsym(handle, "exception_dl"); |
---|
69 | if (func == NULL) { |
---|
70 | err = dlerror (); |
---|
71 | if (err) |
---|
72 | printf ("dlsym: %s\n", err); |
---|
73 | } |
---|
74 | rtems_test_assert(func != NULL); |
---|
75 | |
---|
76 | exception_base(throw_runtime); |
---|
77 | |
---|
78 | func(throw_runtime); |
---|
79 | |
---|
80 | rtems_test_assert(dlclose(handle) == 0); |
---|
81 | |
---|
82 | return 0; |
---|
83 | } |
---|