undefined reference to `_memset64' when creating a struct array under DMD with -betterC

243 Views Asked by At

I'm quite new to D, and am trying to create an array of structs with -betterC active, but keep running into this error:

/home/xander/Documents/lithium/kernel/kernel.main.d:17: undefined reference to `_memset64'

when I try to link it. Here is the offending line:

idt_entry[256] idtr;

I did not find this error with gdc, but require access to inline assembly for my project, so switching back is not an option.

Repo link: Omega0x013/lithium

2

There are 2 best solutions below

0
raoof On

I think defining the function will solve your problem. source from here

extern (C) long *_memset64(long *p, long value, size_t count)
{
    long *pstart = p;
    long *ptop;

    for (ptop = &p[count]; p < ptop; p++)
        *p = value;
    return pstart;
}
0
Rottenheimer2 On

D compilers, like a lot of compilers (GCC and clang come to mind), will detect some patterns and usages and generate code calling functions from the standard library that reflect that pattern and can do it potentially more efficiently, given that standard library functions are often greatly optimized and in occasions using niche machine-specific hardware extensions, like AVX-accelerated functions.

In your case, since this is freestanding code (a fact that you did not conceal really well given that this is an x86 IDT structure :D), the standard library is not available, and you can't link to it, but this is something the compiler does not know, so it will still generate a call to the function, thus, it's your job as the programmer to supply it!

This answer provides the drop-in function to implement, but I think some reasoning was due, it's never good to copy code without understanding its purpose!