diff options
author | Rabin Vincent <rabin@rab.in> | 2014-10-29 23:21:37 +0100 |
---|---|---|
committer | Tom Rini <trini@ti.com> | 2014-11-07 16:27:05 -0500 |
commit | 854d2b9753e464b7c1add062702565ebdb464119 (patch) | |
tree | 5ab86e1f507f24cadc6d1390776e848f56432df8 | |
parent | 5b471dee99a9dab381110060054e6b52e87f210a (diff) | |
download | u-boot-imx-854d2b9753e464b7c1add062702565ebdb464119.zip u-boot-imx-854d2b9753e464b7c1add062702565ebdb464119.tar.gz u-boot-imx-854d2b9753e464b7c1add062702565ebdb464119.tar.bz2 |
dlmalloc: ensure gd is set for early alloc
Attempting to run the sandbox leads to a segfault, because some dynamic
libraries (outside of u-boot) attempt to use malloc() to allocate memory
before u-boot's gd variable is initialized.
Check for gd not being NULL in the SYS_MALLOC_F_LEN handling, so that
malloc() doesn't crash when called at this point.
$ gdb -q --args ./u-boot
(gdb) r
Program received signal SIGSEGV, Segmentation fault.
0x0000000000412b9b in malloc (bytes=bytes@entry=37) at common/dlmalloc.c:2184
2184 if (!(gd->flags & GD_FLG_RELOC)) {
(gdb) p gd
$1 = (gd_t *) 0x0
(gdb) bt
#0 0x0000000000412b9b in malloc (bytes=bytes@entry=37) at common/dlmalloc.c:2184
#1 0x00007ffff75bf8e1 in set_binding_values (domainname=0x7ffff11f4f12 "libgpg-error", dirnamep=0x7fffffffe168, codesetp=0x0)
at bindtextdom.c:228
#2 0x00007ffff75bfb4c in set_binding_values (codesetp=0x0, dirnamep=0x7fffffffe168, domainname=<optimized out>) at bindtextdom.c:350
#3 __bindtextdomain (domainname=<optimized out>, dirname=0x7ffff11f4f00 "/usr/share/locale") at bindtextdom.c:348
#4 0x00007ffff11eca17 in ?? () from /lib/x86_64-linux-gnu/libgpg-error.so.0
#5 0x00007ffff7dea9fa in call_init (l=<optimized out>, argc=argc@entry=1, argv=argv@entry=0x7fffffffe208,
env=env@entry=0x7fffffffe218) at dl-init.c:78
#6 0x00007ffff7deaae3 in call_init (env=0x7fffffffe218, argv=0x7fffffffe208, argc=1, l=<optimized out>) at dl-init.c:36
#7 _dl_init (main_map=0x7ffff7ffe1a8, argc=1, argv=0x7fffffffe208, env=0x7fffffffe218) at dl-init.c:126
#8 0x00007ffff7ddd1ca in _dl_start_user () from /lib64/ld-linux-x86-64.so.2
Signed-off-by: Rabin Vincent <rabin@rab.in>
Acked-by: Simon Glass <sjg@chromium.org>
-rw-r--r-- | common/dlmalloc.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/common/dlmalloc.c b/common/dlmalloc.c index f987339..d87834d 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -2181,7 +2181,7 @@ Void_t* mALLOc(bytes) size_t bytes; INTERNAL_SIZE_T nb; #ifdef CONFIG_SYS_MALLOC_F_LEN - if (!(gd->flags & GD_FLG_RELOC)) { + if (gd && !(gd->flags & GD_FLG_RELOC)) { ulong new_ptr; void *ptr; |