You don't replace memcpy unless you do it right. The difference between systems with a bad or good memcpy is abysmal.
> 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#cmdoptio...
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)
so does gcc, it's pretty much a requirement of the C standard. https://gcc.godbolt.org/z/aaE5hn
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.
(Or with the Annex K variants -- memcpy_s(), memmove_s() -- if that floats your boat, and as this is Microsoft it surely does.)
I don’t think it’s an issue of whether it was rejected on principle, or because of its origin, I think that there just wasn’t enough interest in it. My feeling is that Annex K is not as useful without the right set of code review practices and static analysis tools. Many of the secure variants just take an extra size parameter—you would need some kind of assurance that the extra size parameter is somehow correct; without this assurance, the Annex K functions aren’t very useful. There’s not a great way to get that assurance without static analysis tools, as far as I know, because there are tons of unsafe ways to use the Annex K functions, like this:
// Don’t do this.
err = memcpy_s(dest, n, src, n);
If you’re just duplicating the “count” argument and pasting it in “destsz”, it will work but it won’t catch any of the errors that memcpy_s is designed to catch.0. http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1967.htm
That's exactly what annex k does. Detection of a runtime-constraint violation results in a call to a constraint handler; which handler can abort the process if you want it to.