+ sy->senv = scount++;
+
+ if (buf != NULL)
+ buf = construct(buf, sy, 0);
+ }
+ }
+
+ return scount;
+}
+
+
+//
+// Custom version of sy_assign for ELF .o files.
+// The order that the symbols should be dumped is different.
+// (globals must be explicitly at the end of the table)
+//
+// N.B.: It should be possible to merge this with sy_assign, as there's nothing
+// really ELF specific in here, other than the "globals go at the end of
+// the queue" thing, which doesn't break the others. :-P
+uint32_t sy_assign_ELF(uint8_t * buf, uint8_t *(* construct)())
+{
+ uint16_t scount = 0;
+
+// if (construct == (uint8_t *(*)())constr_elfsymtab)
+// if (buf == NULL)
+ {
+ // Append all symbols not appearing on the .sdecl list to the end of
+ // the .sdecl list
+ for(SYM * sy=sorder; sy!=NULL; sy=sy->sorder)
+ AddToSymbolDeclarationList(sy);
+ }
+
+ // Run through all symbols (now on the .sdecl list) and assign numbers to
+ // them. We also pick which symbols should be global or not here.
+ for(SYM * sy=sdecl; sy!=NULL; sy=sy->sdecl)
+ {
+ // Export vanilla labels (but don't make them global). An exception is
+ // made for equates, which are not exported unless they are referenced.
+ if (sy->stype == LABEL && lsym_flag
+ && (sy->sattr & (DEFINED | REFERENCED)) != 0
+ && (*sy->sname != '.')
+ && (sy->sattr & GLOBAL) == 0)
+ {
+ sy->senv = scount++;
+
+ if (buf != NULL)
+ buf = construct(buf, sy, 0);
+ }
+ }
+
+ firstglobal = scount;
+
+ // For ELF object mode run through all symbols in reference order
+ // and export all global-referenced labels. Not sure if this is
+ // required but it's here nonetheless
+
+ for(SYM * sy=sdecl; sy!=NULL; sy=sy->sdecl)
+ {
+ if ((sy->stype == LABEL)
+ && ((sy->sattr & (GLOBAL | DEFINED)) == (GLOBAL | DEFINED)
+ || (sy->sattr & (GLOBAL | REFERENCED)) == (GLOBAL | REFERENCED))
+ || (sy->sattr & COMMON))
+ {
+ sy->senv = scount++;