From db6caaa265376bc73712614de935377a3559519c Mon Sep 17 00:00:00 2001 From: ggn Date: Mon, 17 Oct 2022 19:49:32 +0300 Subject: [PATCH] Fix for #209 - forbid exporting expressions with unresolved symbols --- expr.c | 2 +- rmac.h | 1 + sect.c | 9 +++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/expr.c b/expr.c index 5a9155c..30629df 100644 --- a/expr.c +++ b/expr.c @@ -585,7 +585,7 @@ be converted from a linked list into an array). // // Evaluate expression. // If the expression involves only ONE external symbol, the expression is -// UNDEFINED, but it's value includes everything but the symbol value, and +// UNDEFINED, but its value includes everything but the symbol value, and // 'a_esym' is set to the external symbol. // int evexpr(TOKEN * _tk, uint64_t * a_value, WORD * a_attr, SYM ** a_esym) diff --git a/rmac.h b/rmac.h index 5f23090..6ec6c4d 100644 --- a/rmac.h +++ b/rmac.h @@ -261,6 +261,7 @@ PTR #define SIZP 0x0080 // .p (FPU pakced decimal real) #define SIZQ 0x0100 // .q (quad word) +// Extended attributes #define EQUATEDREG 0x0008 // Equated register symbol #define UNDEF_EQUR 0x0010 #define EQUATEDCC 0x0020 diff --git a/sect.c b/sect.c index 20e6fcb..834df9d 100644 --- a/sect.c +++ b/sect.c @@ -462,6 +462,15 @@ int ResolveFixups(int sno) if (evexpr(fup->expr, &eval, &eattr, &esym) != OK) continue; + if (esym) + if (!(esym->sattr & DEFINED)) + { + // If our expression still has an undefined symbol at this stage, it's bad news. + // The linker is never going to resolve the expression, so that's an error. + error("cannot export complex expression with unresloved symbol '%s'", esym->sname); + continue; + } + if ((CHECK_OPTS(OPT_PC_RELATIVE)) && (eattr & (DEFINED | REFERENCED | EQUATED)) == (DEFINED | REFERENCED)) { error("relocation not allowed when o30 is enabled"); -- 2.33.0.windows.1