[PATCH 2/2] aarch64: Add workaround for GDB bug handling string literals
Yury Khrustalev
yury.khrustalev@arm.com
Tue Jun 30 09:47:00 GMT 2026
* Florian
On Mon, Jun 29, 2026 at 11:07:13PM +0200, Florian Weimer wrote:
> When GDB evaluates an expression in the inferior, it first
> creates a copy of the string using malloc. For this malloc
> call, GDB was not tracking properly if the malloc symbol is
> actually an IFUNC resolver. This means that the IFUNC
> resolver gets called like the real malloc function.
>
> This change adds a kludge to detect this, which prevents GDB
> from overwriting the __libc_malloc code with the user-supplied
> string literal.
>
> ...
>
> diff --git a/sysdeps/aarch64/multiarch/malloc-ifuncs.c b/sysdeps/aarch64/multiarch/malloc-ifuncs.c
> index 648fb617de..3552168ecd 100644
>
> ...
>
> +/* Return true if the resolver function has been called through GDB.
> + This used below to determine if GDB incorrectly calls the malloc
> + IFUNC resolver instead of the resolver result. The trampoline
> + address is either on the stack, or the kernel-provided entry point,
> + depending on architecture.
> +
> + A fixed GDB will get the malloc address from the GOT. Calling
> + malloc before relocation processing is complete should use the
> + ld.so malloc, which does not involve an IFUNC. */
> +static inline bool
> +called_from_gdb (uintptr_t return_address, uintptr_t stack_frame)
> +{
> +#ifdef SHARED
> + /* Assume that the stack grows downwards. */
> + if (stack_frame <= return_address && return_address <= stack_frame + 128)
> + return true;
> +
> + /* GDB uses the kernel-provided entry point on some architectures
> + for the trampoline. */
> + if (return_address == GLRO(dl_entry))
> + return true;
> +#endif
> + return false;
> +}
Although this does fix the regressions in GDB testsuite, I think this is
a wrong approach and we should not do this.
Thanks,
Yury
More information about the Libc-alpha
mailing list