mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] ldso: fix GDB dynamic linker info on MIPS
@ 2016-01-30 18:20 Felix Fietkau
  2016-01-30 18:24 ` Rich Felker
  0 siblings, 1 reply; 2+ messages in thread
From: Felix Fietkau @ 2016-01-30 18:20 UTC (permalink / raw)
  To: musl

GDB is looking for a pointer to the ldso debug info in the data of the
.rld_map section.

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
---
 arch/mips/reloc.h  | 1 +
 src/ldso/dynlink.c | 9 ++++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/arch/mips/reloc.h b/arch/mips/reloc.h
index 9b40e3d..e9cb209 100644
--- a/arch/mips/reloc.h
+++ b/arch/mips/reloc.h
@@ -25,6 +25,7 @@
 
 #define NEED_MIPS_GOT_RELOCS 1
 #define DYNAMIC_IS_RO 1
+#define DT_DEBUG_INDIRECT DT_MIPS_RLD_MAP
 #define ARCH_SYM_REJECT_UND(s) (!((s)->st_other & STO_MIPS_PLT))
 
 #define CRTJMP(pc,sp) __asm__ __volatile__( \
diff --git a/src/ldso/dynlink.c b/src/ldso/dynlink.c
index 93e7d67..dd85eea 100644
--- a/src/ldso/dynlink.c
+++ b/src/ldso/dynlink.c
@@ -1584,11 +1584,18 @@ _Noreturn void __dls3(size_t *sp)
 	load_deps(&app);
 	make_global(&app);
 
+	for (i=0; app.dynv[i]; i+=2) {
 #ifndef DYNAMIC_IS_RO
-	for (i=0; app.dynv[i]; i+=2)
 		if (app.dynv[i]==DT_DEBUG)
 			app.dynv[i+1] = (size_t)&debug;
 #endif
+#ifdef DT_DEBUG_INDIRECT
+		if (app.dynv[i]==DT_DEBUG_INDIRECT) {
+			size_t *ptr = (size_t *) app.dynv[i+1];
+			*ptr = (size_t)&debug;
+		}
+#endif
+	}
 
 	/* The main program must be relocated LAST since it may contin
 	 * copy relocations which depend on libraries' relocations. */
-- 
2.2.2



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] ldso: fix GDB dynamic linker info on MIPS
  2016-01-30 18:20 [PATCH] ldso: fix GDB dynamic linker info on MIPS Felix Fietkau
@ 2016-01-30 18:24 ` Rich Felker
  0 siblings, 0 replies; 2+ messages in thread
From: Rich Felker @ 2016-01-30 18:24 UTC (permalink / raw)
  To: musl

On Sat, Jan 30, 2016 at 07:20:19PM +0100, Felix Fietkau wrote:
> GDB is looking for a pointer to the ldso debug info in the data of the
> ..rld_map section.
> 
> Signed-off-by: Felix Fietkau <nbd@openwrt.org>
> ---
>  arch/mips/reloc.h  | 1 +
>  src/ldso/dynlink.c | 9 ++++++++-
>  2 files changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/mips/reloc.h b/arch/mips/reloc.h
> index 9b40e3d..e9cb209 100644
> --- a/arch/mips/reloc.h
> +++ b/arch/mips/reloc.h
> @@ -25,6 +25,7 @@
>  
>  #define NEED_MIPS_GOT_RELOCS 1
>  #define DYNAMIC_IS_RO 1
> +#define DT_DEBUG_INDIRECT DT_MIPS_RLD_MAP
>  #define ARCH_SYM_REJECT_UND(s) (!((s)->st_other & STO_MIPS_PLT))
>  
>  #define CRTJMP(pc,sp) __asm__ __volatile__( \
> diff --git a/src/ldso/dynlink.c b/src/ldso/dynlink.c
> index 93e7d67..dd85eea 100644
> --- a/src/ldso/dynlink.c
> +++ b/src/ldso/dynlink.c
> @@ -1584,11 +1584,18 @@ _Noreturn void __dls3(size_t *sp)
>  	load_deps(&app);
>  	make_global(&app);
>  
> +	for (i=0; app.dynv[i]; i+=2) {
>  #ifndef DYNAMIC_IS_RO
> -	for (i=0; app.dynv[i]; i+=2)
>  		if (app.dynv[i]==DT_DEBUG)
>  			app.dynv[i+1] = (size_t)&debug;
>  #endif
> +#ifdef DT_DEBUG_INDIRECT
> +		if (app.dynv[i]==DT_DEBUG_INDIRECT) {
> +			size_t *ptr = (size_t *) app.dynv[i+1];
> +			*ptr = (size_t)&debug;
> +		}
> +#endif
> +	}
>  
>  	/* The main program must be relocated LAST since it may contin
>  	 * copy relocations which depend on libraries' relocations. */
> -- 
> 2.2.2

This certainly works, but DYNAMIC_IS_RO and DT_DEBUG_INDIRECT are
probably redundant now; I can't imagine wanting one without the other.
I've also tried to replace #if/#ifdef in dynlink.c with if, in the
interest of catching warnings/errors no matter what arch we're
compiling for, so maybe we could do in internal/dynlink.h:

#ifndef DT_DEBUG_INDIRECT
#define DT_DEBUG_INDIRECT 0
#endif

then in dynlink.c:

		if (!DT_DEBUG_INDIRECT && app.dynv[i]==DT_DEBUG)
		...
		if (DT_DEBUG_INDIRECT && app.dynv[i]==DT_DEBUG_INDIRECT)

What do you think?

Rich


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-01-30 18:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-30 18:20 [PATCH] ldso: fix GDB dynamic linker info on MIPS Felix Fietkau
2016-01-30 18:24 ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).