80fe15e84188d1805643feecde2b59cce27d6c91
[openwrt/openwrt.git] / toolchain / musl / patches / 800-mips_pie_debug.patch
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.
3
4 This patch was taken from this thread: https://www.openwall.com/lists/musl/2022/01/09/4
5
6 --- a/arch/mips/reloc.h
7 +++ b/arch/mips/reloc.h
8 @@ -29,6 +29,7 @@
9
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))
14
15 #define CRTJMP(pc,sp) __asm__ __volatile__( \
16 --- a/arch/mips64/reloc.h
17 +++ b/arch/mips64/reloc.h
18 @@ -38,6 +38,7 @@
19
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))
24
25 #define CRTJMP(pc,sp) __asm__ __volatile__( \
26 --- a/arch/mipsn32/reloc.h
27 +++ b/arch/mipsn32/reloc.h
28 @@ -29,6 +29,7 @@
29
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))
34
35 #define CRTJMP(pc,sp) __asm__ __volatile__( \
36 --- a/ldso/dynlink.c
37 +++ b/ldso/dynlink.c
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;
41 }
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;
45 + }
46 }
47
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
53 #endif
54
55 +#ifndef DT_DEBUG_INDIRECT_REL
56 +#define DT_DEBUG_INDIRECT_REL 0
57 +#endif
58 +
59 #define AUX_CNT 32
60 #define DYN_CNT 32
61