Skip to content

Fix compiler error: pass -mpopcnt when using clang / llvm and targeting x86_64 #107939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

TCROC
Copy link
Contributor

@TCROC TCROC commented Jun 24, 2025

Introduced by PR: #59595

The error occurs when compiling with llvm on linux. At the very least, with the llvm compiler bundled with zig that we use.

In file included from thirdparty/embree/kernels/bvh/bvh_intersector_hybrid4_bvh4.cpp:4:
In file included from thirdparty/embree/kernels/bvh/bvh_intersector_hybrid.cpp:4:
In file included from thirdparty/embree/kernels/bvh/bvh_intersector_hybrid.h:6:
In file included from thirdparty/embree/kernels/bvh/bvh.h:7:
In file included from thirdparty/embree/kernels/bvh/bvh_node_aabb.h:6:
In file included from thirdparty/embree/kernels/bvh/bvh_node_base.h:6:
In file included from thirdparty/embree/kernels/bvh/bvh_node_ref.h:6:
In file included from thirdparty/embree/kernels/bvh/../common/default.h:8:
In file included from thirdparty/embree/kernels/bvh/../common/../../common/sys/thread.h:7:
In file included from thirdparty/embree/kernels/bvh/../common/../../common/sys/mutex.h:7:
thirdparty/embree/kernels/bvh/../common/../../common/sys/intrinsics.h:489:12: error: always_inline function '_mm_popcnt_u64' requires target feature 'popcnt', but would be inlined into function 'popcnt' that is compiled without support for 'popcnt'
  489 |     return _mm_popcnt_u64(in);
      |            ^
1 error generated.l.cpp
scons: *** [bin/obj/thirdparty/embree/kernels/bvh/steambvh_intersector_hybrid4_bvh4.linuxbsd.editor.double.x86_64.llvm.steam.o] Error 1
scons: building terminated because of errors.
INFO: Time elapsed: 00:02:22.99

The fix is to pass the -mpopcnt flag to the compiler so that the function _mm_popcnt_u64 supports always_inline.

Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally, it works as expected (although I can build Godot fine with Clang without that PR on Fedora 42).

This makes sense to do as POPCNT is not mandated by SSE 4.2, but all CPUs that support SSE 4.2 also support POPCNT.

@akien-mga akien-mga changed the title Fix compiler error: pass -mpopcnt when using clang / llvm and targeting x86_64 Fix compiler error: pass -mpopcnt when using clang / llvm and targeting x86_64 Jun 24, 2025
@Repiteo Repiteo merged commit bd548fa into godotengine:master Jun 24, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Jun 24, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants