Linker Error Fix Walkthrough
Issue
The user reported a linker error: ld.lld: error: undefined symbol: _D10minimal_os6kernel17shell_integration18runCompilerBuilderFNbNiZv
This symbol corresponded to minimal_os.kernel.shell_integration.runCompilerBuilder. Although the function was defined in
src/minimal_os/kernel/shell_integration.d
and used in the same file, ldc2 was failing to emit it into the object file.
Investigation
Initial checks: Confirmed the function definition existed and was used by compilerBuilderProcessEntry.
Attempts to force emission:
Added extern(C) to runCompilerBuilder.
Added pragma(inline, false).
Added export.
None of these worked; the symbol remained undefined (though the name changed to the C name).
Inlining: Inlined runCompilerBuilder into compilerBuilderProcessEntry to bypass potential visibility issues.
Discovery: After inlining, compilerBuilderProcessEntry itself became undefined! This indicated that the content of the function was causing ldc2 to skip emission.
Bisection: Systematically commented out parts of the function body to identify the culprit.
Root Cause: The issue was identified in the userland bootstrap block:
immutable(char)[][] desktopStack = [ "xorg-server", "xinit", "display-manager", "i3" ];
In -betterC mode, dynamic array literals that require allocation are restricted. ldc2 apparently handled this by silently dropping the function instead of reporting an error (or maybe it was a specific interaction with the build flags).
Fix
Inlined runCompilerBuilder: Kept the inlined version for simplicity.
Static Array: Changed the dynamic array literal to a static array:
immutable(char)[][4] desktopStack = [ "xorg-server", "xinit", "display-manager", "i3" ];
Verification: Rebuilt the project using
./buildscript.sh
. The build succeeded and the ISO image was generated.
Changes
Modified
src/minimal_os/kernel/shell_integration.d
:
Inlined runCompilerBuilder into compilerBuilderProcessEntry.
Changed desktopStack to use a static array size [4].
Added pragma(inline, false) and export to compilerBuilderProcessEntry (precautionary).