]> git.sur5r.net Git - cc65/commitdiff
Fixed a problem with .global: In some situations, exported symbols went
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Mon, 19 Apr 2004 17:00:12 +0000 (17:00 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Mon, 19 Apr 2004 17:00:12 +0000 (17:00 +0000)
into the object files with an address size of ADDR_SIZE_DEFAULT, something
which cannot be handled by the linker.

git-svn-id: svn://svn.cc65.org/cc65/trunk@2980 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/ca65/symentry.c
src/ca65/symentry.h
src/ca65/symtab.c

index 1f0420956568b5ede9b53f87f527c0424549dcac..a1c86d80286ce51acccc75acc256b84a946c7a6c 100644 (file)
@@ -6,7 +6,7 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2003 Ullrich von Bassewitz                                       */
+/* (C) 1998-2004 Ullrich von Bassewitz                                       */
 /*               Römerstraße 52                                              */
 /*               D-70794 Filderstadt                                         */
 /* EMail:        uz@cc65.org                                                 */
@@ -474,6 +474,30 @@ void SymConDes (SymEntry* S, unsigned char AddrSize, unsigned Type, unsigned Pri
 
 
 
+void SymExportFromGlobal (SymEntry* S)
+/* Called at the end of assembly. Converts a global symbol that is defined
+ * into an export.
+ */
+{
+    /* Remove the global flag and make the symbol an export */
+    S->Flags &= ~SF_GLOBAL;
+    S->Flags |= SF_EXPORT;
+}
+
+
+
+void SymImportFromGlobal (SymEntry* S)
+/* Called at the end of assembly. Converts a global symbol that is undefined
+ * into an import.
+ */
+{
+    /* Remove the global flag and make it an import */
+    S->Flags &= ~SF_GLOBAL;
+    S->Flags |= SF_IMPORT;
+}
+
+
+
 int SymIsConst (SymEntry* S, long* Val)
 /* Return true if the given symbol has a constant value. If Val is not NULL
  * and the symbol has a constant value, store it's value there.
index 9ff6475a314ac8d8373015915719468b086df779..c9772a99edf09e43ef33c312118753384af21310 100644 (file)
@@ -6,7 +6,7 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2003 Ullrich von Bassewitz                                       */
+/* (C) 1998-2004 Ullrich von Bassewitz                                       */
 /*               Römerstraße 52                                              */
 /*               D-70794 Filderstadt                                         */
 /* EMail:        uz@cc65.org                                                 */
@@ -165,6 +165,16 @@ void SymConDes (SymEntry* Sym, unsigned char AddrSize, unsigned Type, unsigned P
  * mark the symbol as an export. Initializers may never be zero page symbols.
  */
 
+void SymExportFromGlobal (SymEntry* S);
+/* Called at the end of assembly. Converts a global symbol that is defined
+ * into an export.
+ */
+
+void SymImportFromGlobal (SymEntry* S);
+/* Called at the end of assembly. Converts a global symbol that is undefined
+ * into an import.
+ */
+
 #if defined(HAVE_INLINE)
 INLINE int SymIsDef (const SymEntry* S)
 /* Return true if the given symbol is already defined */
@@ -196,6 +206,17 @@ INLINE int SymIsImport (const SymEntry* S)
 #  define SymIsImport(S)  (((S)->Flags & SF_IMPORT) != 0)
 #endif
 
+#if defined(HAVE_INLINE)
+INLINE int SymIsExport (const SymEntry* S)
+/* Return true if the given symbol is marked as export */
+{
+    /* Check the export flag */
+    return (S->Flags & SF_EXPORT) != 0;
+}
+#else
+#  define SymIsExport(S)  (((S)->Flags & SF_EXPORT) != 0)
+#endif
+
 int SymIsConst (SymEntry* Sym, long* Val);
 /* Return true if the given symbol has a constant value. If Val is not NULL
  * and the symbol has a constant value, store it's value there.
index 5d7e864c6db5c00c29fe79efa34666210aae321b..bfc1ef9b20aaa8af6c13969d6d63569b2fbddcf4 100644 (file)
@@ -6,7 +6,7 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2003 Ullrich von Bassewitz                                       */
+/* (C) 1998-2004 Ullrich von Bassewitz                                       */
 /*               Römerstraße 52                                              */
 /*               D-70794 Filderstadt                                         */
 /* EMail:        uz@cc65.org                                                 */
@@ -520,11 +520,10 @@ void SymCheck (void)
         * already defined, otherwise mark it as import.
         */
        if (S->Flags & SF_GLOBAL) {
-           S->Flags &= ~SF_GLOBAL;
            if (S->Flags & SF_DEFINED) {
-               S->Flags |= SF_EXPORT;
+               SymExportFromGlobal (S);
            } else {
-               S->Flags |= SF_IMPORT;
+               SymImportFromGlobal (S);
            }
        }
 
@@ -584,6 +583,18 @@ void SymCheck (void)
                 ED_Init (&ED);
                 StudyExpr (S->Expr, &ED);
                 S->AddrSize = ED.AddrSize;
+                if (SymIsExport (S)) {
+                    if (S->ExportSize == ADDR_SIZE_DEFAULT) {
+                        /* Use the real export size */
+                        S->ExportSize = S->AddrSize;
+                    } else if (S->AddrSize > S->ExportSize) {
+                        /* We're exporting a symbol smaller than it actually is */
+                        PWarning (&S->Pos, 1,
+                                  "Symbol `%s' is %s but exported %s",
+                                  GetSymName (S), AddrSizeToStr (S->AddrSize),
+                                  AddrSizeToStr (S->ExportSize));
+                    }
+                }
                 ED_Done (&ED);
             }
        }