summaryrefslogtreecommitdiff
path: root/package/mpatrol/mpatrol-uclibc.patch
blob: aab70a87687824a9cad2fbca7f58fb26f6327753 (plain)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
Patches for mpatrol to support uClibc and MIPS full call stack tracing
by Dan Howell <dahowell@directv.com>

diff -urN mpatrol/src/config.h mpatrol-uclibc/src/config.h
--- mpatrol/src/config.h	2006-04-27 15:58:21.000000000 -0700
+++ mpatrol-uclibc/src/config.h	2006-05-05 20:32:58.000000000 -0700
@@ -795,6 +795,10 @@
  */
 
 #ifndef MP_INIT_SUPPORT
+/* Note that machine.c currently only implements MP_INIT_SUPPORT for
+ * x86, 68k, 88k, and Sparc architechtures. */
+#if ARCH == ARCH_IX86 || ARCH == ARCH_M68K || \
+    ARCH == ARCH_M88K || ARCH == ARCH_SPARC
 #if SYSTEM == SYSTEM_DGUX || SYSTEM == SYSTEM_DRSNX || \
     SYSTEM == SYSTEM_DYNIX || SYSTEM == SYSTEM_LINUX || \
     SYSTEM == SYSTEM_SOLARIS || SYSTEM == SYSTEM_UNIXWARE
@@ -809,6 +813,9 @@
 #else /* SYSTEM */
 #define MP_INIT_SUPPORT 0
 #endif /* SYSTEM */
+#else /* ARCH */
+#define MP_INIT_SUPPORT 0
+#endif
 #endif /* MP_INIT_SUPPORT */
 
 
diff -urN mpatrol/src/inter.c mpatrol-uclibc/src/inter.c
--- mpatrol/src/inter.c	2002-01-08 12:13:59.000000000 -0800
+++ mpatrol-uclibc/src/inter.c	2006-05-17 18:02:04.000000000 -0700
@@ -79,12 +79,24 @@
 
 #if TARGET == TARGET_UNIX
 #if SYSTEM == SYSTEM_LINUX
+#ifndef __UCLIBC__
 /* This contains a pointer to the environment variables for a process.  If
  * it is not set up yet then we must use sbrk() to allocate all memory since
  * we can't initialise mpatrol until the environment variable can be read.
  */
 
 extern char **__environ;
+#else /* __UCLIBC__ */
+/* In uClibc, the dynamic loader calls malloc() and related functions,
+ * and sets __environ before these calls, so we can't use it to determine
+ * if we can initialize mpatrol. Instead, we use __progname, which is set
+ * in __uClibc_main just before before uClibc transfers control to the
+ * application's main() function (and static constructors, if any). Before
+ * this, we must use sbrk() to allocate memory.
+ */
+
+extern const char *__progname;
+#endif /* __UCLIBC__ */
 #elif SYSTEM == SYSTEM_TRU64
 /* The exception support library on Tru64 always allocates some memory from
  * the heap in order to initialise the code address range tables.  We need
@@ -118,7 +130,11 @@
 
 #if TARGET == TARGET_UNIX
 #if SYSTEM == SYSTEM_LINUX
+#ifndef __UCLIBC__
 #define crt_initialised() (__environ)
+#else /* __UCLIBC__ */
+#define crt_initialised() (__progname)
+#endif /* __UCLIBC__ */
 #elif SYSTEM == SYSTEM_TRU64
 #define crt_initialised() (__exc_crd_list_head && init_flag)
 #else /* SYSTEM */
@@ -306,7 +322,7 @@
     alloctype t;
     int c;
 
-    if (memhead.fini || (memhead.astack.size == 0))
+    if (memhead.fini || (memhead.astack.size == 0) || memhead.recur != 1)
         return;
 #if MP_FULLSTACK
     /* Create the address nodes for the current call.  This is not necessarily
@@ -1307,7 +1323,7 @@
     loginfo v;
     int j;
 
-    if (!memhead.init || memhead.fini)
+    if (!memhead.init || memhead.fini || memhead.recur != 0)
     {
         __mp_memset(p, c, l);
         return p;
@@ -1371,7 +1387,7 @@
     loginfo v;
     int j;
 
-    if (!memhead.init || memhead.fini)
+    if (!memhead.init || memhead.fini || memhead.recur != 0)
         if (f == AT_MEMCCPY)
         {
             if (r = __mp_memfind(p, l, &c, 1))
diff -ur mpatrol/src/machine.c mpatrol-uclibc/src/machine.c
--- mpatrol/src/machine.c	2002-01-08 12:13:59.000000000 -0800
+++ mpatrol-uclibc/src/machine.c	2006-06-07 15:11:20.000000000 -0700
@@ -217,6 +217,19 @@
 	.end	__mp_stackpointer
 
 
+/* Obtain the frame pointer (s8) for the current function.
+ */
+
+	.text
+	.globl	__mp_framepointer
+	.ent	__mp_framepointer
+__mp_framepointer:
+	.frame	$29,0,$31
+	move	$2,$30
+	j	$31
+	.end	__mp_framepointer
+
+
 /* Obtain the return address for the current function.
  */
 
diff -urN mpatrol/src/memory.c mpatrol-uclibc/src/memory.c
--- mpatrol/src/memory.c	2002-01-08 12:13:59.000000000 -0800
+++ mpatrol-uclibc/src/memory.c	2006-05-12 18:12:39.000000000 -0700
@@ -47,7 +47,7 @@
 #endif /* SYSTEM */
 #include <setjmp.h>
 #include <signal.h>
-#if MP_SIGINFO_SUPPORT
+#if MP_SIGINFO_SUPPORT && SYSTEM != SYSTEM_LINUX
 #include <siginfo.h>
 #endif /* MP_SIGINFO_SUPPORT */
 #include <fcntl.h>
diff -urN mpatrol/src/signals.c mpatrol-uclibc/src/signals.c
--- mpatrol/src/signals.c	2002-01-08 12:13:59.000000000 -0800
+++ mpatrol-uclibc/src/signals.c	2006-05-12 18:12:19.000000000 -0700
@@ -36,7 +36,7 @@
 #include <stdlib.h>
 #include <signal.h>
 #if TARGET == TARGET_UNIX
-#if MP_SIGINFO_SUPPORT
+#if MP_SIGINFO_SUPPORT && SYSTEM != SYSTEM_LINUX
 #include <siginfo.h>
 #endif /* MP_SIGINFO_SUPPORT */
 #elif TARGET == TARGET_WINDOWS
diff -urN mpatrol/src/stack.c mpatrol-uclibc/src/stack.c
--- mpatrol/src/stack.c	2002-01-08 12:13:59.000000000 -0800
+++ mpatrol-uclibc/src/stack.c	2006-06-22 15:39:04.000000000 -0700
@@ -48,7 +48,7 @@
 #else /* MP_LIBRARYSTACK_SUPPORT */
 #if TARGET == TARGET_UNIX
 #include <setjmp.h>
-#if MP_SIGINFO_SUPPORT
+#if MP_SIGINFO_SUPPORT && SYSTEM != SYSTEM_LINUX
 #include <siginfo.h>
 #endif /* MP_SIGINFO_SUPPORT */
 #if SYSTEM == SYSTEM_DRSNX || SYSTEM == SYSTEM_SOLARIS
@@ -58,6 +58,17 @@
 #define R_SP REG_SP
 #endif /* R_SP */
 #endif /* ARCH */
+#elif SYSTEM == SYSTEM_LINUX
+#if ARCH == ARCH_MIPS
+#include <linux/unistd.h>
+/* We need the ucontext defined in asm/ucontext.h, but sys/ucontext.h
+ * has a conflicting definition of ucontext. So we'll trick the
+ * preprocessor into letting the include file define a non-conflicting
+ * name. */
+#define ucontext asm_ucontext
+#include <asm/ucontext.h>
+#undef ucontext
+#endif /* ARCH */
 #endif /* SYSTEM */
 #endif /* TARGET */
 #endif /* MP_LIBRARYSTACK_SUPPORT */
@@ -122,6 +133,15 @@
 #define SP_OFFSET 2 /* stack pointer offset has been set */
 #define SP_LOWER  4 /* lower part of stack pointer offset has been set */
 #define SP_UPPER  8 /* upper part of stack pointer offset has been set */
+#define BR_UNCOND 16 /* unconditional branch needs to be taken */
+#define BR_COND   32 /* conditional branch encountered */
+#define RA_NOFRAME 64 /* no frame - return address is in ra register */
+#define SP_IN_FP  128 /* stack pointer stored in frame pointer (s8) register */
+
+#if SYSTEM == SYSTEM_LINUX
+#define RA_SIGTRAMP  1 /* return address is a signal trampoline */
+#define RA_SIGRETURN 2 /* return address is in the signalled function */
+#endif /* SYSTEM */
 #endif /* TARGET && ARCH */
 #endif /* MP_BUILTINSTACK_SUPPORT && MP_LIBRARYSTACK_SUPPORT */
 
@@ -152,6 +172,13 @@
 #endif /* SYSTEM */
 #endif /* SYSTEM */
 #else /* MP_LIBRARYSTACK_SUPPORT */
+/* On some systems, such as those using uClibc, the signal() function may
+ * call memcpy() or other memory related functions, so we need to guard
+ * against recursion.
+ */
+
+static unsigned char recursive;
+
 static jmp_buf environment;
 #if MP_SIGINFO_SUPPORT
 static struct sigaction bushandler;
@@ -261,23 +288,41 @@
 int
 unwind(frameinfo *f)
 {
-    long p, s;
-    unsigned long a, i, q;
+    long p, m, s;
+    unsigned long a, i, q, t, b, r;
     unsigned short l, u;
 
     s = -1;
-    p = 0;
+    p = m = 0;
     q = 0xFFFFFFFF;
     l = u = 0;
     a = 0;
+    t = b = 0;
     /* Determine the current stack pointer and return address if we are
      * initiating call stack traversal.
      */
     if (f->ra == 0)
     {
         f->sp = __mp_stackpointer();
+        f->fp = __mp_framepointer();
         f->ra = __mp_returnaddress();
     }
+#if SYSTEM == SYSTEM_LINUX
+    /* Handle signal frames.
+     */
+    if (f->ra & RA_SIGRETURN)
+    {
+        /* in case of frameless function, get ra and sp from sigcontext */
+        p = ((struct sigcontext *) f->sp)->sc_regs[31];
+        f->fp = ((struct sigcontext *) f->sp)->sc_regs[30];
+        f->sp = ((struct sigcontext *) f->sp)->sc_regs[29];
+        a |= RA_NOFRAME;
+    }
+    f->ra &= ~3;
+#endif
+    /* Save initial code-reading starting point.
+     */
+    r = f->ra;
     /* Search for the return address offset in the stack frame.
      */
     while (!((a & RA_OFFSET) && (a & SP_OFFSET)) && (f->ra < q))
@@ -294,6 +339,67 @@
             s = 0;
             a |= SP_OFFSET;
         }
+        else if (i == 0x03C0E821)
+        {
+            /* move sp,s8 */
+            a |= SP_IN_FP;
+        }
+        else if ((i >> 28 == 0x1) || (i >> 26 == 0x01))
+        {
+            /* branch */
+            t = f->ra + ((signed short)(i & 0xFFFF) * 4) + 4;
+            if ((i >> 16 == 0x1000) && !(a & BR_COND))
+            {
+                /* unconditional branch, if no conditional branch could
+                   branch past this code */
+                b = t;
+                a |= BR_UNCOND;
+            }
+            else
+            {
+                /* conditional branch, ignore if previous conditional branch
+                   is further forwards */
+                if ((t > b) && (t > f->ra))
+                {
+                    b = t;
+                    a |= BR_COND;
+                    /* can branch past an unconditional branch */
+                    if (b > q)
+                        q = 0xFFFFFFFF;
+                }
+                else if (t < r)
+                {
+                    /* but if branching backwards, set reverse branch target to
+                       lowest address target encountered so far */
+                    r = t;
+                    /* ensure a loop back */
+                    q = 0xFFFFFFFF;
+                }
+            }
+        }
+#if SYSTEM == SYSTEM_LINUX
+        else if (i == 0x0000000c)
+        {
+            /* syscall - check for signal handler trampolines */
+            if (*((unsigned long *) (f->ra - 4)) == 0x24020000 + __NR_sigreturn)
+            {
+                /* li v0,__NR_sigreturn */
+                /* get pointer to sigcontext */
+                f->sp = f->ra + 4;
+                f->ra = ((struct sigcontext *) f->sp)->sc_pc | RA_SIGRETURN;
+                return 1;
+            }
+            else if (*((unsigned long *) (f->ra - 4)) == 0x24020000 + __NR_rt_sigreturn)
+            {
+                /* li v0,__NR_rt_sigreturn */
+                /* get pointer to sigcontext */
+                f->sp = f->ra + 4 +
+                    sizeof(struct siginfo) + offsetof(struct asm_ucontext, uc_mcontext);
+                f->ra = ((struct sigcontext *) f->sp)->sc_pc | RA_SIGRETURN;
+                return 1;
+            }
+        }
+#endif
         else
             switch (i >> 16)
             {
@@ -319,6 +425,10 @@
                 u = i & 0xFFFF;
                 a |= SP_UPPER;
                 break;
+              case 0x8FBE:
+                /* lw s8,##(sp) */
+                m = i & 0xFFFF;
+                break;
               case 0x8FBF:
                 /* lw ra,##(sp) */
                 p = i & 0xFFFF;
@@ -326,9 +436,52 @@
                 break;
             }
         f->ra += 4;
+        /* Process branch instructions.
+         */
+        if (a & BR_COND)
+        {
+            if (f->ra >= b)
+            {
+                /* reached target of previous conditional branch */
+                a &= ~BR_COND;
+                b = 0;
+            }
+        }
+        else if (a & BR_UNCOND)
+            /* clear branch flag and process instruction in delay slot */
+            a &= ~BR_UNCOND;
+        else if (b != 0)
+        {
+            /* now follow the unconditional branch */
+            if (b < f->ra)
+            {
+                /* avoid infinite loops */
+                q = f->ra - 8;
+                /* go back as far as possible */
+                if (r < b)
+                    b = r;
+            }
+            f->ra = b;
+            b = 0;
+        }
     }
     if ((s == 0) && ((a & SP_LOWER) || (a & SP_UPPER)))
         s = (u << 16) | l;
+#if SYSTEM == SYSTEM_LINUX
+    if ((a & RA_NOFRAME) && !(a & RA_OFFSET) &&
+        ((*((unsigned long *) (p - 8)) == 0x0320F809) ||
+         (*((unsigned long *) (p - 8)) >> 16 == 0x0C10)))
+    {
+        /* jalr ra,t9 or jal ## */
+        /* f->sp already set */
+        f->ra = p;
+        return 1;
+    }
+#endif
+    if (a & SP_IN_FP)
+        f->sp = f->fp;
+    if (m > 0)
+        f->fp = ((unsigned long *) f->sp)[m >> 2];
     if ((s > 0) && (i = ((unsigned long *) f->sp)[p >> 2]) &&
         ((*((unsigned long *) (i - 8)) == 0x0320F809) ||
          (*((unsigned long *) (i - 8)) >> 16 == 0x0C10)))
@@ -338,6 +491,19 @@
         f->ra = i;
         return 1;
     }
+#if SYSTEM == SYSTEM_LINUX
+    else if ((s > 0) && (i != 0) &&
+             (*((unsigned long *) (i + 4)) == 0x0000000c) &&
+             ((*((unsigned long *) i) == 0x24020000 + __NR_sigreturn) ||
+              (*((unsigned long *) i) == 0x24020000 + __NR_rt_sigreturn)))
+    {
+        /* li v0,__NR_sigreturn or __NR_rt_sigreturn ; syscall */
+        /* signal trampoline */
+        f->sp += s;
+        f->ra = i | RA_SIGTRAMP;
+        return 1;
+    }
+#endif
     f->sp = f->ra = 0;
     return 0;
 }
@@ -573,16 +739,14 @@
     }
 #endif /* TARGET */
 #else /* MP_BUILTINSTACK_SUPPORT && MP_LIBRARYSTACK_SUPPORT */
-#if (TARGET == TARGET_UNIX && (ARCH == ARCH_IX86 || ARCH == ARCH_M68K || \
-      ARCH == ARCH_M88K || ARCH == ARCH_POWER || ARCH == ARCH_POWERPC || \
-      ARCH == ARCH_SPARC)) || ((TARGET == TARGET_WINDOWS || \
-      TARGET == TARGET_NETWARE) && ARCH == ARCH_IX86)
-    /* This section is not complete in any way for the OS / processor
-     * combinations it supports, as it is intended to be as portable as possible
-     * without writing in assembler.  In particular, optimised code is likely
-     * to cause major problems for stack traversal on some platforms.
-     */
 #if TARGET == TARGET_UNIX
+    /* On some systems, such as those using uClibc, the signal() function may
+     * call memcpy() or other memory related functions, so we need to guard
+     * against recursion here.
+     */
+   if (!recursive)
+   {
+    recursive = 1;
 #if MP_SIGINFO_SUPPORT
     i.sa_flags = 0;
     (void *) i.sa_handler = (void *) stackhandler;
@@ -597,6 +761,15 @@
         __mp_newframe(p, p->first);
     else
 #endif /* TARGET */
+#if (TARGET == TARGET_UNIX && (ARCH == ARCH_IX86 || ARCH == ARCH_M68K || \
+      ARCH == ARCH_M88K || ARCH == ARCH_POWER || ARCH == ARCH_POWERPC || \
+      ARCH == ARCH_SPARC)) || ((TARGET == TARGET_WINDOWS || \
+      TARGET == TARGET_NETWARE) && ARCH == ARCH_IX86)
+    /* This section is not complete in any way for the OS / processor
+     * combinations it supports, as it is intended to be as portable as possible
+     * without writing in assembler.  In particular, optimised code is likely
+     * to cause major problems for stack traversal on some platforms.
+     */
     {
         if (p->frame == NULL)
             if (p->first == NULL)
@@ -640,32 +813,10 @@
             r = 1;
         }
     }
-#if TARGET == TARGET_UNIX
-#if MP_SIGINFO_SUPPORT
-    sigaction(SIGBUS, &bushandler, NULL);
-    sigaction(SIGSEGV, &segvhandler, NULL);
-#else /* MP_SIGINFO_SUPPORT */
-    signal(SIGBUS, bushandler);
-    signal(SIGSEGV, segvhandler);
-#endif /* MP_SIGINFO_SUPPORT */
-#endif /* TARGET */
 #elif TARGET == TARGET_UNIX && ARCH == ARCH_MIPS
     /* For the MIPS architecture we perform code reading to determine the
      * frame pointers and the return addresses.
      */
-#if MP_SIGINFO_SUPPORT
-    i.sa_flags = 0;
-    (void *) i.sa_handler = (void *) stackhandler;
-    sigfillset(&i.sa_mask);
-    sigaction(SIGBUS, &i, &bushandler);
-    sigaction(SIGSEGV, &i, &segvhandler);
-#else /* MP_SIGINFO_SUPPORT */
-    bushandler = signal(SIGBUS, stackhandler);
-    segvhandler = signal(SIGSEGV, stackhandler);
-#endif /* MP_SIGINFO_SUPPORT */
-    if (setjmp(environment))
-        __mp_newframe(p, p->first);
-    else
     {
         if (p->frame == NULL)
             unwind(&p->next);
@@ -673,6 +824,10 @@
         {
             p->frame = (void *) p->next.sp;
             p->addr = (void *) (p->next.ra - 8);
+#if SYSTEM == SYSTEM_LINUX
+            if (p->next.ra & (RA_SIGTRAMP|RA_SIGRETURN))
+                p->addr = (void *) (p->next.ra & ~3);
+#endif /* SYSTEM */
             r = 1;
         }
         else
@@ -681,6 +836,8 @@
             p->addr = NULL;
         }
     }
+#endif /* TARGET && ARCH */
+#if TARGET == TARGET_UNIX
 #if MP_SIGINFO_SUPPORT
     sigaction(SIGBUS, &bushandler, NULL);
     sigaction(SIGSEGV, &segvhandler, NULL);
@@ -688,7 +845,9 @@
     signal(SIGBUS, bushandler);
     signal(SIGSEGV, segvhandler);
 #endif /* MP_SIGINFO_SUPPORT */
-#endif /* TARGET && ARCH */
+    recursive = 0;
+   } /* if (!bushandler) */
+#endif /* TARGET */
 #endif /* MP_BUILTINSTACK_SUPPORT && MP_LIBRARYSTACK_SUPPORT */
     return r;
 }
diff -ur mpatrol/src/stack.h mpatrol-uclibc/src/stack.h
--- mpatrol/src/stack.h	2002-01-08 12:13:59.000000000 -0800
+++ mpatrol-uclibc/src/stack.h	2006-06-07 15:12:58.000000000 -0700
@@ -75,6 +75,7 @@
 typedef struct frameinfo
 {
     unsigned int sp; /* stack pointer */
+    unsigned int fp; /* frame pointer (s8) */
     unsigned int ra; /* return address */
 }
 frameinfo;
diff -urN mpatrol/src/symbol.c mpatrol-uclibc/src/symbol.c
--- mpatrol/src/symbol.c	2002-01-08 12:13:59.000000000 -0800
+++ mpatrol-uclibc/src/symbol.c	2006-05-24 15:43:04.000000000 -0700
@@ -1157,7 +1157,7 @@
             __mp_error(ET_MAX, AT_MAX, NULL, 0, "%s: %s\n", f, m);
         return 0;
     }
-    if (n == 0)
+    if (n <= sizeof(asymbol *))
     {
         /* If we couldn't find the symbol table then it is likely that the file
          * has been stripped.  However, if the file was dynamically linked then
@@ -1172,7 +1172,7 @@
                 __mp_error(ET_MAX, AT_MAX, NULL, 0, "%s: %s\n", f, m);
             return 0;
         }
-        if (n == 0)
+        if (n <= sizeof(asymbol *))
         {
             m = "missing symbol table";
             if (a != NULL)
@@ -1893,6 +1893,17 @@
                     l = (dynamiclink *) *((unsigned long *) d->d_un.d_ptr + 1);
                 break;
             }
+#if ARCH == ARCH_MIPS
+            else if (d->d_tag == DT_MIPS_RLD_MAP)
+            {
+                /* MIPS elf has DT_MIPS_RLD_MAP instead of DT_DEBUG. */
+                if (!d->d_un.d_ptr || !(*(unsigned long **) d->d_un.d_ptr))
+                    l = NULL;
+                else
+                    l = (dynamiclink *) *((*(unsigned long **) d->d_un.d_ptr) + 1);
+                break;
+            }
+#endif /* ARCH */
         /* We skip past the first item on the list since it represents the
          * executable file, but we may wish to record the name of the file
          * if we haven't already determined it.