From 33b799b94c38fd2d3961b465a8114e384573a6d6 Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Thu, 22 Oct 2020 22:59:14 +0100 Subject: [PATCH] ujail: elf: work around GCC bug on MIPS64 Work-around gcc bug which leads to segfault parsing ELF on MIPS64. The codepath added in this commit gets triggered when parsing /lib/ld-musl-mips64-sf.so.1 (a symlink to /lib/libc.so) on MIPS64 (built with gcc-8.4.0 and musl 1.1.24) in qemu-system-mips64 on the malta/be64 target. Include work-around outputting an error message, but preventing segfault when building for MIPS64. Tested-by: Roman Kuzmitskii [tested on edgerouter 4 and edgerouter lite] Signed-off-by: Daniel Golle --- jail/elf.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/jail/elf.c b/jail/elf.c index 7c6076a..ede85a6 100644 --- a/jail/elf.c +++ b/jail/elf.c @@ -235,7 +235,11 @@ int elf_load_deps(const char *path, const char *map) unsigned int dyn_offset, dyn_size; unsigned int load_offset, load_vaddr; unsigned int interp_offset; +#if defined(__mips__) && (__mips == 64) + static int gcc_mips64_bug_work_around; + gcc_mips64_bug_work_around = 1; +#endif if (elf_find_section(map, PT_LOAD, &load_offset, NULL, &load_vaddr)) { ERROR("failed to load the .load section from %s\n", path); return -1; @@ -252,6 +256,14 @@ int elf_load_deps(const char *path, const char *map) int clazz = map[EI_CLASS]; +#if defined(__mips__) && (__mips == 64) + if (gcc_mips64_bug_work_around != 1) { + ERROR("compiler bug: GCC for MIPS64 should be fixed!\n"); + return -1; + } + gcc_mips64_bug_work_around = 0; +#endif + if (clazz == ELFCLASS32) return elf32_scan_dynamic(map, dyn_offset, dyn_size, load_vaddr - load_offset); else if (clazz == ELFCLASS64) -- 2.30.2