diff --git a/src/worker/builder.ts b/src/worker/builder.ts index aa5f0585..27deaf92 100644 --- a/src/worker/builder.ts +++ b/src/worker/builder.ts @@ -591,7 +591,7 @@ function applySymbolConfigs(params, entries: string[]) { /** * Record a linker symbol. If the platform already passes `NAME=...` in - * libargs, the entry is replaced in place -- appending instead would define the + * libargs (or `-g NAME=...` in extra_link_args), the entry is replaced in place -- appending instead would define the * symbol twice ("Redefinition of symbol", "Definition of public symbol ..."). */ function setLinkSymbol(params, symbols: PhaseLists, entry: string) { @@ -606,6 +606,17 @@ function setLinkSymbol(params, symbols: PhaseLists, entry: string) { } } } + // sdldz80 platforms pass `-g NAME=...` pairs in extra_link_args + let xa = params.extra_link_args; + if (xa) { + for (let i = 1; i < xa.length; i++) { + if (xa[i - 1] === '-g' && xa[i].split('=')[0] === name) { + xa[i] = entry; + applySymbolConfigs(params, [entry]); + return; + } + } + } symbols.linker = mergeByName(symbols.linker, entry); applySymbolConfigs(params, [entry]); } diff --git a/src/worker/tools/sdcc.ts b/src/worker/tools/sdcc.ts index 70337fd5..69b05407 100644 --- a/src/worker/tools/sdcc.ts +++ b/src/worker/tools/sdcc.ts @@ -1,7 +1,7 @@ import { Worker } from "node:worker_threads"; import { defineArgs, extraArgsFor, linkSymbolArgs } from "../../common/toolmeta"; import { CodeListingMap, WorkerError } from "../../common/workertypes"; -import { BuildStep, BuildStepResult, gatherFiles, staleFiles, populateFiles, putWorkFile, populateExtraFiles, anyTargetChanged, getWorkFileAsString } from "../builder"; +import { BuildStep, BuildStepResult, gatherFiles, staleFiles, populateFiles, putWorkFile, populateExtraFiles, anyTargetChanged, getWorkFileAsString, fixParamsWithDefines } from "../builder"; import { parseListing, parseSourceLines, msvcErrorMatcher } from "../listingutils"; import { EmscriptenModule, emglobal, execMain, loadNative, moduleInstFn, print_fn, setupFS, setupStdin } from "../wasmutils"; import { preprocessMCPP } from "./mcpp"; @@ -266,6 +266,7 @@ export function compileSDCC(step: BuildStep): BuildStepResult { var params = step.params; var isGBZ80 = params.arch === 'gbz80'; var outpath = step.prefix + ".asm"; + fixParamsWithDefines(step.path, params); // //#symbol, //#flag, //#tooldef if (staleFiles(step, [outpath])) { var errors = []; loadNative('sdcc'); diff --git a/test/unit/testbuildparams.ts b/test/unit/testbuildparams.ts index fc5e7075..aa741d5d 100644 --- a/test/unit/testbuildparams.ts +++ b/test/unit/testbuildparams.ts @@ -214,6 +214,14 @@ describe("explicit build directives (//#symbol, //#flag, //#tooldef)", function assert.deepStrictEqual(params.symbols.linker, []); }); + it("#symbol ld replaces a matching -g entry in extra_link_args (sdldz80)", function () { + const params: any = { extra_link_args: ['-l', 'gb', '-g', 'GB_MAPPER=0x0', '-g', 'GB_RAM_SIZE=0x0'] }; + applyDirectives("//#symbol ld GB_MAPPER=0x03\n//#symbol ld GB_RAM_SIZE=0x02\n", params); + assert.deepStrictEqual(params.extra_link_args, ['-l', 'gb', '-g', 'GB_MAPPER=0x03', '-g', 'GB_RAM_SIZE=0x02']); + // merged into extra_link_args, not queued again -> no duplicate -g on the link line + assert.deepStrictEqual(params.symbols.linker, []); + }); + it("#symbol ld queues a symbol that is not a platform libarg", function () { const params = nesParams(); applyDirectives("//#symbol ld NEWSYM=0x10\n", params);