module-template: fix C-backend module builds on x86-64 clang/gcc - #17
Closed
dougchansan wants to merge 1 commit into
Closed
Conversation
Building a C-backend module through module-template fails on x86-64
Linux/macOS with clang or gcc. Three errors, two independent causes.
1) The generated CPU header is never resolved.
Generated sources do:
#ifndef DOLRECOMP_CPU_HEADER
#define DOLRECOMP_CPU_HEADER "cpu/cpu.h"
#endif
#include DOLRECOMP_CPU_HEADER
"cpu/cpu.h" is DolRecomp's standalone layout. A module compiles
against GXRuntime, where the same header is core/cpu.h, and none of
module-template's four include directories provides a cpu/ subdir:
generated.h:15:10: fatal error: 'cpu/cpu.h' file not found
Nothing in RecompCore or moderngekko-port sets the override, so set
it in module-template, which is the one place that knows the module
is being built against GXRuntime.
2) The x86-64-v3 dispatch path references code that is not there.
selected_dispatch() calls dolrecomp_call__x86_64_v3(), which only
exists when the module was generated with that variant
(dolrecomp --targets ... x86-64-v3). moderngekko-port does not pass
--targets, so it is normally absent:
module_export.c:23: error: invalid cpu feature string for builtin
module_export.c:24: error: invalid cpu feature string for builtin
module_export.c:35: error: call to undeclared function
'dolrecomp_call__x86_64_v3'
clang also rejects "movbe" and "lzcnt" as __builtin_cpu_supports
feature strings, which gcc accepts.
Compile the whole v3 path only under DOLRECOMP_MODULE_HAVE_X86_64_V3
and drop the two feature strings clang does not accept.
Both went unnoticed because the configurations built regularly fold the
code away before the compiler sees it: under MSVC and on non-x86-64
targets the __x86_64__ && (__GNUC__ || __clang__) guard is false, so
host_has_x86_64_v3() is a constant 0 and the call is dead-code
eliminated. The LLVM backend does not include generated.h, so it never
hits (1) either.
Verified on x86-64 Linux with clang 18: before, the build stops with the
errors above; after, a Luigi's Mansion C-backend module compiles clean
(0 errors) and links to a 42.3 MB .so with no undefined v3 symbol.
dougchansan
force-pushed
the
pr/module-template-clang-build
branch
from
August 21, 2026 23:39
a6db2d1 to
ce05a37
Compare
Author
|
Obsolete after the module-template rewrite on main: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Building a C-backend module through
module-templatefails on x86-64 Linux/macOS with clang or gcc. Three errors, two independent causes.1. The generated CPU header is never resolved
Generated sources emit:
cpu/cpu.his DolRecomp's standalone layout. A module compiles against GXRuntime, where the same header iscore/cpu.h, and none ofmodule-template's four include directories (GENERATED_DIR,GXRUNTIME_DIR/include,CHASSIS_ABI_DIR, the binary dir) provides acpu/subdir:Nothing in RecompCore or
moderngekko-portsets the override, so this sets it inmodule-template— the one place that knows the module is being built against GXRuntime. TheDOLRECOMP_CPU_HEADERhook exists for exactly this case.2. The x86-64-v3 dispatch path references code that isn't there
selected_dispatch()callsdolrecomp_call__x86_64_v3(), which only exists when the module was generated with that variant (dolrecomp --targets ... x86-64-v3).moderngekko-portdoesn't pass--targets, so it's normally absent:clang also rejects
"movbe"and"lzcnt"as__builtin_cpu_supportsfeature strings, which gcc accepts — that's the first two errors, independent of the missing symbol.Fix: compile the whole v3 path only under
DOLRECOMP_MODULE_HAVE_X86_64_V3, and drop the two feature strings clang doesn't accept.Why this went unnoticed
The configurations that get built regularly fold the code away before the compiler can complain. Under MSVC and on non-x86-64 targets the
__x86_64__ && (__GNUC__ || __clang__)guard is false, sohost_has_x86_64_v3()is a constant0and the call is dead-code eliminated. And the LLVM backend doesn't includegenerated.h, so it never hits (1) either. It takes the C backend and an x86-64 clang/gcc host to see any of this.Verification
On x86-64 Linux with clang 18, building a Luigi's Mansion (GLME01) C-backend module:
gGLME01_recomp.so(42.3 MB),nm -Dshows no undefineddolrecomp_call__x86_64_v3Cause (1) was also isolated on its own: a one-line TU including
generated.hwith module-template's exact include set fails with'cpu/cpu.h' file not found, and compiles clean with-DDOLRECOMP_CPU_HEADER="core/cpu.h".