I am looking at this header file in linux kernel: https://elixir.bootlin.com/linux/v4.14/source/arch/x86/boot/string.h
#ifndef BOOT_STRING_H
#define BOOT_STRING_H
/* Undef any of these macros coming from string_32.h. */
#undef memcpy
#undef memset
#undef memcmp
void *memcpy(void *dst, const void *src, size_t len);
void *memset(void *dst, int c, size_t len);
int memcmp(const void *s1, const void *s2, size_t len);
#define memcpy(d,s,l) __builtin_memcpy(d,s,l)
#define memset(d,c,l) __builtin_memset(d,c,l)
#define memcmp __builtin_memcmp
...
#endif /* BOOT_STRING_H */
I can't figure out what does the #undef + function declaration + macro define on memcpy, memset and memcmp do. For example, it first declares a function memcpy and then defines a macro memcpy after that. I am not sure what's the purpose of this. I find that this function is defined here: https://elixir.bootlin.com/linux/v4.14/source/arch/x86/boot/copy.S#L20. If somewhere in the code uses memcpy (for example here: https://elixir.bootlin.com/linux/v4.14/source/arch/x86/boot/main.c#L40) uses memcpy what does it use? The function defined in copy.S or the __builtin_memcpy?