File indexing completed on 2025-05-11 08:24:33
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #define TEST_TRACE 0
0030 #if TEST_TRACE
0031 #define DEBUG_TRACE (RTEMS_RTL_TRACE_DETAIL | \
0032 RTEMS_RTL_TRACE_WARNING | \
0033 RTEMS_RTL_TRACE_LOAD | \
0034 RTEMS_RTL_TRACE_UNLOAD | \
0035 RTEMS_RTL_TRACE_SYMBOL | \
0036 RTEMS_RTL_TRACE_RELOC | \
0037 RTEMS_RTL_TRACE_LOAD_SECT | \
0038 RTEMS_RTL_TRACE_ALLOCATOR | \
0039 RTEMS_RTL_TRACE_UNRESOLVED | \
0040 RTEMS_RTL_TRACE_ARCHIVES | \
0041 RTEMS_RTL_TRACE_DEPENDENCY)
0042
0043 #define DL_DEBUG_TRACE DEBUG_TRACE
0044 #define DL_DEBUG_CMD 1
0045 #else
0046 #define DL_DEBUG_TRACE 0
0047 #define DL_DEBUG_CMD 0
0048 #endif
0049
0050 #include <dlfcn.h>
0051
0052 #include "dl-load.h"
0053
0054 #include <tmacros.h>
0055
0056 #include <rtems/rtl/rtl-shell.h>
0057 #include <rtems/rtl/rtl-trace.h>
0058
0059 typedef int (*call_sig)(void);
0060
0061 static void dl_load_dump (void)
0062 {
0063 #if DL_DEBUG_CMD
0064 char* list[] = { "rtl", "list", NULL };
0065 char* sym[] = { "rtl", "sym", NULL };
0066 printf ("RTL List:\n");
0067 rtems_rtl_shell_command (2, list);
0068 printf ("RTL Sym:\n");
0069 rtems_rtl_shell_command (2, sym);
0070 #endif
0071 }
0072
0073 static bool dl_check_resolved(void* handle, bool has_unresolved)
0074 {
0075 int unresolved = 0;
0076 if (dlinfo (handle, RTLD_DI_UNRESOLVED, &unresolved) == 0)
0077 return 1;
0078 if (has_unresolved)
0079 {
0080 if (unresolved == 0)
0081 {
0082 dl_load_dump();
0083 return false;
0084 }
0085 }
0086 else
0087 {
0088 if (unresolved != 0)
0089 {
0090 dl_load_dump();
0091 return false;
0092 }
0093 }
0094 printf ("handel: %p: no unresolved externals\n", handle);
0095 return true;
0096 }
0097
0098 static void* dl_load_obj(const char* name, bool has_unresolved)
0099 {
0100 void* handle;
0101
0102 printf("load: %s\n", name);
0103
0104 handle = dlopen (name, RTLD_NOW | RTLD_GLOBAL);
0105 if (!handle)
0106 {
0107 printf("dlopen failed: %s\n", dlerror());
0108 return NULL;
0109 }
0110
0111 dl_check_resolved (handle, has_unresolved);
0112
0113 printf ("handle: %p loaded\n", handle);
0114
0115 return handle;
0116 }
0117
0118 int dl_load_test(void)
0119 {
0120 void* o1;
0121
0122 printf ("Test source (link in strstr): %s\n", dl_localise_file (__FILE__));
0123
0124 #if DL_DEBUG_TRACE
0125 rtems_rtl_trace_set_mask (DL_DEBUG_TRACE);
0126 #endif
0127
0128 o1 = dl_load_obj("/dl10-o1.o", false);
0129 if (!o1)
0130 return 1;
0131
0132 if (!dl_check_resolved (o1, false))
0133 return 1;
0134
0135 dl_load_dump ();
0136
0137 return 0;
0138 }