diff --git a/src/link/symbol.cpp b/src/link/symbol.cpp index a7f320b6..184f5077 100644 --- a/src/link/symbol.cpp +++ b/src/link/symbol.cpp @@ -26,8 +26,12 @@ Label const &Symbol::label() const { } void sym_AddSymbol(Symbol &symbol) { - // Check if the symbol already exists - if (Symbol *other = sym_GetSymbol(symbol.name); other) { + Symbol *other = sym_GetSymbol(symbol.name); + int32_t const *symValue = std::get_if(&symbol.data); + int32_t const *otherValue = other ? std::get_if(&other->data) : nullptr; + + // Check if the symbol already exists with a different value + if (other && !(symValue && otherValue && *symValue == *otherValue)) { fprintf(stderr, "error: \"%s\" both in %s from ", symbol.name.c_str(), symbol.objFileName); symbol.src->dump(symbol.lineNo); fprintf(stderr, " and in %s from ", other->objFileName); @@ -36,7 +40,7 @@ void sym_AddSymbol(Symbol &symbol) { exit(1); } - // If not, add it + // If not, add it (potentially replacing the previous same-value symbol) symbols[symbol.name] = &symbol; } diff --git a/test/link/same-consts/a.asm b/test/link/same-consts/a.asm new file mode 100644 index 00000000..8cace25a --- /dev/null +++ b/test/link/same-consts/a.asm @@ -0,0 +1,2 @@ +def constant equ 42 +export constant diff --git a/test/link/same-consts/b.asm b/test/link/same-consts/b.asm new file mode 100644 index 00000000..8cace25a --- /dev/null +++ b/test/link/same-consts/b.asm @@ -0,0 +1,2 @@ +def constant equ 42 +export constant diff --git a/test/link/same-consts/out.err b/test/link/same-consts/out.err new file mode 100644 index 00000000..e69de29b diff --git a/test/link/test.sh b/test/link/test.sh index 75bb9d01..357e92b1 100755 --- a/test/link/test.sh +++ b/test/link/test.sh @@ -190,6 +190,15 @@ tryDiff "$test"/out.err "$outtemp" tryCmp "$test"/out.gb "$gbtemp" evaluateTest +test="same-consts" +startTest +"$RGBASM" -o "$otemp" "$test"/a.asm +"$RGBASM" -o "$gbtemp2" "$test"/b.asm +continueTest +rgblinkQuiet -o "$gbtemp" "$gbtemp2" "$otemp" 2>"$outtemp" +tryDiff "$test"/out.err "$outtemp" +evaluateTest + test="scramble-romx" startTest "$RGBASM" -o "$otemp" "$test"/a.asm