Skip to content

Commit f50218f

Browse files
committed
lzloader: fix memset() implementation
Some compilers apparently optimize code in fastlz/ to call memset(), so the uncompressing boot loader, fastlz/lzloader.cc, needs to implement this function. The current implementation called the "builtin" memset, which, if you look at the compilation result, actually calls memset() and results in endless recursion and a hanging boot... This started happening on Fedora 32 with Gcc 10, for example. So let's implement memset() using the base_memset() we already have in libc/string/memset.c. Fixes #1084. Signed-off-by: Nadav Har'El <[email protected]>
1 parent 8647177 commit f50218f

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

fastlz/lzloader.cc

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,16 @@ extern char _binary_loader_stripped_elf_lz_start;
2121
extern char _binary_loader_stripped_elf_lz_end;
2222
extern char _binary_loader_stripped_elf_lz_size;
2323

24-
// std libraries used by fastlz.
25-
extern "C" void *memset(void *s, int c, size_t n)
26-
{
27-
return __builtin_memset(s, c, n);
28-
}
24+
// The code in fastlz.cc does not call memset(), but some version of gcc
25+
// implement some assignments by calling memset(), so we need to implement
26+
// a memset() function. This is not performance-critical so let's stick to
27+
// the basic implementation we have in libc/string/memset.c. To avoid
28+
// compiling this source file a second time (the loader needs different
29+
// compile parameters), we #include it here instead.
30+
extern "C" void *memset(void *s, int c, size_t n);
31+
#define memset_base memset
32+
#include "libc/string/memset.c"
33+
#undef memset_base
2934

3035
extern "C" void uncompress_loader()
3136
{

0 commit comments

Comments
 (0)