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...

So let's implement memset() using the base_memset() we already have in
libc/string/memset.c.

Fixes #913.

Signed-off-by: Nadav Har'El <n...@scylladb.com>
---
 fastlz/lzloader.cc | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/fastlz/lzloader.cc b/fastlz/lzloader.cc
index 5f95e41..f82566e 100644
--- a/fastlz/lzloader.cc
+++ b/fastlz/lzloader.cc
@@ -15,11 +15,16 @@ extern char _binary_loader_stripped_elf_lz_start;
 extern char _binary_loader_stripped_elf_lz_end;
 extern char _binary_loader_stripped_elf_lz_size;
 
-// std libraries used by fastlz.
-extern "C" void *memset(void *s, int c, size_t n)
-{
-    return __builtin_memset(s, c, n);
-}
+// Some older versions of gcc optimize code in fastlz by calling
+// memset(), so we need to implement a memset() function. Because it's
+// not needed on recent compilers, let's stick to the basic implementation
+// we have in libc/string/memset.c. To avoid compiling this source file
+// a second time (the loader needs different compile parameters), we #include
+// it here instead.
+extern "C" void *memset(void *s, int c, size_t n);
+#define memset_base memset
+#include "libc/string/memset.c"
+#undef memset_base
 
 extern "C" void uncompress_loader()
 {
-- 
2.9.5

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to