Is that possible to use standard libc features in GNU-EFI with Visual Studio?

546 Views Asked by At

I am using gnu-efi as Visual Studio 2019 project. My UEFI program works as expected on real hardware. Next step, I need C features like "pow(...);". Naturally, when working with efi all of these features are disabled. When I directly include <math.h> I get unresolved external ... error. If I start a unrestricted project that builds successfully.

I asked it and someone advised met to downolad EDK2 libc but I do not know how to use it in my project or if that works with GNU-EFI. I have no idea what to do in order to use C features. I will very glad if anyone tells me what to do.

2

There are 2 best solutions below

0
On

One way not mentioned here is the "fake it until you make it" strategy.

One cheap and dirty way with math.h is to take advantage of the knowledge that the compiler likely has intrinsics for most of those functions anyway and just wrap the __builtin functions.

double __cdecl pow(double in, double p) {
    return __builtin_pow(in, p);
}

This also may work with memmov, memcpy, memcmp and a few others. malloc can be created by wrapping BootServices->AllocatePool. You can create an include directory of your own, point the compiler at it and just fill it with touched dummy headers as the compiler asks for them. Surprisingly you can get away with a lot by employing lies and subterfuge.

Of course you'll never get a full libc but with a careful choice of libraries you can still port a lot of stuff without much effort. I was able to get a bunch of C++ code working from EASTL and Anti-grain geometry using the fake it strategy

0
On

Here is the libc that is ported to UEFI.