Skip to contentSkip to conversation

Bcc: output an import directive on external function declaration

PATCH New MFLD 1 participant 1 message Apr 11, 2015

lore
Share & tools
lore

MFLD

author
#0 lore raw

PATCH 1/1 Bcc: output an import directive on external function declaration

Hello,

This patch tries to solve the problem described in the "Question on import symbols generated by BCC <http://news.gmane.org/find-root.php?message_id=551599A4.7060804%40gmail.com>" topic (see earlier in the mailing list archive). When parsing an external function declaration, Bcc outputs an assembler import directive in the code segment. So that in the object symbol table, the external function is flagged 'T' (= symbol in code segment) in place of 'U' (= undefined segment).

Unit test result (to be compared with the one in the referenced topic):

mfld@mfldhome ~/advantech/dev86/bcc $ bcc -c -o test2.o test2.c mfld@mfldhome ~/advantech/dev86/bcc $ objdump86 test2.o OBJECTFILE 'test2.o'
MODULE 'test2'
BYTEPOS 00000038
BINLEN 0000000c
STRINGS 0025 +0013
VERSION 0.0
SEG0 0000000c

SYMS 2
SYM 0 00000000 ..E.T _main
SYM 1 00000000 ...IT _entry

text data bss dec hex filename
12 0 0 12 c test2.o

BYTECODE
SEG 0
: 55 89 e5 57 56 e8 U..WV.
RELSZ 2
DW _entry-PC
: 5e 5f 5d c3 ^_].
SEG 3

-----

bcc/declare.c +9 -1
index 1f0aae2..2fd7239 100644
@@ -834,7 +834,15 @@
         gvarsymptr->flags = DIRECTPAGE;
 #endif
         if (gvarsc == EXTERNDECL)
-        gvarsymptr->flags |= EXTERNAL;
+        {
+            gvarsymptr->flags |= EXTERNAL;
+            if (gvartype->constructor == FUNCTION)
+            {
+                /* Output an assembler import directive in code segment */
+                cseg ();
+                import (gvarname);
+            }
+        }
     }
     else
     {