source: rtems/testsuites/libtests/dl07/dl-load.c @ 6c9f017

5
Last change on this file since 6c9f017 was 6c9f017, checked in by Chris Johns <chrisj@…>, on 02/02/19 at 04:09:53

libdl: Add powerpc large memory and small data support.

  • Add support for architecure sections that can be handled by the architecture back end.
  • Add trampoline/fixup support for PowerPC. This means the PowerPC now supports large memory loading of applications.
  • Add a bit allocator to manage small block based regions of memory.
  • Add small data (sdata/sbss) support for the PowerPC. The support makes the linker allocated small data region of memory a global resource available to libdl loaded object files.

Updates #3687
Updates #3685

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 * Copyright (c) 2014 Chris Johns <chrisj@rtems.org>.
3 * All rights reserved.
4 *
5 * The license and distribution terms for this file may be
6 * found in the file LICENSE in this distribution or at
7 * http://www.rtems.org/license/LICENSE.
8 */
9
10#define TEST_TRACE 0
11#if TEST_TRACE
12 #define DEBUG_TRACE (RTEMS_RTL_TRACE_DETAIL | \
13                      RTEMS_RTL_TRACE_WARNING | \
14                      RTEMS_RTL_TRACE_LOAD | \
15                      RTEMS_RTL_TRACE_UNLOAD | \
16                      RTEMS_RTL_TRACE_SYMBOL | \
17                      RTEMS_RTL_TRACE_RELOC | \
18                      RTEMS_RTL_TRACE_ALLOCATOR | \
19                      RTEMS_RTL_TRACE_UNRESOLVED | \
20                      RTEMS_RTL_TRACE_ARCHIVES | \
21                      RTEMS_RTL_TRACE_GLOBAL_SYM | \
22                      RTEMS_RTL_TRACE_DEPENDENCY)
23 #define DL_DEBUG_TRACE DEBUG_TRACE /* RTEMS_RTL_TRACE_ALL */
24 #define DL_RTL_CMDS    1
25#else
26 #define DL_DEBUG_TRACE 0
27 #define DL_RTL_CMDS    0
28#endif
29
30#include <dlfcn.h>
31
32#include "dl-load.h"
33
34#include <tmacros.h>
35
36#include <rtems/rtl/rtl-shell.h>
37#include <rtems/rtl/rtl-trace.h>
38
39typedef int (*call_sig)(void);
40
41static void dl_load_dump (void)
42{
43#if DL_RTL_CMDS
44  char* list[] = { "rtl", "list", NULL };
45  char* sym[] = { "rtl", "sym", NULL };
46  printf ("RTL List:\n");
47  rtems_rtl_shell_command (2, list);
48  printf ("RTL Sym:\n");
49  rtems_rtl_shell_command (2, sym);
50#endif
51}
52
53static void dl_check_resolved(void* handle, bool has_unresolved)
54{
55  int unresolved = 0;
56  rtems_test_assert (dlinfo (handle, RTLD_DI_UNRESOLVED, &unresolved) == 0);
57  if (has_unresolved)
58  {
59    if (unresolved == 0)
60    {
61      dl_load_dump();
62      rtems_test_assert (unresolved != 0);
63    }
64  }
65  else
66  {
67    if (unresolved != 0)
68    {
69      dl_load_dump();
70      rtems_test_assert (unresolved == 0);
71    }
72  }
73}
74
75static void* dl_load_obj(const char* name, bool has_unresolved)
76{
77  void* handle;
78
79  printf("load: %s\n", name);
80
81  handle = dlopen (name, RTLD_NOW | RTLD_GLOBAL);
82  if (!handle)
83  {
84    printf("dlopen failed: %s\n", dlerror());
85    return NULL;
86  }
87
88  dl_check_resolved (handle, has_unresolved);
89
90  printf ("handle: %p loaded\n", handle);
91
92  return handle;
93}
94
95static void dl_close (void* handle, const char* msg)
96{
97  int r;
98  printf ("%s: handle: %p closing\n", msg, handle);
99  r = dlclose (handle);
100  if (r != 0)
101    printf("dlclose failed: %s\n", dlerror());
102  rtems_test_assert (r == 0);
103}
104
105static int dl_call (void* handle, const char* func)
106{
107  call_sig call = dlsym (handle, func);
108  if (call == NULL)
109  {
110    printf("dlsym failed: symbol not found: %s\n", func);
111    return 1;
112  }
113  call ();
114  return 0;
115}
116
117int dl_load_test(void)
118{
119  void* o1;
120  void* o2;
121  void* o3;
122  void* o4;
123  void* o5;
124
125  printf ("Test source (link in strstr): %s\n", dl_localise_file (__FILE__));
126
127#if DL_DEBUG_TRACE
128  rtems_rtl_trace_set_mask (DL_DEBUG_TRACE);
129#endif
130
131  o1 = dl_load_obj("/dl07-o1.o", false);
132  if (!o1)
133    return 1;
134  o2 = dl_load_obj("/dl07-o2.o", false);
135  if (!o1)
136    return 1;
137  o3 = dl_load_obj("/dl07-o3.o", true);
138  if (!o1)
139    return 1;
140  o4 = dl_load_obj("/dl07-o4.o", false);
141  if (!o1)
142    return 1;
143  o5 = dl_load_obj("/dl07-o5.o", false);
144  if (!o1)
145    return 1;
146
147  dl_check_resolved (o3, false);
148
149  dl_load_dump ();
150
151  printf ("\n\nRun mains in each module:\n\n");
152  if (dl_call (o1, "rtems_main_o1"))
153    return 1;
154  if (dl_call (o2, "rtems_main_o2"))
155    return 1;
156  if (dl_call (o3, "rtems_main_o3"))
157    return 1;
158  if (dl_call (o4, "rtems_main_o4"))
159    return 1;
160  if (dl_call (o5, "rtems_main_o5"))
161    return 1;
162
163  /*
164   * Try and close the dependent modules, we should get an error.
165   */
166  printf ("unload test: o1\n");
167  rtems_test_assert (dlclose (o1) != 0);
168  printf ("unload test: o2\n");
169  rtems_test_assert (dlclose (o2) != 0);
170  printf ("unload test: o4\n");
171  rtems_test_assert (dlclose (o4) != 0);
172  printf ("unload test: o5\n");
173  rtems_test_assert (dlclose (o5) != 0);
174
175  dl_close (o3, "o3");
176  rtems_test_assert (dlclose (o1) != 0);
177  dl_close (o4, "o4");
178  rtems_test_assert (dlclose (o1) != 0);
179  dl_close (o5, "o5");
180  rtems_test_assert (dlclose (o1) != 0);
181  dl_close (o2, "o2");
182  dl_close (o1, "o1");
183
184  return 0;
185}
Note: See TracBrowser for help on using the repository browser.