I am building an EFI driver and therefore cannot use stdlib, so no memset. I am also running after ExitBootServices, so no edk2 CopyMem. This is my function:
void Set_Memory(VOID* Dest, UINTN Len, CHAR8 Val)
{
for (int i = 0; i < Len; ++i)
{
((UINT8*)Dest)[i] = Val;
}
}
When compiling with optimizations, I get LNK2001 unresolved external symbol memset. Presumably the MSVC compiler is replacing my call to Set_Memory with a call to memset. I also cannot define my own memset, because I get the error C2169 'memset': intrinsic function, cannot be defined. How can I prevent this without losing other optimizations?
Use the #pragma optimize("", off) to turn off optimizations for certain functions.
For example:
#pragma optimize("", off)
void Set_Memory(VOID* Dest, UINTN Len, CHAR8 Val)
{
for (int i = 0; i < Len; ++i)
{
((UINT8*)Dest)[i] = Val;
}
}
#pragma optimize("", on)
optimize pragma is documented here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With