We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5428 - A lot of 'undeclared identifier' at 'mmintrin.h' (from immintrin.h) at SDL_cpuinfo.h:86
Summary: A lot of 'undeclared identifier' at 'mmintrin.h' (from immintrin.h) at SDL_cp...
Status: RESOLVED INVALID
Alias: None
Product: SDL
Classification: Unclassified
Component: build (show other bugs)
Version: 2.0.14
Hardware: ARM macOS 10.15
: P2 trivial
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-12-30 23:20 UTC by Vitaly Novichkov
Modified: 2020-12-31 14:06 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vitaly Novichkov 2020-12-30 23:20:56 UTC
I tring to cross-compile the ARM64 build of my project, using next parameters:

I use the state of the 2.0.14 release.

```
cmake -G "Ninja" -DCMAKE_BUILD_TYPE=MinSizeRel -DCMAKE_OSX_ARCHITECTURES="arm64" ..
```

And I getting the big list of errors while using SDL_cpuinfo.h at my program. Probably because x86-specific SIMD calls was been used from the ARM-targeted build.


The log of errors:

```
FAILED: CMakeFiles/thextech.dir/src/game_main.cpp.o 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DGIT_BRANCH=\"master\" -DGIT_VERSION=\"e5fc17b\" -DTHEXTECH_VERSION_1=1 -DTHEXTECH_VERSION_2=3 -DTHEXTECH_VERSION_3=3 -DTHEXTECH_VERSION_4=1 -DTHEXTECH_VERSION_REL="" -I../lib/DirManager -I../lib/FileMapper -I../lib/fmt -I../lib/IniProcessor -I../lib/Utils/.. -I../src -I../lib -Ioutput/include -Ioutput/include/SDL2 -fvisibility-inlines-hidden -Os -DNDEBUG -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk -mmacosx-version-min=10.11 -std=gnu++11 -MD -MT CMakeFiles/thextech.dir/src/game_main.cpp.o -MF CMakeFiles/thextech.dir/src/game_main.cpp.o.d -o CMakeFiles/thextech.dir/src/game_main.cpp.o -c ../src/game_main.cpp
In file included from ../src/game_main.cpp:32:
In file included from ../src/globals.h:32:
In file included from output/include/SDL2/SDL.h:38:
In file included from output/include/SDL2/SDL_cpuinfo.h:86:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include/immintrin.h:14:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include/mmintrin.h:33:5: error: use of undeclared identifier '__builtin_ia32_emms'; did you mean '__builtin_isless'?
    __builtin_ia32_emms();
    ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/math.h:647:12: note: '__builtin_isless' declared here
    return isless(__lcpp_x, __lcpp_y);
           ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/usr/include/math.h:545:22: note: expanded from macro 'isless'
#define isless(x, y) __builtin_isless((x),(y))
                     ^
In file included from ../src/game_main.cpp:32:
In file included from ../src/globals.h:32:
In file included from output/include/SDL2/SDL.h:38:
In file included from output/include/SDL2/SDL_cpuinfo.h:86:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include/immintrin.h:14:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include/mmintrin.h:33:25: error: too few arguments to function call, expected 2, have 0
    __builtin_ia32_emms();
                        ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include/mmintrin.h:50:19: error: use of undeclared identifier '__builtin_ia32_vec_init_v2si'
    return (__m64)__builtin_ia32_vec_init_v2si(__i, 0);
                  ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include/mmintrin.h:67:12: error: use of undeclared identifier '__builtin_ia32_vec_ext_v2si'
    return __builtin_ia32_vec_ext_v2si((__v2si)__m, 0);
           ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include/mmintrin.h:129:19: error: use of undeclared identifier '__builtin_ia32_packsswb'
    return (__m64)__builtin_ia32_packsswb((__v4hi)__m1, (__v4hi)__m2);
                  ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include/mmintrin.h:159:19: error: use of undeclared identifier '__builtin_ia32_packssdw'
    return (__m64)__builtin_ia32_packssdw((__v2si)__m1, (__v2si)__m2);
                  ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include/mmintrin.h:189:19: error: use of undeclared identifier '__builtin_ia32_packuswb'
    return (__m64)__builtin_ia32_packuswb((__v4hi)__m1, (__v4hi)__m2);
                  ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include/mmintrin.h:216:19: error: use of undeclared identifier '__builtin_ia32_punpckhbw'
    return (__m64)__builtin_ia32_punpckhbw((__v8qi)__m1, (__v8qi)__m2);
                  ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include/mmintrin.h:239:19: error: use of undeclared identifier '__builtin_ia32_punpckhwd'
    return (__m64)__builtin_ia32_punpckhwd((__v4hi)__m1, (__v4hi)__m2);
                  ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include/mmintrin.h:260:19: error: use of undeclared identifier '__builtin_ia32_punpckhdq'
    return (__m64)__builtin_ia32_punpckhdq((__v2si)__m1, (__v2si)__m2);
                  ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include/mmintrin.h:287:19: error: use of undeclared identifier '__builtin_ia32_punpcklbw'
    return (__m64)__builtin_ia32_punpcklbw((__v8qi)__m1, (__v8qi)__m2);
                  ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include/mmintrin.h:310:19: error: use of undeclared identifier '__builtin_ia32_punpcklwd'
    return (__m64)__builtin_ia32_punpcklwd((__v4hi)__m1, (__v4hi)__m2);
                  ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include/mmintrin.h:331:19: error: use of undeclared identifier '__builtin_ia32_punpckldq'
    return (__m64)__builtin_ia32_punpckldq((__v2si)__m1, (__v2si)__m2);
                  ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include/mmintrin.h:352:19: error: use of undeclared identifier '__builtin_ia32_paddb'; did you mean '__builtin_arm_addg'?
    return (__m64)__builtin_ia32_paddb((__v8qi)__m1, (__v8qi)__m2);
                  ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include/mmintrin.h:352:19: note: '__builtin_arm_addg' declared here
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include/mmintrin.h:352:19: error: first argument of MTE builtin function must be a pointer ('__v8qi' (vector of 8 'char' values) invalid)
    return (__m64)__builtin_ia32_paddb((__v8qi)__m1, (__v8qi)__m2);
                  ^                    ~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include/mmintrin.h:373:19: error: use of undeclared identifier '__builtin_ia32_paddw'; did you mean '__builtin_arm_addg'?
    return (__m64)__builtin_ia32_paddw((__v4hi)__m1, (__v4hi)__m2);
                  ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include/mmintrin.h:352:19: note: '__builtin_arm_addg' declared here
    return (__m64)__builtin_ia32_paddb((__v8qi)__m1, (__v8qi)__m2);
                  ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include/mmintrin.h:373:19: error: first argument of MTE builtin function must be a pointer ('__v4hi' (vector of 4 'short' values) invalid)
    return (__m64)__builtin_ia32_paddw((__v4hi)__m1, (__v4hi)__m2);
                  ^                    ~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include/mmintrin.h:394:19: error: use of undeclared identifier '__builtin_ia32_paddd'; did you mean '__builtin_arm_addg'?
    return (__m64)__builtin_ia32_paddd((__v2si)__m1, (__v2si)__m2);
                  ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include/mmintrin.h:352:19: note: '__builtin_arm_addg' declared here
    return (__m64)__builtin_ia32_paddb((__v8qi)__m1, (__v8qi)__m2);
                  ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include/mmintrin.h:394:19: error: first argument of MTE builtin function must be a pointer ('__v2si' (vector of 2 'int' values) invalid)
    return (__m64)__builtin_ia32_paddd((__v2si)__m1, (__v2si)__m2);
                  ^                    ~~~~~~~~~~~~
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
ninja: build stopped: subcommand failed.
```
Comment 1 Vitaly Novichkov 2020-12-30 23:27:50 UTC
I forgot to say, I do use Xcode 12.3 and CMake 3.18 to produce the build. ARM support was been added since Xcode 12. Older Xcode doesn't support ARM targets.
Comment 2 Vitaly Novichkov 2020-12-31 00:32:23 UTC
Okay, I think, I know why this happens... It's probably because I had SDL2 at CMake external project side being built for x86_64 instead of ARM, I actually should to bypass the missing CMake argument to resolve this...
Comment 3 Ozkan Sezer 2020-12-31 00:45:27 UTC
I believe you are using a generated SDL_config.h, either by cmake
or by configure, correct?  If that is the case, using such config
file for another arch, or for a multi-arch case where the arch'es
are not compatible like arm64 and x86_64, can cause problems.

If you are using a generated SDL_config.h, for which arch was it
generated? I guess it was x86_64?

One solution would be guarding HAVE_IMMINTRIN_H define by x86_64
or i386 checks. Something like the following maybe?

diff --git a/include/SDL_config.h.cmake b/include/SDL_config.h.cmake
--- a/include/SDL_config.h.cmake
+++ b/include/SDL_config.h.cmake
@@ -220,7 +220,9 @@
 #cmakedefine HAVE_INOTIFY_INIT 1
 #cmakedefine HAVE_INOTIFY_INIT1 1
 #cmakedefine HAVE_INOTIFY 1
+#if defined(__i386__) || defined(__x86_64__)
 #cmakedefine HAVE_IMMINTRIN_H 1
+#endif
 #cmakedefine HAVE_LIBUDEV_H 1
 #cmakedefine HAVE_LIBSAMPLERATE_H 1
 
diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in
--- a/include/SDL_config.h.in
+++ b/include/SDL_config.h.in
@@ -221,7 +221,9 @@
 #undef HAVE_INOTIFY_INIT1
 #undef HAVE_INOTIFY
 #undef HAVE_IBUS_IBUS_H
+#if defined(__i386__) || defined(__x86_64__)
 #undef HAVE_IMMINTRIN_H
+#endif
 #undef HAVE_LIBUDEV_H
 #undef HAVE_LIBSAMPLERATE_H
Comment 4 Vitaly Novichkov 2020-12-31 00:58:10 UTC
The reason of failure most probably because of missing bypassing of CMAKE_OSX_ARCHITECTURES flag into child external projects. I did that just now at all my dependencies, and checking the result now...
Comment 5 Vitaly Novichkov 2020-12-31 14:05:32 UTC
Okay, I confirm that it's just pure mistake of my build chain that actually did build of SDL2 for x86_64 even the ARM requested for the main project. I fixed that mistake, and the project builds for ARM successfully.