Skip to content

Commit 16b753f

Browse files
atilanevesclaude
authored andcommitted
Fix dmd:frontend linker errors introduced in 2.112
Three backend symbols were referenced from dmd:frontend modules: 1. statementsem.d and dsymbolsem.d unconditionally imported dmd.iasm (inline assembler, backend-only). Wrap the calls in version(NoBackend), consistent with how iasm/package.d itself handles the no-backend case. 2. globals.d (dmd:lexer) has Edition used as an AA value type, which causes TypeInfo_Enum for Edition to be instantiated in globals.o. That TypeInfo references Edition.__init, defined in astenums.d. Since astenums.d was only in dmd:frontend (not dmd:lexer), the symbol was unresolvable due to static archive link order. Fix by moving astenums.d into dmd:lexer and excluding it from dmd:frontend's source path. Add a regression test (compiler/test/dub_package/frontend_subpackage.d) that links against dmd:frontend only and calls initDMD(). Add a targeted CI step (test_frontend_subpackage) that runs this test with both the host compiler and the freshly-built compiler, using -m${MODEL} to match the build architecture. Fixes dlang#23119 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 6313729 commit 16b753f

8 files changed

Lines changed: 56 additions & 7 deletions

File tree

.cirrus.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ common_steps_template: &COMMON_STEPS_TEMPLATE
3535
./ci/run.sh test_dmd
3636
fi
3737
38+
test_frontend_subpackage_script: \[ "${DMD_TEST_COVERAGE:-0}" == "1" \] || ./ci/run.sh test_frontend_subpackage
3839
test_druntime_script: \[ "${DMD_TEST_COVERAGE:-0}" == "1" \] || ./ci/run.sh test_druntime
3940
test_phobos_script: \[ "${DMD_TEST_COVERAGE:-0}" == "1" \] || ./ci/run.sh test_phobos
4041

.github/workflows/main.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ jobs:
159159
arch: ${{ env.MODEL == '64' && 'x64' || 'x86' }}
160160
- name: Test dmd
161161
run: ci/run.sh test_dmd
162+
- name: Test frontend subpackage
163+
if: '!matrix.coverage && (success() || failure()) && (matrix.host_dmd == ''dmd'' || matrix.host_dmd == ''dmd-latest'')'
164+
run: ci/run.sh test_frontend_subpackage
162165
- name: Test druntime
163166
if: '!matrix.coverage && (success() || failure())'
164167
run: ci/run.sh test_druntime
@@ -258,6 +261,12 @@ jobs:
258261
ci/run.sh test_dmd
259262
echo '::endgroup::'
260263
264+
if [ "$HOST_DMD" = "dmd" ]; then
265+
echo '::group::Test frontend subpackage'
266+
ci/run.sh test_frontend_subpackage
267+
echo '::endgroup::'
268+
fi
269+
261270
echo '::group::Test druntime'
262271
ci/run.sh test_druntime
263272
echo '::endgroup::'

ci/run.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ test_dub_package() {
172172
echo "Skipping DUB examples on GDC."
173173
else
174174
local abs_build_path="$PWD/$build_path"
175-
pushd test/dub_package
175+
pushd compiler/test/dub_package
176176
for file in *.d ; do
177177
dubcmd=""
178178
# running impvisitor is failing right now
@@ -186,13 +186,26 @@ test_dub_package() {
186186
done
187187
popd
188188
# Test rdmd build
189-
"${build_path}/dmd" -version=NoBackend -version=GC -version=NoMain -Jgenerated/dub -Jsrc/dmd/res -Isrc -i -run test/dub_package/frontend.d
189+
"${build_path}/dmd" -version=NoBackend -version=GC -version=NoMain -Jgenerated/dub -Jcompiler/src/dmd/res -Icompiler/src -i -run compiler/test/dub_package/frontend.d
190190
fi
191191
if [ "$OS_NAME" != "windows" ]; then
192192
deactivate
193193
fi
194194
}
195195

196+
# test that the dmd:frontend subpackage links correctly (no backend symbols pulled in)
197+
test_frontend_subpackage() {
198+
if [ "$OS_NAME" != "windows" ]; then
199+
source ~/dlang/*/activate # activate host compiler
200+
fi
201+
local abs_build_path="$PWD/$build_path"
202+
dub --single compiler/test/dub_package/frontend_subpackage.d
203+
DFLAGS="-m${MODEL:-64} -de" dub --single --compiler="${abs_build_path}/dmd" compiler/test/dub_package/frontend_subpackage.d
204+
if [ "$OS_NAME" != "windows" ]; then
205+
deactivate
206+
fi
207+
}
208+
196209
# clone phobos repos if not already available
197210
setup_repos() {
198211
local branch="$1"
@@ -297,6 +310,7 @@ if [ "$#" -gt 0 ]; then
297310
test_druntime) test_druntime ;;
298311
test_phobos) test_phobos ;;
299312
test_dub_package) test_dub_package ;;
313+
test_frontend_subpackage) test_frontend_subpackage ;;
300314
testsuite) testsuite ;;
301315
codecov) codecov ;;
302316
*) echo "Unknown command: $1" >&2; exit 1 ;;

compiler/src/dmd/dsymbolsem.d

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3455,8 +3455,12 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
34553455
{
34563456
if (dsym.semanticRun >= PASS.semanticdone)
34573457
return;
3458-
import dmd.iasm : asmSemantic;
3459-
asmSemantic(dsym, sc);
3458+
version (NoBackend) {}
3459+
else
3460+
{
3461+
import dmd.iasm : asmSemantic;
3462+
asmSemantic(dsym, sc);
3463+
}
34603464
dsym.semanticRun = PASS.semanticdone;
34613465
}
34623466

compiler/src/dmd/statementsem.d

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import dmd.func;
4242
import dmd.funcsem;
4343
import dmd.globals;
4444
import dmd.hdrgen;
45-
import dmd.iasm;
4645
import dmd.id;
4746
import dmd.identifier;
4847
import dmd.importc;
@@ -3751,7 +3750,13 @@ Statement statementSemanticVisit(Statement s, Scope* sc)
37513750
*/
37523751

37533752
//printf("AsmStatement()::semantic()\n");
3754-
result = asmSemantic(s, sc);
3753+
version (NoBackend)
3754+
result = s;
3755+
else
3756+
{
3757+
import dmd.iasm;
3758+
result = asmSemantic(s, sc);
3759+
}
37553760
}
37563761

37573762
void visitCompoundAsm(CompoundAsmStatement cas)

compiler/test/dub_package/frontend_file.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ double average(int[] array)
6363
}
6464
}.replace("SIZE_T", size_t.sizeof == 8 ? "ulong" : "uint");
6565

66-
assert(generated.canFind(expected));
66+
assert(generated.canFind(expected), generated);
6767
}
6868

6969
/**
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env dub
2+
/+dub.sdl:
3+
dependency "dmd:frontend" path="../../.."
4+
+/
5+
6+
// Verify that dmd:frontend links without requiring backend symbols.
7+
// Regression test for https://github.com/dlang/dmd/issues/23119
8+
9+
import dmd.frontend;
10+
11+
void main()
12+
{
13+
initDMD();
14+
}

dub.sdl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ subPackage {
3434
sourcePaths
3535

3636
sourceFiles \
37+
"compiler/src/dmd/astenums.d" \
3738
"compiler/src/dmd/console.d" \
3839
"compiler/src/dmd/entity.d" \
3940
"compiler/src/dmd/errors.d" \
@@ -101,6 +102,7 @@ subPackage {
101102
excludedSourceFiles "compiler/src/dmd/lib/*"
102103
excludedSourceFiles "compiler/src/dmd/irgen/*"
103104
excludedSourceFiles "compiler/src/dmd/{\
105+
astenums,\
104106
astbase,\
105107
console,\
106108
entity,\

0 commit comments

Comments
 (0)