From a1992702f895632abd0906a05ab22c07fddb5bed Mon Sep 17 00:00:00 2001 From: acqn Date: Sun, 24 Jan 2021 18:19:48 +0800 Subject: [PATCH] Declarations of 'extern' object and function should be visible in the file scope. --- src/cc65/symtab.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cc65/symtab.c b/src/cc65/symtab.c index 56c868b2a..3c000f3a1 100644 --- a/src/cc65/symtab.c +++ b/src/cc65/symtab.c @@ -1159,12 +1159,13 @@ SymEntry* AddLocalSym (const char* Name, const Type* T, unsigned Flags, int Offs SymEntry* AddGlobalSym (const char* Name, const Type* T, unsigned Flags) /* Add an external or global symbol to the symbol table and return the entry */ { - /* Use the global symbol table */ + /* Start from the local symbol table */ SymTable* Tab = SymTab; /* Do we have an entry with this name already? */ SymEntry* Entry = FindSymInTree (Tab, Name); if (Entry) { + /* We have a symbol with this name already */ if (HandleSymRedefinition (Entry, T, Flags)) { Entry = 0; @@ -1215,7 +1216,11 @@ SymEntry* AddGlobalSym (const char* Name, const Type* T, unsigned Flags) /* Use the fail-safe table for fictitious symbols */ Tab = FailSafeTab; } - } + + } else if ((Flags & (SC_EXTERN | SC_FUNC)) != 0) { + /* Add the new declaration to the global symbol table instead */ + Tab = SymTab0; + } if (Entry == 0 || Entry->Owner != Tab) {