+ const ExtSym* S;
+
+ /* Write the number of exports */
+ WriteSize (D, ExtSymCount (D->Exports));
+
+ /* Write out the symbol information */
+ S = ExtSymList (D->Exports);
+ while (S) {
+
+ ExprNode* Expr;
+ unsigned char SegmentID;
+ ExprDesc ED;
+
+ /* Get the name */
+ unsigned NameIdx = ExtSymName (S);
+ const char* Name = GetString (NameIdx);
+
+ /* Get the export for this symbol. We've checked before that this
+ * export does really exist, so if it is unresolved, or if we don't
+ * find it, there is an error in the linker code.
+ */
+ Export* E = FindExport (NameIdx);
+ if (E == 0 || IsUnresolvedExport (E)) {
+ Internal ("Unresolved export `%s' found in O65WriteExports", Name);
+ }
+
+ /* Get the expression for the symbol */
+ Expr = E->Expr;
+
+ /* Recursively collect information about this expression */
+ O65ParseExpr (Expr, InitExprDesc (&ED, D), 1);
+
+ /* We cannot handle expressions with imported symbols, or expressions
+ * with more than one segment reference here
+ */
+ if (ED.ExtRef != 0 || (ED.SegRef != 0 && ED.SecRef != 0)) {
+ ED.TooComplex = 1;
+ }
+
+ /* Bail out if we cannot handle the expression */
+ if (ED.TooComplex) {
+ Error ("Expression for symbol `%s' is too complex", Name);
+ }
+
+ /* Determine the segment id for the expression */
+ if (ED.SegRef != 0 || ED.SecRef != 0) {
+
+ const SegDesc* Seg;
+
+ /* Segment or section reference */
+ if (ED.SecRef != 0) {
+ ED.SegRef = ED.SecRef->Seg; /* Get segment from section */
+ }
+
+ /* Search for the segment and map it to it's o65 segmentID */
+ Seg = O65FindSeg (D, ED.SegRef);
+ if (Seg == 0) {
+ /* For some reason, we didn't find this segment in the list of
+ * segments written to the o65 file.
+ */
+ Error ("Segment for symbol `%s' is undefined", Name);
+ }
+ SegmentID = O65SegType (Seg);
+
+ } else {
+
+ /* Absolute value */
+ SegmentID = O65SEG_ABS;
+
+ }
+
+ /* Write the name to the output file */
+ WriteData (D->F, Name, strlen (Name) + 1);
+
+ /* Output the segment id followed by the literal value */
+ Write8 (D->F, SegmentID);
+ WriteSize (D, ED.Val);
+
+ /* Next symbol */
+ S = ExtSymNext (S);
+ }