1 Fix DT_DEBUG handling on MIPS in musl libc.
2 With this change gdb will load the symbol files for shared libraries on MIPS too.
4 This patch was taken from this thread: https://www.openwall.com/lists/musl/2022/01/09/4
6 --- a/arch/mips/reloc.h
7 +++ b/arch/mips/reloc.h
10 #define NEED_MIPS_GOT_RELOCS 1
11 #define DT_DEBUG_INDIRECT DT_MIPS_RLD_MAP
12 +#define DT_DEBUG_INDIRECT_REL DT_MIPS_RLD_MAP_REL
13 #define ARCH_SYM_REJECT_UND(s) (!((s)->st_other & STO_MIPS_PLT))
15 #define CRTJMP(pc,sp) __asm__ __volatile__( \
16 --- a/arch/mips64/reloc.h
17 +++ b/arch/mips64/reloc.h
20 #define NEED_MIPS_GOT_RELOCS 1
21 #define DT_DEBUG_INDIRECT DT_MIPS_RLD_MAP
22 +#define DT_DEBUG_INDIRECT_REL DT_MIPS_RLD_MAP_REL
23 #define ARCH_SYM_REJECT_UND(s) (!((s)->st_other & STO_MIPS_PLT))
25 #define CRTJMP(pc,sp) __asm__ __volatile__( \
26 --- a/arch/mipsn32/reloc.h
27 +++ b/arch/mipsn32/reloc.h
30 #define NEED_MIPS_GOT_RELOCS 1
31 #define DT_DEBUG_INDIRECT DT_MIPS_RLD_MAP
32 +#define DT_DEBUG_INDIRECT_REL DT_MIPS_RLD_MAP_REL
33 #define ARCH_SYM_REJECT_UND(s) (!((s)->st_other & STO_MIPS_PLT))
35 #define CRTJMP(pc,sp) __asm__ __volatile__( \
38 @@ -1923,6 +1923,10 @@ void __dls3(size_t *sp, size_t *auxv)
39 size_t *ptr = (size_t *) app.dynv[i+1];
40 *ptr = (size_t)&debug;
42 + if (app.dynv[i]==DT_DEBUG_INDIRECT_REL) {
43 + size_t *ptr = (size_t *)((size_t)&app.dynv[i] + app.dynv[i+1]);
44 + *ptr = (size_t)&debug;
48 /* This must be done before final relocations, since it calls
49 --- a/src/internal/dynlink.h
50 +++ b/src/internal/dynlink.h
51 @@ -92,6 +92,10 @@ struct fdpic_dummy_loadmap {
52 #define DT_DEBUG_INDIRECT 0
55 +#ifndef DT_DEBUG_INDIRECT_REL
56 +#define DT_DEBUG_INDIRECT_REL 0