
This fix seems to be a twin of v2015.01 commit 854d2b9753e4 ("dlmalloc: ensure gd is set for early alloc"). Here is a gdb backtrace to make them look even more similar (sandbox build):
(gdb) run Starting program: /path/to/u-boot [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault. 0x00000000004123c0 in free (mem=0x0) at common/dlmalloc.c:2460 2460 if (mem == NULL) /* free(0) has no effect */ (gdb) where #0 0x00000000004123c0 in free (mem=0x0) at common/dlmalloc.c:2460 #1 0x00007ffff3f46cea in ?? () from /lib/x86_64-linux-gnu/libselinux.so.1 #2 0x00007ffff7de76ba in call_init (l=<optimized out>, argc=argc@entry=1, argv=argv@entry=0x7fffffffd928, env=env@entry=0x7fffffffd938) at dl-init.c:72 #3 0x00007ffff7de77cb in call_init (env=0x7fffffffd938, argv=0x7fffffffd928, argc=1, l=<optimized out>) at dl-init.c:30 #4 _dl_init (main_map=0x7ffff7ffe168, argc=1, argv=0x7fffffffd928, env=0x7fffffffd938) at dl-init.c:120 #5 0x00007ffff7dd7c6a in _dl_start_user () from /lib64/ld-linux-x86-64.so.2 #6 0x0000000000000001 in ?? () #7 0x00007fffffffddbb in ?? () #8 0x0000000000000000 in ?? ()
Interestingly, this issue appears on a very old v2015.04 U-boot, but not on u-boot/master (even if the fix applies cleanly to u-boot/master). With the patch applied, my ancient u-boot starts to work properly:
$ ./u-boot
U-Boot 2015.04-00280-g5755c9e48b83 (May 23 2018 - 20:53:31)
DRAM: 128 MiB Using default environment
In: serial Out: lcd Err: lcd =>
Signed-off-by: Eugeniu Rosca erosca@de.adit-jv.com --- common/dlmalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/common/dlmalloc.c b/common/dlmalloc.c index b395eefbf862..6012f9f162c0 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -1524,7 +1524,7 @@ void fREe(mem) Void_t* mem;
#if CONFIG_VAL(SYS_MALLOC_F_LEN) /* free() is a no-op - all the memory will be freed on relocation */ - if (!(gd->flags & GD_FLG_FULL_MALLOC_INIT)) + if (gd && !(gd->flags & GD_FLG_FULL_MALLOC_INIT)) return; #endif