I discovered that the XLinkLog.h header redefines the critical system macro __attribute__.
The rule is...don't use, change, or redefine things (e.g. macros) with double underscores. Period no exceptions.
https://devblogs.microsoft.com/oldnewthing/20230109-00/?p=107685
XLink is working around this issue by careful ordering of header includes. Not a good solution. One header that is broken by this issue is libusb.h. Other code/headers may be affected silently.
Setup
Repro
- Setup a Windows machine to compile with mingw
- Create any .cpp file in the XLink project, e.g.
src\pc\protocols\myfile.cpp
- Edit your cpp file to have the following
#define MVLOG_UNIT_NAME xLinkUsb
#ifdef XLINK_LIBUSB_LOCAL
#include <libusb.h>
#else
#include <libusb-1.0/libusb.h>
#endif
#include "XLink/XLinkLog.h"
int myvar = 1;
- config, build
Your build should be successful
Now...change the order so that your file has this code...
#define MVLOG_UNIT_NAME xLinkUsb
#include "XLink/XLinkLog.h"
#ifdef XLINK_LIBUSB_LOCAL
#include <libusb.h>
#else
#include <libusb-1.0/libusb.h>
#endif
int myvar = 1;
Result
uncountable number of errors, deep within the system headers, usually related to intrinsics. For example...
[build] C:/Users/WDAGUtilityAccount/Desktop/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/mmintrin.h: In function '__m64 _mm_cvtsi32_si64(int)':
[build] C:/Users/WDAGUtilityAccount/Desktop/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/mmintrin.h:79:54: error: cannot convert a vector of type '__vector(2) int' to type '__m64' {aka 'int'} which has different size
[build] 79 | return (__m64) __builtin_ia32_vec_init_v2si (__i, 0);
[build] | ^
[build] C:/Users/WDAGUtilityAccount/Desktop/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/mmintrin.h: In function 'int _mm_cvtsi64_si32(__m64)':
[build] C:/Users/WDAGUtilityAccount/Desktop/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/mmintrin.h:122:39: error: cannot convert '__m64' {aka 'int'} to '__vector(2) int'
[build] 122 | return __builtin_ia32_vec_ext_v2si ((__v2si)__i, 0);
[build] | ^~~~~~~~~~~
[build] | |
[build] | __m64 {aka int}
[build] <built-in>: note: initializing argument 1 of 'int __builtin_ia32_vec_ext_v2si(__vector(2) int, int)'
[build] C:/Users/WDAGUtilityAccount/Desktop/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/mmintrin.h: In function '__m64 _mm_packs_pi16(__m64, __m64)':
[build] C:/Users/WDAGUtilityAccount/Desktop/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/mmintrin.h:161:43: error: cannot convert '__v4hi' {aka 'short int'} to '__vector(4) short int'
[build] 161 | return (__m64) __builtin_ia32_packsswb ((__v4hi)__m1, (__v4hi)__m2);
[build] | ^~~~~~~~~~~~
[build] | |
[build] | __v4hi {aka short int}
[build] <built-in>: note: initializing argument 1 of '__vector(8) char __builtin_ia32_packsswb(__vector(4) short int, __vector(4) short int)'
Notes
The bug is in include\XLink\XLinkLog.h. It redefines the system macro __attribute__. That is forbidden. And causes chaos like libusb header failures and potentially silent failures elsewhere. For example, in usb_host.cpp 4 local headers and 5+ system headers will no longer have a functioning __attribute__ macro.
|
#if (defined (WINNT) || defined(_WIN32) || defined(_WIN64) ) |
|
#define __attribute__(x) |
|
#define FUNCATTR_WEAK static |
|
#else |
|
#define FUNCATTR_WEAK |
|
#endif |
I discovered that the
XLinkLog.hheader redefines the critical system macro__attribute__.The rule is...don't use, change, or redefine things (e.g. macros) with double underscores. Period no exceptions.
https://devblogs.microsoft.com/oldnewthing/20230109-00/?p=107685
XLink is working around this issue by careful ordering of header includes. Not a good solution. One header that is broken by this issue is
libusb.h. Other code/headers may be affected silently.Setup
Repro
src\pc\protocols\myfile.cppYour build should be successful
Now...change the order so that your file has this code...
Result
uncountable number of errors, deep within the system headers, usually related to intrinsics. For example...
Notes
The bug is in
include\XLink\XLinkLog.h. It redefines the system macro__attribute__. That is forbidden. And causes chaos like libusb header failures and potentially silent failures elsewhere. For example, inusb_host.cpp4 local headers and 5+ system headers will no longer have a functioning__attribute__macro.XLink/include/XLink/XLinkLog.h
Lines 48 to 53 in d209b7e