ref: 361d6cf5176ee41a397b0b965de5fb0506af38ad
parent: 6800609fa74f76f446b7e80cb7c81f072ec49fbd
parent: 76efd26da019f29ed0ddf236fcbd0c9aea1b60d9
author: Eldred Habert <[email protected]>
date: Tue Feb 25 21:56:35 EST 2020
Merge pull request #437 from rednex/locals Prevent local symbols that are not labels
--- a/src/asm/asmy.y
+++ b/src/asm/asmy.y
@@ -551,7 +551,12 @@
%left NEG /* negation -- unary minus */
%token <tzSym> T_LABEL
+%token <tzSym> T_LOCAL_LABEL
+%type <tzSym> scoped_label
+%type <tzSym> scoped_label_bare
%token <tzSym> T_ID
+%token <tzSym> T_LOCAL_ID
+%type <tzSym> scoped_id
%token <tzSym> T_POP_EQU
%token <tzSym> T_POP_SET
%token <tzSym> T_POP_EQUAL
@@ -654,8 +659,20 @@
| pseudoop
;
+scoped_label_bare : T_LABEL | T_LOCAL_LABEL ;
+scoped_label : T_LABEL ':'
+ {
+ strcpy($$, $1);
+ }
+ | T_LOCAL_LABEL ':'
+ {
+ strcpy($$, $1);
+ }
+;
+scoped_id : T_ID | T_LOCAL_ID ;
+
label : /* empty */
- | T_LABEL
+ | scoped_label_bare
{
if ($1[0] == '.')
sym_AddLocalReloc($1);
@@ -662,7 +679,7 @@
else
sym_AddReloc($1);
}
- | T_LABEL ':'
+ | scoped_label
{
if ($1[0] == '.')
sym_AddLocalReloc($1);
@@ -669,7 +686,7 @@
else
sym_AddReloc($1);
}
- | T_LABEL ':' ':'
+ | scoped_label ':'
{
if ($1[0] == '.')
sym_AddLocalReloc($1);
@@ -925,7 +942,7 @@
| purge_list_entry comma purge_list
;
-purge_list_entry : T_ID
+purge_list_entry : scoped_id
{
sym_Purge($1);
}
@@ -938,7 +955,7 @@
| import_list_entry comma import_list
;
-import_list_entry : T_ID
+import_list_entry : scoped_id
{
/*
* This is done automatically if the label isn't found
@@ -955,7 +972,7 @@
| export_list_entry comma export_list
;
-export_list_entry : T_ID
+export_list_entry : scoped_id
{
sym_Export($1);
}
@@ -968,7 +985,7 @@
| global_list_entry comma global_list
;
-global_list_entry : T_ID
+global_list_entry : scoped_id
{
sym_Export($1);
}
@@ -1233,7 +1250,7 @@
}
;
-relocexpr_no_str : T_ID
+relocexpr_no_str : scoped_id
{
rpn_Symbol(&$$, $1);
}
@@ -1265,7 +1282,7 @@
| T_OP_NOT relocexpr %prec NEG { rpn_UNNOT(&$$, &$2); }
| T_OP_HIGH '(' relocexpr ')' { rpn_HIGH(&$$, &$3); }
| T_OP_LOW '(' relocexpr ')' { rpn_LOW(&$$, &$3); }
- | T_OP_BANK '(' T_ID ')'
+ | T_OP_BANK '(' scoped_id ')'
{
/* '@' is also a T_ID, it is handled here. */
rpn_BankSymbol(&$$, $3);
@@ -1276,7 +1293,7 @@
}
| T_OP_DEF {
oDontExpandStrings = true;
- } '(' T_ID ')'
+ } '(' scoped_id ')'
{
struct sSymbol const *sym = sym_FindSymbol($4);
if (sym && !(sym_IsDefined(sym) && sym->type != SYM_LABEL))
--- a/src/asm/lexer.c
+++ b/src/asm/lexer.c
@@ -913,10 +913,18 @@
goto scanagain;
}
- if (token->nToken == T_ID && linestart)
- return T_LABEL;
- else
- return token->nToken;
+ uint32_t type = token->nToken;
+
+ if (type == T_ID && strchr(yylval.tzSym, '.'))
+ type = T_LOCAL_ID;
+
+ if (linestart) {
+ if (type == T_ID)
+ return T_LABEL;
+ if (type == T_LOCAL_ID)
+ return T_LOCAL_LABEL;
+ }
+ return type;
}
/* Longest match was a keyword or operator. */
--- a/test/asm/label-macro-arg.asm
+++ b/test/asm/label-macro-arg.asm
@@ -40,6 +40,6 @@
test_char _
test_char @
test_char #
- test_char .
+ test_char .
test_char :
--- a/test/asm/label-macro-arg.err
+++ b/test/asm/label-macro-arg.err
@@ -1,5 +1,7 @@
-ERROR: label-macro-arg.asm(45) -> label-macro-arg.asm::test_char(31):
- Label "sizeof_" created outside of a SECTION
+ERROR: label-macro-arg.asm(44) -> label-macro-arg.asm::test_char(31):
+ Local label in main scope
while expanding symbol "VAR_DEF"
-ERROR: label-macro-arg.asm(45) -> label-macro-arg.asm::test_char(31):
- Macro 'something' not defined
+ERROR: label-macro-arg.asm(44) -> label-macro-arg.asm::test_char(31):
+ syntax error
+while expanding symbol "VAR_DEF"
+error: Assembly aborted (2 errors)!
--- a/test/asm/label-macro-arg.out
+++ b/test/asm/label-macro-arg.out
@@ -5,4 +5,3 @@
sizeof__something equals $1
sizeof_@something equals $1
sizeof_#something equals $1
-sizeof_.something equals $1