Skip to content

module-template: fix C-backend module builds on x86-64 clang/gcc - #17

Closed
dougchansan wants to merge 1 commit into
ExpansionPak:moderngekko-runtimefrom
dougchansan:pr/module-template-clang-build
Closed

module-template: fix C-backend module builds on x86-64 clang/gcc#17
dougchansan wants to merge 1 commit into
ExpansionPak:moderngekko-runtimefrom
dougchansan:pr/module-template-clang-build

Conversation

@dougchansan

@dougchansan dougchansan commented Aug 21, 2026

Copy link
Copy Markdown

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 emit:

#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 (GENERATED_DIR, GXRUNTIME_DIR/include, CHASSIS_ABI_DIR, the binary dir) 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 this sets it in module-template — the one place that knows the module is being built against GXRuntime. The DOLRECOMP_CPU_HEADER hook exists for exactly this case.

2. The x86-64-v3 dispatch path references code that isn't 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 doesn't pass --targets, so it's 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 — 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, so host_has_x86_64_v3() is a constant 0 and the call is dead-code eliminated. And the LLVM backend doesn't include generated.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:

result
before build stops, 3 errors above
after 0 errors, links gGLME01_recomp.so (42.3 MB), nm -D shows no undefined dolrecomp_call__x86_64_v3

Cause (1) was also isolated on its own: a one-line TU including generated.h with module-template's exact include set fails with 'cpu/cpu.h' file not found, and compiles clean with -DDOLRECOMP_CPU_HEADER="core/cpu.h".

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
dougchansan force-pushed the pr/module-template-clang-build branch from a6db2d1 to ce05a37 Compare August 21, 2026 23:39
@dougchansan

Copy link
Copy Markdown
Author

Obsolete after the module-template rewrite on main: module_export.c no longer has the x86-64-v3 dispatch path this fixed (chassis_dispatch now calls dolrecomp_call directly), so the clang/gcc build break cannot occur. Closing.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant