apsun / loliOS

Lightweight & operational Linux-inspired OS.
33 stars 1 forks source link

Fix clang infinite recursion in memcpy/memset #25

Closed apsun closed 2 years ago

apsun commented 2 years ago

Building with clang and optimizations disabled causes infinite recursion. Apparently clang synthesizes a call to memset... inside of memset. -fno-builtin does not help (IIRC all it does is disable the builtin aliases for e.g. memcpy -> __builtin_memcpy, not prevent the builtins from being used).

Potential solutions, off the top of my head:

apsun commented 2 years ago

Seems clang generates a "mem* instruction" (https://github.com/llvm/llvm-project/blob/f3e9047249d05ff2fb79076dbfbbdad4a35fbc63/llvm/include/llvm/IR/IntrinsicInst.h#L874) as part of its optimization passes.

apsun commented 2 years ago

FWIW, rep movsb is still fast enough to watch video (since we're bottlenecked on copying packets from ne2k). So we could go back to doing that if there's no way to disable this behavior.

apsun commented 2 years ago

Apparently clang only generated this because I wrote word_t word = {0}; in memset... Initializing the bytes one at a time avoids the memset recursion. Fixed with 3efea79e81c016834f6822210c1752cf81661398