7 static reduce_name_table();
8 static convert_outname();
14 * Notice : entries in the symbol_table are converted.
18 struct outhead header;
20 long ntext = text - text_area,
21 ndata = data - data_area,
24 nrelo = relo - reloc_info;
28 nchar = string - string_area;
29 header.oh_magic = O_MAGIC;
31 header.oh_flags = HF_LINK;
33 header.oh_nrelo = nrelo;
34 header.oh_nname = nname;
35 header.oh_nemit = ntext + ndata;
36 header.oh_nchar = nchar;
42 sect.os_foff = OFF_EMIT( header);
48 sect.os_base = 20 + ntext;
50 sect.os_foff = OFF_EMIT( header) + ntext;
56 sect.os_base = 20 + ntext;
58 sect.os_foff = OFF_EMIT( header) + ntext;
64 sect.os_base = 20 + ntext + ndata;
66 sect.os_foff = OFF_EMIT( header) + ntext + ndata;
73 wr_emit( text_area, ntext);
75 wr_emit( data_area, ndata);
77 wr_relo( reloc_info, nrelo);
79 convert_outname( &header);
80 wr_name( symbol_table, nname);
82 wr_string( string_area, nchar);
89 * Reduce the name table size. This is done by first marking
90 * the name-table entries that are needed for relocation, then
91 * removing the entries that are compiler-generated and not
92 * needed for relocation, while remembering how many entries were
93 * removed at each point, and then updating the relocation info.
94 * After that, the string table is reduced.
97 #define S_NEEDED S_MOD
98 #define removable(nm) (!(nm->on_type & (S_NEEDED|S_STB)) && *(nm->on_foff+string_area) == GENLAB)
100 register int *diff_index =
101 (int *) Malloc((unsigned)(nname + 1) * sizeof(int));
102 register struct outrelo *rp = reloc_info;
103 register struct outname *np;
106 register char *p, *q;
109 for (i = 0; i < nrelo; i++) {
110 if (symbol_table[rp->or_nami].on_valu == -1 ||
111 (symbol_table[rp->or_nami].on_type & S_COM)) {
112 symbol_table[rp->or_nami].on_type |= S_NEEDED;
117 for (i = 0, np = symbol_table; i < nname; i++, np++) {
118 diff_index[i] = diff_index[i-1];
122 if ((np->on_type & S_TYP) == S_CRS) {
123 struct outname *n = &symbol_table[(int) np->on_valu];
124 if (! (n->on_type & S_COM)) {
125 np->on_type &= ~S_TYP;
126 np->on_type |= (n->on_type & S_TYP);
127 np->on_valu = n->on_valu;
133 for (i = 0; i < nrelo; i++) {
134 symbol_table[rp->or_nami].on_type &= ~S_NEEDED;
135 rp->or_nami -= diff_index[rp->or_nami];
138 for (i = 0, np = symbol_table; i < nname; i++, np++) {
139 if ((np->on_type & S_TYP) == S_CRS) {
140 np->on_valu -= diff_index[(int) np->on_valu];
142 if (diff_index[i] && diff_index[i] == diff_index[i-1]) {
143 symbol_table[i - diff_index[i]] = *np;
146 nname -= diff_index[nname - 1];
148 free((char *)(diff_index-1));
150 new_str = q = Malloc((unsigned)(string - string_area));
151 for (i = 0, np = symbol_table; i < nname; i++, np++) {
152 p = np->on_foff + string_area;
153 np->on_foff = q - new_str;
154 while (*q++ = *p) p++;
157 string_area = new_str;
159 for (i = 0, np = symbol_table; i < nname; i++, np++) {
160 if ((np->on_type & S_TYP) == S_CRS) {
161 /* replace by reference to string */
162 np->on_valu = symbol_table[(int) np->on_valu].on_foff;
169 fprint( STDERR, "write failed\n");
175 convert_outname( header)
176 struct outhead *header;
179 register struct outname *np;
180 register long l = OFF_CHAR(*header);
182 for (i = 0, np = symbol_table; i < nname; i++, np++) {
184 if ((np->on_type & S_TYP) == S_CRS) {