From f01a227470c9fa8eb89b272190533e8ac3b7814f Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Thu, 13 Feb 2020 20:12:19 +0100 Subject: [PATCH] Fix non-const labels with callbacks having incorrect values when diffed Basically, this broke PC, which is currently the only label-typed symbol with a callback. --- include/asm/symbol.h | 1 + src/asm/rpn.c | 2 +- src/asm/symbol.c | 8 ++++---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/asm/symbol.h b/include/asm/symbol.h index ec696701..259cfbbd 100644 --- a/include/asm/symbol.h +++ b/include/asm/symbol.h @@ -70,6 +70,7 @@ static inline bool sym_IsExported(struct sSymbol const *sym) return sym->isExported; } +int32_t sym_GetValue(struct sSymbol const *sym); uint32_t sym_CalcHash(const char *s); void sym_SetExportAll(uint8_t set); void sym_AddLocalReloc(char const *tzSym); diff --git a/src/asm/rpn.c b/src/asm/rpn.c index 6b634467..059e2def 100644 --- a/src/asm/rpn.c +++ b/src/asm/rpn.c @@ -442,7 +442,7 @@ void rpn_BinaryOp(enum RPNCommand op, struct Expression *expr, struct sSymbol const *symbol1 = symbolOf(src1); struct sSymbol const *symbol2 = symbolOf(src2); - expr->nVal = symbol1->nValue - symbol2->nValue; + expr->nVal = sym_GetValue(symbol1) - sym_GetValue(symbol2); expr->isKnown = true; } else { /* If it's not known, start computing the RPN expression */ diff --git a/src/asm/symbol.c b/src/asm/symbol.c index c0646b5f..d9fa01e7 100644 --- a/src/asm/symbol.c +++ b/src/asm/symbol.c @@ -72,7 +72,7 @@ static int32_t CallbackPC(struct sSymbol const *self) /* * Get the nValue field of a symbol */ -static int32_t getvaluefield(struct sSymbol const *sym) +int32_t sym_GetValue(struct sSymbol const *sym) { if (sym->Callback) return sym->Callback(sym); @@ -268,11 +268,11 @@ uint32_t sym_GetConstantValue(char const *s) if (pCurrentSection->nOrg == -1) yyerror("Expected constant PC but section is not fixed"); else - return getvaluefield(psym); + return sym_GetValue(psym); } else if (psym != NULL) { if (sym_IsConstant(psym)) - return getvaluefield(psym); + return sym_GetValue(psym); fatalerror("\"%s\" does not have a constant value", s); } @@ -294,7 +294,7 @@ uint32_t sym_GetDefinedValue(char const *s) if (!sym_IsNumeric(psym)) yyerror("'%s' is a macro or string symbol", s); - return getvaluefield(psym); + return sym_GetValue(psym); } }