From 637397dd2fbd08388e37388a7474d98af88b78af Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 19 Dec 2023 10:28:40 +0200 Subject: [PATCH] LibC: Make memcpy and memset not optimized GCC does some weird optimizations and breaks these functions --- libc/string.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libc/string.cpp b/libc/string.cpp index 44c088aafe..5f29280456 100644 --- a/libc/string.cpp +++ b/libc/string.cpp @@ -17,7 +17,8 @@ int memcmp(const void* s1, const void* s2, size_t n) return 0; } -void* memcpy(void* dstp, const void* srcp, size_t n) +__attribute__((optimize("-O0"))) +void* memcpy(void* __restrict__ dstp, const void* __restrict__ srcp, size_t n) { unsigned char* dst = static_cast(dstp); const unsigned char* src = static_cast(srcp); @@ -45,6 +46,7 @@ void* memmove(void* destp, const void* srcp, size_t n) return destp; } +__attribute__((optimize("-O0"))) void* memset(void* s, int c, size_t n) { unsigned char* p = static_cast(s);