error: function declared 'ms_abi' here was previously declared without calling convention (clang)

error: function declared 'ms_abi' here was previously declared without calling convention (clang)

当我尝试编译包含另一个 C header 的 C 代码时,出现此错误:

x86_64-uefi/../../libk/string.h:9:10: error: function declared 'ms_abi' here was
      previously declared without calling convention
KABI int memcmp(const void *d1, const void *d2, uint64_t len);
         ^
x86_64-uefi/../../libk/string.h:9:10: note: previous declaration is here

编译器为clang,涉及文件如下:
memcmp.c

#include "../string.h"

KABI int memcmp(const void *d1, const void *d2, uint64_t len) {
    const uint8_t *d1_ = d1, *d2_ = d2;
    for(uint64_t i = 0; i < len; i += 1, d1_++, d2_++){
        if(*d1_ != *d2_) return *d1_ < *d2_ ? -1 : 1;
    }
    return 0;
}

string.h

#pragma once

#include "systemapi.h"
#include "typedefs.h"

KABI int memcmp(const void *d1, const void *d2, uint64_t len);

systemapi.h(typedef 仅定义 uintx_t 类型)

#pragma once

#define KABI __attribute__((ms_abi))

另一个 header,其中包括 string.hlibk.h

#pragma once

#include "string.h"
#include "systemapi.h"
#include "typedefs.h"

而包含lib.h的文件在编译时报错,main.c(但所有文件在链接lib.h时都报错)

KABI void arch_main(void)
{
     // The function does not uses memcmp, just uses the KABI part of lib.h
     // Calling the whole lib.h is a convention 

}

编译器标志:-I/usr/include/efi -I/usr/include/efi/x86_64 -I/usr/include/efi/protocol -fno-stack-protector -fpic -fshort-wchar -mno-red-zone -DHAVE_USE_MS_ABI -c main.c -o main.o

如果没有构建环境,有根据的猜测是您正在重新定义具有与 ms_abi 函数属性不兼容的原型的内置函数。如果您使用 -ffreestanding 进行编译并提供您自己的函数,例如 memcpymemset 等,您应该考虑使用 -fno-builtin 选项进行编译,这样 CLANG/GCC 就不会'使用其内置形式的功能可能会与您自己的冲突。