From: uz Date: Sat, 24 Mar 2012 13:42:10 +0000 (+0000) Subject: Fixed an error: For symbols declared as extern in local scope, the name for X-Git-Tag: V2.14~443 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=515661e5f4ca75c9a40445d167cc4ebc9ba7bcf6;p=cc65 Fixed an error: For symbols declared as extern in local scope, the name for the external assembler symbol wasn't set. git-svn-id: svn://svn.cc65.org/cc65/trunk@5620 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/cc65/symentry.c b/src/cc65/symentry.c index e42c8bbaa..1644c962f 100644 --- a/src/cc65/symentry.c +++ b/src/cc65/symentry.c @@ -162,7 +162,7 @@ int SymIsOutputFunc (const SymEntry* Sym) return IsTypeFunc (Sym->Type) && SymIsDef (Sym) && (Sym->Flags & (SC_REF | SC_EXTERN)); -} +} @@ -209,6 +209,23 @@ void SymUseAttr (SymEntry* Sym, struct Declaration* D) +void SymSetAsmName (SymEntry* Sym) +/* Set the assembler name for an external symbol from the name of the symbol */ +{ + unsigned Len; + + /* Cannot be used to change the name */ + PRECONDITION (Sym->AsmName == 0); + + /* The assembler name starts with an underline */ + Len = strlen (Sym->Name); + Sym->AsmName = xmalloc (Len + 2); + Sym->AsmName[0] = '_'; + memcpy (Sym->AsmName+1, Sym->Name, Len+1); +} + + + void CvtRegVarToAuto (SymEntry* Sym) /* Convert a register variable to an auto variable */ { diff --git a/src/cc65/symentry.h b/src/cc65/symentry.h index 900d2ee5f..08cac8d80 100644 --- a/src/cc65/symentry.h +++ b/src/cc65/symentry.h @@ -252,6 +252,9 @@ INLINE int SymHasAttr (const SymEntry* Sym, DeclAttrType A) void SymUseAttr (SymEntry* Sym, struct Declaration* D); /* Use the attributes from the declaration for this symbol */ +void SymSetAsmName (SymEntry* Sym); +/* Set the assembler name for an external symbol from the name of the symbol */ + void CvtRegVarToAuto (SymEntry* Sym); /* Convert a register variable to an auto variable */ diff --git a/src/cc65/symtab.c b/src/cc65/symtab.c index db6541ee7..23b19695e 100644 --- a/src/cc65/symtab.c +++ b/src/cc65/symtab.c @@ -710,6 +710,7 @@ SymEntry* AddLocalSym (const char* Name, const Type* T, unsigned Flags, int Offs Entry->V.R.SaveOffs = StackPtr; } else if ((Flags & SC_EXTERN) == SC_EXTERN) { Entry->V.Label = Offs; + SymSetAsmName (Entry); } else if ((Flags & SC_STATIC) == SC_STATIC) { /* Generate the assembler name from the label number */ Entry->V.Label = Offs; @@ -809,8 +810,6 @@ SymEntry* AddGlobalSym (const char* Name, const Type* T, unsigned Flags) } else { - unsigned Len; - /* Create a new entry */ Entry = NewSymEntry (Name, Flags); @@ -826,10 +825,7 @@ SymEntry* AddGlobalSym (const char* Name, const Type* T, unsigned Flags) } /* Add the assembler name of the symbol */ - Len = strlen (Name); - Entry->AsmName = xmalloc (Len + 2); - Entry->AsmName[0] = '_'; - memcpy (Entry->AsmName+1, Name, Len+1); + SymSetAsmName (Entry); /* Add the entry to the symbol table */ AddSymEntry (Tab, Entry);