简体   繁体   中英

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

when I try to compile C code that includes another C header I get this error:

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

The compiler is clang and the involved files are the following:
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 (typedefs just define the uintx_t types)

#pragma once

#define KABI __attribute__((ms_abi))

Another header that includes string.h , libk.h

#pragma once

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

And the file that includes lib.h and that reports the error when compiling, main.c (but all files report the error when linking with 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 

}

Flags of the compiler: -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

Without having your build environment, an educated guess would be that you are redefining the built in functions that have prototypes that are incompatible with the ms_abi function attribute. If you are compiling with -ffreestanding and supplying your own functions like memcpy , memset , etc., you should consider compiling with -fno-builtin option so that CLANG/GCC doesn't use its built in forms of the functions that may conflict with your own.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM