5 ms·
Fun story. I once had a program hang (running on EFI) on a fairly benal line of C code. Turns out Clang injects memcpy into your code even if you don't call it
by trissylegs 6y ago
Fun story. I once had a program hang (running on EFI) on a fairly benal line of C code.
Turns out Clang injects memcpy into your code even if you don't call it. I hadn't defined memcpy anywhere so it just hung.
- moonchild 6y agoThis is documented[0]: > Note that it is assumed that a freestanding environment will additionally provide memcpy, memmove, memset, and memcmp implementations, as these are needed for efficient codegen for many programs. GCC has effectively the same stipulation[1]: > GCC requires the freestanding environment provide memcpy, memmove, memset and memcmp. The main thing I'm confused about is why you didn't get a linker error. 0. https://clang.llvm.org/docs/CommandGuide/clang.html#cmdoption-ffreestanding https://clang.llvm.org/docs/CommandGuide/clang.html#cmdoptio... 1. https://gcc.gnu.org/onlinedocs/gcc/Standards.html https://gcc.gnu.org/onlinedocs/gcc/Standards.html
- trissylegs 6y ago> The main thing I'm confused about is why you didn't get a linker error. EFI isn't your usual Freestanding env. Your output is a dynamically linked PE2 (Windows) executable. The linker had spots for memcpy and others to be linked in Dynamically. But they were not. Whatever was there caused a hang in TianoCore UEFI. (Which would eventually reset due to the watchdog timer)
- jcelerier 6y ago> Turns out Clang injects memcpy into your code even if you don't call it. so does gcc, it's pretty much a requirement of the C standard. https://gcc.godbolt.org/z/aaE5hn https://gcc.godbolt.org/z/aaE5hn
- matheusmoreira 6y ago> it's pretty much a requirement of the C standard Why would the C standard mandate the presence of standard library functions in a freestanding environment? I always assumed compilers emitting calls to mem* functions were doing it because it was the easy solution just like linking to libgcc.
- deleted 6y ago[deleted]