From 5074259998152fa06f0c52ede73f5f2a20355ab8 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Thu, 3 Nov 2005 04:38:21 +0000 Subject: [PATCH] * symrec.c (symrec_define): Don't error if a symbol is declared common and then defined, and warn instead of error if a symbol is declared global and then defined. * externdef.asm: Test for the warning. svn path=/trunk/yasm/; revision=1308 --- libyasm/symrec.c | 6 ++++-- libyasm/tests/Makefile.inc | 3 +++ libyasm/tests/externdef.asm | 2 ++ libyasm/tests/externdef.errwarn | 2 ++ libyasm/tests/externdef.hex | 0 5 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 libyasm/tests/externdef.asm create mode 100644 libyasm/tests/externdef.errwarn create mode 100644 libyasm/tests/externdef.hex diff --git a/libyasm/symrec.c b/libyasm/symrec.c index 23f874bb..43e43aff 100644 --- a/libyasm/symrec.c +++ b/libyasm/symrec.c @@ -192,12 +192,14 @@ symtab_define(yasm_symtab *symtab, const char *name, sym_type type, yasm_symrec *rec = symtab_get_or_new(symtab, name, in_table); /* Has it been defined before (either by DEFINED or COMMON/EXTERN)? */ - if ((rec->status & SYM_DEFINED) || - (rec->visibility & (YASM_SYM_COMMON | YASM_SYM_EXTERN))) { + if (rec->status & SYM_DEFINED) { yasm__error(line, N_("redefinition of `%s'"), name); yasm__error_at(line, rec->line, N_("`%s' previously defined here"), name); } else { + if (rec->visibility & YASM_SYM_EXTERN) + yasm__warning(YASM_WARN_GENERAL, line, + N_("`%s' both defined and declared extern"), name); rec->line = line; /* set line number of definition */ rec->type = type; rec->status |= SYM_DEFINED; diff --git a/libyasm/tests/Makefile.inc b/libyasm/tests/Makefile.inc index 0594c1cf..7d2ad8cb 100644 --- a/libyasm/tests/Makefile.inc +++ b/libyasm/tests/Makefile.inc @@ -11,6 +11,9 @@ EXTRA_DIST += libyasm/tests/charconst64.errwarn EXTRA_DIST += libyasm/tests/charconst64.hex EXTRA_DIST += libyasm/tests/duplabel-err.asm EXTRA_DIST += libyasm/tests/duplabel-err.errwarn +EXTRA_DIST += libyasm/tests/externdef.asm +EXTRA_DIST += libyasm/tests/externdef.errwarn +EXTRA_DIST += libyasm/tests/externdef.hex EXTRA_DIST += libyasm/tests/incbin.asm EXTRA_DIST += libyasm/tests/incbin.errwarn EXTRA_DIST += libyasm/tests/incbin.hex diff --git a/libyasm/tests/externdef.asm b/libyasm/tests/externdef.asm new file mode 100644 index 00000000..3663af30 --- /dev/null +++ b/libyasm/tests/externdef.asm @@ -0,0 +1,2 @@ +extern foo +foo: diff --git a/libyasm/tests/externdef.errwarn b/libyasm/tests/externdef.errwarn new file mode 100644 index 00000000..8ff4a7ee --- /dev/null +++ b/libyasm/tests/externdef.errwarn @@ -0,0 +1,2 @@ +-:1: warning: binary object format does not support extern variables +-:2: warning: `foo' both defined and declared extern diff --git a/libyasm/tests/externdef.hex b/libyasm/tests/externdef.hex new file mode 100644 index 00000000..e69de29b -- 2.40.0