All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] gdb: Add malloc and free symbols to kernel.exec to improve gdb functionality
@ 2022-03-18  6:34 Glenn Washburn
  2022-03-22 16:49 ` Daniel Kiper
  0 siblings, 1 reply; 2+ messages in thread
From: Glenn Washburn @ 2022-03-18  6:34 UTC (permalink / raw)
  To: Daniel Kiper, grub-devel; +Cc: Glenn Washburn

Add linker flags when linking kernel.exec to have malloc and free point to
grub_malloc and grub_free respectively. Some gdb functionality depends on
gdb locating the symbols "malloc" and "free", such as dynamically creating
strings for arguments to injected function calls. A trivial example would
the gdb command 'p strlen("astring")'. Make sure not to do this on emu
platforms, or an infinite loop occurs because emu has a special
grub_malloc() that calls malloc().

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 conf/Makefile.common | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/conf/Makefile.common b/conf/Makefile.common
index b343a038ee..2d8f1bf2e8 100644
--- a/conf/Makefile.common
+++ b/conf/Makefile.common
@@ -39,6 +39,13 @@ LDFLAGS_KERNEL = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC)
 CPPFLAGS_KERNEL = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) -DGRUB_KERNEL=1
 CCASFLAGS_KERNEL = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM)
 STRIPFLAGS_KERNEL = -R .rel.dyn -R .reginfo -R .note -R .comment -R .drectve -R .note.gnu.gold-version -R .MIPS.abiflags -R .ARM.exidx
+if !COND_emu
+if COND_HAVE_ASM_USCORE
+  LDFLAGS_KERNEL += -Wl,--defsym=_malloc=_grub_malloc -Wl,--defsym=_free=_grub_free
+else
+  LDFLAGS_KERNEL += -Wl,--defsym=malloc=grub_malloc -Wl,--defsym=free=grub_free
+endif
+endif
 
 CFLAGS_MODULE = $(CFLAGS_PLATFORM) -ffreestanding
 LDFLAGS_MODULE = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-r
-- 
2.27.0



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

* Re: [PATCH v2] gdb: Add malloc and free symbols to kernel.exec to improve gdb functionality
  2022-03-18  6:34 [PATCH v2] gdb: Add malloc and free symbols to kernel.exec to improve gdb functionality Glenn Washburn
@ 2022-03-22 16:49 ` Daniel Kiper
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Kiper @ 2022-03-22 16:49 UTC (permalink / raw)
  To: Glenn Washburn; +Cc: grub-devel

On Fri, Mar 18, 2022 at 01:34:05AM -0500, Glenn Washburn wrote:
> Add linker flags when linking kernel.exec to have malloc and free point to
> grub_malloc and grub_free respectively. Some gdb functionality depends on
> gdb locating the symbols "malloc" and "free", such as dynamically creating
> strings for arguments to injected function calls. A trivial example would
> the gdb command 'p strlen("astring")'. Make sure not to do this on emu
> platforms, or an infinite loop occurs because emu has a special
> grub_malloc() that calls malloc().
>
> Signed-off-by: Glenn Washburn <development@efficientek.com>

Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>

Daniel


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

end of thread, other threads:[~2022-03-22 16:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-18  6:34 [PATCH v2] gdb: Add malloc and free symbols to kernel.exec to improve gdb functionality Glenn Washburn
2022-03-22 16:49 ` Daniel Kiper

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.