x86/efi: enable MS ABI attribute on clang
PATCH 1/1 x86/efi: enable MS ABI attribute on clang
Or else the EFI service calls will use the wrong calling convention.
The __ms_abi__ attribute is available on all supported versions of clang.
---
Cc: Ian Jackson <[email protected]>
Without this a Xen built with clang won't be able to correctly use the EFI services, leading to weird messages from the firmware and crashes. The impact of this fix for GCC users is exactly 0, and will fix the build on clang.
The biggest fallout from this could be using the attribute on a compiler that doesn't support it, which would translate into a build failure, but the gitlab tests have shown no issues.
--- xen/include/asm-x86/x86_64/efibind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/include/asm-x86/x86_64/efibind.h +1 -1
@@ -172,7 +172,7 @@ typedef uint64_t UINTN;#ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options #ifdef _MSC_EXTENSIONS#define EFIAPI __cdecl // Force C calling convention for Microsoft C compiler -#elif __GNUC__ >4 || (__GNUC__ ==4 && __GNUC_MINOR__ >=4 ) +#elif __clang__ || __GNUC__ >4 || (__GNUC__ ==4 && __GNUC_MINOR__ >=4 )#define EFIAPI __attribute__((__ms_abi__)) // Force Microsoft ABI#else #define EFIAPI // Substitute expresion to force C calling convention
Signature · 1 line
2.29.2
Quoted 6 lines · Roger Pau Monne
Or else the EFI service calls will use the wrong calling convention.
The
__ms_abi__attribute is available on all supported versions of clang.Signed-off-by Roger Pau Monné <[email protected]>
Quoted 7 lines
---
Cc: Ian Jackson <[email protected]>Without this a Xen built with clang won't be able to correctly use the EFI services, leading to weird messages from the firmware and crashes. The impact of this fix for GCC users is exactly 0, and will fix the build on clang.
DYM "fix the compiled binary"?
The build on clang isn't broken atm, but it provably has the wrong ABI.
~Andrew
xen/include/asm-x86/x86_64/efibind.h typedef uint64_t UINTN; · line 178
Quoted 12 lines · Roger Pau Monne
xen/include/asm-x86/x86_64/efibind.h +1
-1@@ -172,7 +172,7 @@ typedef uint64_t UINTN;#ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options #ifdef _MSC_EXTENSIONS#define EFIAPI __cdecl // Force C calling convention for Microsoft C compiler -#elif __GNUC__ >4 || (__GNUC__ ==4 && __GNUC_MINOR__ >=4 ) +#elif __clang__ || __GNUC__ >4 || (__GNUC__ ==4 && __GNUC_MINOR__ >=4 )#define EFIAPI __attribute__((__ms_abi__)) // Force Microsoft ABI#else #define EFIAPI // Substitute expresion to force C calling convention
So the problem is that some capable Clang versions set too low a __GNUC_MINOR__ (I'm observing 2 alongside __GNUC__ being 4 on Clang5). The way the description and change are written made me rather imply __GNUC__ to not be available at all, which I then thought can't be the case because iirc we use it elsewhere.
Jan
Quoted 12 lines · Jan Beulich
Quoted 11 lines · Roger Pau Monne
xen/include/asm-x86/x86_64/efibind.h +1
-1@@ -172,7 +172,7 @@ typedef uint64_t UINTN;#ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options #ifdef _MSC_EXTENSIONS#define EFIAPI __cdecl // Force C calling convention for Microsoft C compiler -#elif __GNUC__ >4 || (__GNUC__ ==4 && __GNUC_MINOR__ >=4 ) +#elif __clang__ || __GNUC__ >4 || (__GNUC__ ==4 && __GNUC_MINOR__ >=4 )#define EFIAPI __attribute__((__ms_abi__)) // Force Microsoft ABI#else #define EFIAPI // Substitute expresion to force C calling convention
Quoted 8 lines
Quoted 1 line
So the problem is that some capable Clang versions set too low a
__GNUC_MINOR__(I'm observing 2 alongside__GNUC__being 4 on Clang5). The way the description and change are written made me rather imply__GNUC__to not be available at all, which I then thought can't be the case because iirc we use it elsewhere.
Yes, I also see 4.2 on Clang 11.
Do you want me to expand the description by adding:
"Add a specific Clang check because the GCC version reported by Clang is below the required 4.4 to use the __ms_abi__ attribute."
Thanks, Roger.
Quoted 22 lines · Roger Pau Monné
Quoted 12 lines · Jan Beulich
Quoted 11 lines · Roger Pau Monne
xen/include/asm-x86/x86_64/efibind.h +1
-1@@ -172,7 +172,7 @@ typedef uint64_t UINTN;#ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options #ifdef _MSC_EXTENSIONS#define EFIAPI __cdecl // Force C calling convention for Microsoft C compiler -#elif __GNUC__ >4 || (__GNUC__ ==4 && __GNUC_MINOR__ >=4 ) +#elif __clang__ || __GNUC__ >4 || (__GNUC__ ==4 && __GNUC_MINOR__ >=4 )#define EFIAPI __attribute__((__ms_abi__)) // Force Microsoft ABI#else #define EFIAPI // Substitute expresion to force C calling convention Quoted 8 lines
Quoted 1 line
So the problem is that some capable Clang versions set too low a
__GNUC_MINOR__(I'm observing 2 alongside__GNUC__being 4 on Clang5). The way the description and change are written made me rather imply__GNUC__to not be available at all, which I then thought can't be the case because iirc we use it elsewhere.
Quoted 6 lines
Yes, I also see 4.2 on Clang 11.
Do you want me to expand the description by adding:
"Add a specific Clang check because the GCC version reported by Clang is below the required 4.4 to use the
__ms_abi__attribute."
I guess adding this is easy enough when done while committing. Thanks for the addition.
Jan
Roger Pau Monne writes ("[PATCH for-4.15] x86/efi: enable MS ABI attribute on clang"):
Quoted 5 lines
Or else the EFI service calls will use the wrong calling convention.
The
__ms_abi__attribute is available on all supported versions of clang.
Quoted 8 lines
Signed-off-by Roger Pau Monné <[email protected]>---
Cc: Ian Jackson <[email protected]>Without this a Xen built with clang won't be able to correctly use the EFI services, leading to weird messages from the firmware and crashes. The impact of this fix for GCC users is exactly 0, and will fix the build on clang.
Quoted 3 lines
The biggest fallout from this could be using the attribute on a compiler that doesn't support it, which would translate into a build failure, but the gitlab tests have shown no issues.
Thanks for the thorough attention to the release question in your mails. You're making my work very easy :-).
Ian.