Skip to content
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

Linux cross-compilation with Clang (use_llvm=yes) doesn't work out of the box #103251

Open
akien-mga opened this issue Feb 24, 2025 · 6 comments
Open

Comments

@akien-mga
Copy link
Member

akien-mga commented Feb 24, 2025

Tested versions

  • Reproducible in 4.4.rc (0e3dbba)
  • Should be reproducible in earlier versions, I don't think it was ever meant to work.

System information

Fedora 41, Clang 19.1.7

Issue description

Cross-compiling Godot on Linux for another Linux arch with Clang doesn't work out of the box. No --target or --sysroot arguments are passed, and no check if performed to confirm that the toolchain is properly setup.

This was initially noticed while trying to cross-compile for arm32 from x86_64, where some x86_64 code gets compiled in zstd:

scons platform=linuxbsd target=editor tests=false verbose=yes warnings=no progress=no module_mono_enabled=yes arch=arm32 use_llvm=yes lto=none

Fails with:

clang -o thirdparty/zstd/decompress/huf_decompress.linuxbsd.editor.arm32.llvm.o -c -std=gnu17 -ffp-contract=off -pipe -fno-color-diagnostics -O2 -w -DTOOLS_ENABLED -DDEBUG_ENABLED -DNDEBUG -DENGINE_UPDATE_CHECK_ENABLED -DNO_EDITOR_SPLASH -DSOWRAP_ENABLED -DTOUCH_ENABLED -DFONTCONFIG_ENABLED -DALSA_ENABLED -DALSAMIDI_ENABLED -DPULSEAUDIO_ENABLED -D_REENTRANT -DDBUS_ENABLED -DSPEECHD_ENABLED -DXKB_ENABLED -DJOYDEV_ENABLED -DUDEV_ENABLED -DLINUXBSD_ENABLED -DUNIX_ENABLED -D_FILE_OFFSET_BITS=64 -DX11_ENABLED -DLIBDECOR_ENABLED -DWAYLAND_ENABLED -DVULKAN_ENABLED -DRD_ENABLED -DGLES3_ENABLED -DCRASH_HANDLER_ENABLED -DMINIZIP_ENABLED -DBROTLI_ENABLED -DTHREADS_ENABLED -DCLIPPER2_ENABLED -DZSTD_STATIC_LINKING_ONLY -Ithirdparty/zstd -Ithirdparty/zstd/common -Ithirdparty/zlib -Ithirdparty/clipper2/include -Ithirdparty/brotli/include -Ithirdparty/linuxbsd_headers/libdecor-0 -Ithirdparty/linuxbsd_headers/wayland -Ithirdparty/linuxbsd_headers -Iplatform/linuxbsd -I. thirdparty/zstd/decompress/huf_decompress.c

...

clang++ -o bin/godot.linuxbsd.editor.arm32.llvm.mono -static-libgcc -static-libstdc++ -s -O2 platform/linuxbsd/godot_linuxbsd.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/crash_handler_linuxbsd.linuxbsd.editor
.arm32.llvm.o platform/linuxbsd/os_linuxbsd.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/joypad_linux.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/freedesktop_portal_desktop.linuxbsd.editor.arm32.llvm.o plat
form/linuxbsd/freedesktop_screensaver.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/xkbcommon-so_wrap.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/x11/display_server_x11.linuxbsd.editor.arm32.llvm.o platform/
linuxbsd/x11/key_mapping_x11.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/x11/dynwrappers/xlib-so_wrap.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/x11/dynwrappers/xcursor-so_wrap.linuxbsd.editor.arm32.llvm.
o platform/linuxbsd/x11/dynwrappers/xinerama-so_wrap.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/x11/dynwrappers/xinput2-so_wrap.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/x11/dynwrappers/xrandr-so_wrap.l
inuxbsd.editor.arm32.llvm.o platform/linuxbsd/x11/dynwrappers/xrender-so_wrap.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/x11/dynwrappers/xext-so_wrap.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/x11/render
ing_context_driver_vulkan_x11.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/x11/gl_manager_x11_egl.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/x11/gl_manager_x11.linuxbsd.editor.arm32.llvm.o platform/linuxbs
d/x11/detect_prime_x11.linuxbsd.editor.arm32.llvm.o thirdparty/glad/glx.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/wayland/protocol/wayland.gen.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/wayland/protocol
/viewporter.gen.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/wayland/protocol/fractional_scale.gen.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/wayland/protocol/xdg_shell.gen.linuxbsd.editor.arm32.llvm.o pla
tform/linuxbsd/wayland/protocol/xdg_system_bell.gen.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/wayland/protocol/xdg_foreign_v1.gen.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/wayland/protocol/xdg_foreign_
v2.gen.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/wayland/protocol/xdg_decoration.gen.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/wayland/protocol/xdg_activation.gen.linuxbsd.editor.arm32.llvm.o platform/
linuxbsd/wayland/protocol/relative_pointer.gen.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/wayland/protocol/pointer_constraints.gen.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/wayland/protocol/pointer_gest
ures.gen.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/wayland/protocol/primary_selection.gen.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/wayland/protocol/idle_inhibit.gen.linuxbsd.editor.arm32.llvm.o platfo
rm/linuxbsd/wayland/protocol/tablet.gen.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/wayland/protocol/text_input.gen.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/wayland/display_server_wayland.linuxbsd.edito
r.arm32.llvm.o platform/linuxbsd/wayland/wayland_thread.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/wayland/key_mapping_xkb.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/wayland/detect_prime_egl.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/wayland/dynwrappers/wayland-cursor-so_wrap.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/wayland/dynwrappers/wayland-client-core-so_wrap.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/wayland/dynwrappers/wayland-egl-core-so_wrap.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/wayland/dynwrappers/libdecor-so_wrap.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/wayland/rendering_context_driver_vulkan_wayland.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/wayland/egl_manager_wayland.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/wayland/egl_manager_wayland_gles.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/tts_linux.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/speechd-so_wrap.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/fontconfig-so_wrap.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/libudev-so_wrap.linuxbsd.editor.arm32.llvm.o platform/linuxbsd/dbus-so_wrap.linuxbsd.editor.arm32.llvm.o main/libmain.linuxbsd.editor.arm32.llvm.a modules/libmodules.linuxbsd.editor.arm32.llvm.a modules/libmodule_text_server_adv.linuxbsd.editor.arm32.llvm.a modules/libmodule_fbx.linuxbsd.editor.arm32.llvm.a modules/libmodule_gltf.linuxbsd.editor.arm32.llvm.a modules/libmodule_ktx.linuxbsd.editor.arm32.llvm.a modules/libmodule_msdfgen.linuxbsd.editor.arm32.llvm.a modules/libmodule_navigation.linuxbsd.editor.arm32.llvm.a modules/libmodule_theora.linuxbsd.editor.arm32.llvm.a modules/libmodule_vorbis.linuxbsd.editor.arm32.llvm.a modules/libmodule_astcenc.linuxbsd.editor.arm32.llvm.a modules/libmodule_basis_universal.linuxbsd.editor.arm32.llvm.a modules/libmodule_bcdec.linuxbsd.editor.arm32.llvm.a modules/libmodule_betsy.linuxbsd.editor.arm32.llvm.a modules/libmodule_bmp.linuxbsd.editor.arm32.llvm.a modules/libmodule_camera.linuxbsd.editor.arm32.llvm.a modules/libmodule_csg.linuxbsd.editor.arm32.llvm.a modules/libmodule_cvtt.linuxbsd.editor.arm32.llvm.a modules/libmodule_dds.linuxbsd.editor.arm32.llvm.a modules/libmodule_enet.linuxbsd.editor.arm32.llvm.a modules/libmodule_etcpak.linuxbsd.editor.arm32.llvm.a modules/libmodule_freetype.linuxbsd.editor.arm32.llvm.a modules/libmodule_gdscript.linuxbsd.editor.arm32.llvm.a modules/libmodule_glslang.linuxbsd.editor.arm32.llvm.a modules/libmodule_godot_physics_2d.linuxbsd.editor.arm32.llvm.a modules/libmodule_godot_physics_3d.linuxbsd.editor.arm32.llvm.a modules/libmodule_gridmap.linuxbsd.editor.arm32.llvm.a modules/libmodule_hdr.linuxbsd.editor.arm32.llvm.a modules/libmodule_interactive_music.linuxbsd.editor.arm32.llvm.a modules/libmodule_jolt_physics.linuxbsd.editor.arm32.llvm.a modules/libmodule_jpg.linuxbsd.editor.arm32.llvm.a modules/libmodule_jsonrpc.linuxbsd.editor.arm32.llvm.a modules/libmodule_lightmapper_rd.linuxbsd.editor.arm32.llvm.a modules/libmodule_mbedtls.linuxbsd.editor.arm32.llvm.a modules/libmodule_meshoptimizer.linuxbsd.editor.arm32.llvm.a modules/libmodule_minimp3.linuxbsd.editor.arm32.llvm.a modules/libmodule_mobile_vr.linuxbsd.editor.arm32.llvm.a modules/libmodule_mono.linuxbsd.editor.arm32.llvm.a modules/libmodule_multiplayer.linuxbsd.editor.arm32.llvm.a modules/libmodule_noise.linuxbsd.editor.arm32.llvm.a modules/libmodule_ogg.linuxbsd.editor.arm32.llvm.a modules/libmodule_openxr.linuxbsd.editor.arm32.llvm.a modules/libmodule_regex.linuxbsd.editor.arm32.llvm.a modules/libmodule_svg.linuxbsd.editor.arm32.llvm.a modules/libmodule_tga.linuxbsd.editor.arm32.llvm.a modules/libmodule_tinyexr.linuxbsd.editor.arm32.llvm.a modules/libmodule_upnp.linuxbsd.editor.arm32.llvm.a modules/libmodule_vhacd.linuxbsd.editor.arm32.llvm.a modules/libmodule_webp.linuxbsd.editor.arm32.llvm.a modules/libmodule_webrtc.linuxbsd.editor.arm32.llvm.a modules/libmodule_websocket.linuxbsd.editor.arm32.llvm.a modules/libmodule_webxr.linuxbsd.editor.arm32.llvm.a modules/libmodule_xatlas_unwrap.linuxbsd.editor.arm32.llvm.a modules/libmodule_zip.linuxbsd.editor.arm32.llvm.a platform/libplatform.linuxbsd.editor.arm32.llvm.a drivers/libdrivers.linuxbsd.editor.arm32.llvm.a editor/libeditor.linuxbsd.editor.arm32.llvm.a scene/libscene.linuxbsd.editor.arm32.llvm.a servers/libservers.linuxbsd.editor.arm32.llvm.a core/libcore.linuxbsd.editor.arm32.llvm.a modules/freetype/libfreetype_builtin.linuxbsd.editor.arm32.llvm.a modules/msdfgen/libmsdfgen_builtin.linuxbsd.editor.arm32.llvm.a modules/text_server_adv/libharfbuzz_builtin.linuxbsd.editor.arm32.llvm.a modules/text_server_adv/libgraphite_builtin.linuxbsd.editor.arm32.llvm.a modules/text_server_adv/libicu_builtin.linuxbsd.editor.arm32.llvm.a -lrt -lpthread -ldl -l:libatomic.a

...

/usr/bin/ld: core/libcore.linuxbsd.editor.arm32.llvm.a(huf_decompress.linuxbsd.editor.arm32.llvm.o): in function `HUF_decompress4X2_usingDTable_internal':
huf_decompress.c:(.text+0x206a): undefined reference to `HUF_decompress4X2_usingDTable_internal_fast_asm_loop'
/usr/bin/ld: core/libcore.linuxbsd.editor.arm32.llvm.a(huf_decompress.linuxbsd.editor.arm32.llvm.o): in function `HUF_decompress4X1_usingDTable_internal':
huf_decompress.c:(.text+0x3f6f): undefined reference to `HUF_decompress4X1_usingDTable_internal_fast_asm_loop'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

Steps to reproduce

  • Install Clang, libstdc++-static and libatomic-static on Linux (I tested Fedora 41 and Clang 19.1.7 from official repos)
  • Compile with the above command

Minimal reproduction project (MRP)

n/a

@akien-mga
Copy link
Member Author

akien-mga commented Feb 24, 2025

I think the problem is just that cross-compilation with Clang isn't supported out of the box. The build is done for the x86_64 target, so it enables the use of x86_64 assembly, and fails, as our SCons setup on the other hand assumes arm32 from the arch argument.

That's also why official Godot builds made with GCC compiled specifically for arm32 don't have this issue.

@bruvzg
Copy link
Member

bruvzg commented Feb 24, 2025

This is strange, calls to this function is in the ZSTD_ENABLE_ASM_X86_64_BMI2 ifdef and should be compiled on arm32. So something should be wrong with architecture detection.

@akien-mga akien-mga changed the title Linux arm32 build with Clang fails linking due to missing symbol in zstd huf_decompress.o Linux cross-compilation with Clang (use_llvm=yes) doesn't work out of the box Feb 24, 2025
@akien-mga akien-mga modified the milestones: 4.4, 4.x Feb 24, 2025
@bruvzg
Copy link
Member

bruvzg commented Feb 24, 2025

Seems like arch= actually do not do anything to select compiler on Linux (or even set -march= flag for cross compilation), so it will only work if CC/CXX and other cross tools are set in the environment.

@akien-mga
Copy link
Member Author

Yeah #64366 addresses that but needs proper review to make sure the chosen architectures are the ones we actually target.

@bruvzg
Copy link
Member

bruvzg commented Feb 24, 2025

Yeah #64366 addresses that but needs proper review to make sure the chosen architectures are the ones we actually target.

Probably only partially, usually default toolchain is not capable of cross compiling, and won't have any libraries to link. But it should at least produce error if wrong tools are used.

@akien-mga
Copy link
Member Author

akien-mga commented Feb 24, 2025

I removed this from the 4.4 priorities as it's not actually a regression, it's a pre-existing issue that was just made more obvious by #96303. Even before that PR, the builds created with use_llvm=yes arch=arm32 would actually be x86_64 builds.

@akien-mga akien-mga marked this as a duplicate and then as not a duplicate of #103273 Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: For team assessment
Development

No branches or pull requests

2 participants