Skip to content

Commit ef8e6e2

Browse files
committed
Fix a whole pile of issues related to the failed attempt to increase
the number of types of relocation possible in the object file. (Now, hopefully, working.) Also change the object serialiser/deserialiser to never try to read or write raw structures; it's way safer this way and we don't need the performance boost any more. --HG-- branch : default-branch
1 parent fd7e9f9 commit ef8e6e2

File tree

9 files changed

+27
-123
lines changed

9 files changed

+27
-123
lines changed

h/out.h

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ struct outrelo {
4343
uint16_t or_type; /* type of reference */
4444
uint16_t or_sect; /* referencing section */
4545
uint16_t or_nami; /* referenced symbol index */
46-
uint16_t _padding; /* padding for alignment */
4746
uint32_t or_addr; /* referencing address */
4847
};
4948

@@ -102,26 +101,14 @@ struct outname {
102101
reserved for debuggers
103102
*/
104103

105-
/*
106-
* structure format strings
107-
*/
108-
#if 0
109-
/* The following strings only make sense on 32-bit platforms, so we're going
110-
* to try and deprecate them. */
111-
#define SF_HEAD "22222244"
112-
#define SF_SECT "44444"
113-
#define SF_RELO "1124"
114-
#define SF_NAME "4224"
115-
#endif
116-
117104
/*
118105
* structure sizes on disk (bytes in file; add digits in SF_*)
119106
* Note! These are NOT the sizes in memory (64-bit architectures will have
120107
* a different layout).
121108
*/
122109
#define SZ_HEAD 20
123110
#define SZ_SECT 20
124-
#define SZ_RELO 8
111+
#define SZ_RELO 10
125112
#define SZ_NAME 12
126113

127114
/*

mach/proto/as/comm6.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ newrelo(s, n)
281281
return;
282282
}
283283
s &= ~S_VAR;
284-
outrelo.or_type = (char)n;
285-
outrelo.or_sect = (char)DOTTYP;
284+
outrelo.or_type = n;
285+
outrelo.or_sect = DOTTYP;
286286
#ifndef ASLD
287287
if (s == S_UND || iscomm) {
288288
assert(relonami != 0);

modules/src/object/obj.h

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,16 @@
1515
#define CHAR_UNSIGNED 0
1616
#endif
1717

18-
#if CHAR_UNSIGNED
19-
#define Xchar(ch) (ch)
20-
#else
21-
#define Xchar(ch) ((ch) & 0377)
22-
#endif
23-
24-
#if ! defined(BYTE_ORDER)
25-
#define BYTE_ORDER 0x3210
26-
#endif
18+
#define Xchar(ch) (uint32_t)(uint8_t)(ch)
2719

28-
#if (BYTE_ORDER == 0x3210 || BYTE_ORDER == 0x1032)
29-
#define uget2(c) (Xchar((c)[0]) | ((unsigned) Xchar((c)[1]) << 8))
30-
#define Xput2(i, c) (((c)[0] = (i)), ((c)[1] = (i) >> 8))
31-
#define put2(i, c) { register int j = (i); Xput2(j, c); }
32-
#else
33-
#define uget2(c) (* ((unsigned short *) (c)))
34-
#define Xput2(i, c) (* ((short *) (c)) = (i))
35-
#define put2(i, c) Xput2(i, c)
36-
#endif
3720

38-
#define get2(c) ((short) uget2(c))
21+
#define uget2(c) (Xchar((c)[0]) | (Xchar((c)[1])<<8))
22+
#define get2(c) ((int16_t) uget2(c))
23+
#define put2(i, c) (((c)[0] = i), ((c)[1] = i>>8))
3924

40-
#if BYTE_ORDER != 0x0123
41-
#define get4(c) (uget2(c) | ((long) uget2((c)+2) << 16))
42-
#define put4(l, c) { register long x=(l); \
43-
Xput2((int)x,c); \
44-
Xput2((int)(x>>16),(c)+2); \
45-
}
46-
#else
47-
#define get4(c) (* ((long *) (c)))
48-
#define put4(l, c) (* ((long *) (c)) = (l))
49-
#endif
25+
#define uget4(c) (uget2(c) | (uget2((c)+2)<<16))
26+
#define get4(c) ((int32_t) uget4(c))
27+
#define put4(i, c) (put2(i, c), put2((i)>>16, (c)+2))
5028

5129
#define SECTCNT 3 /* number of sections with own output buffer */
5230
#if BIGMACHINE

modules/src/object/rd.c

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,6 @@ rd_ohead(head)
109109
register long off;
110110

111111
OUTREAD(PARTEMIT, (char *) head, (long) SZ_HEAD);
112-
#if BYTE_ORDER == 0x0123
113-
if (sizeof(struct outhead) != SZ_HEAD)
114-
#endif
115112
{
116113
register char *c = (char *) head + (SZ_HEAD-4);
117114

@@ -157,16 +154,13 @@ rd_sect(sect, cnt)
157154
offcnt += cnt;
158155
while (cnt--) {
159156
sect--;
160-
#if BYTE_ORDER == 0x0123
161-
if (sizeof(struct outsect) != SZ_SECT)
162-
#endif
163-
{
164-
c -= 4; sect->os_lign = get4(c);
165-
c -= 4; sect->os_flen = get4(c);
166-
c -= 4; sect->os_foff = get4(c);
167-
c -= 4; sect->os_size = get4(c);
168-
c -= 4; sect->os_base = get4(c);
169-
}
157+
158+
c -= 4; sect->os_lign = get4(c);
159+
c -= 4; sect->os_flen = get4(c);
160+
c -= 4; sect->os_foff = get4(c);
161+
c -= 4; sect->os_size = get4(c);
162+
c -= 4; sect->os_base = get4(c);
163+
170164
offset[--offcnt] = sect->os_foff + rd_base;
171165
}
172166
}
@@ -197,9 +191,6 @@ rd_relo(relo, cnt)
197191
{
198192

199193
OUTREAD(PARTRELO, (char *) relo, (long) cnt * SZ_RELO);
200-
#if BYTE_ORDER == 0x0123
201-
if (sizeof(struct outrelo) != SZ_RELO)
202-
#endif
203194
{
204195
register char *c = (char *) relo + (long) cnt * SZ_RELO;
205196

@@ -208,8 +199,8 @@ rd_relo(relo, cnt)
208199
relo--;
209200
c -= 4; relo->or_addr = get4(c);
210201
c -= 2; relo->or_nami = uget2(c);
211-
relo->or_sect = *--c;
212-
relo->or_type = *--c;
202+
c -= 2; relo->or_sect = uget2(c);
203+
c -= 2; relo->or_type = uget2(c);
213204
}
214205
}
215206
}
@@ -221,9 +212,6 @@ rd_name(name, cnt)
221212
{
222213

223214
OUTREAD(PARTNAME, (char *) name, (long) cnt * SZ_NAME);
224-
#if BYTE_ORDER == 0x0123
225-
if (sizeof(struct outname) != SZ_NAME)
226-
#endif
227215
{
228216
register char *c = (char *) name + (long) cnt * SZ_NAME;
229217

modules/src/object/rd_ranlib.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ rd_ranlib(fd, ran, cnt)
1111
register long cnt;
1212
{
1313
rd_bytes(fd, (char *) ran, cnt * SZ_RAN);
14-
#if BYTE_ORDER == 0x0123
15-
if (sizeof (struct ranlib) != SZ_RAN)
16-
#endif
1714
{
1815
register char *c = (char *) ran + cnt * SZ_RAN;
1916

modules/src/object/wr.c

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ wr_ohead(head)
198198
BEGINSEEK(PARTDBUG, off);
199199
#endif
200200
}
201-
if (BYTE_ORDER != 0x0123 || sizeof(struct outhead) != SZ_HEAD)
201+
202202
{
203203
char buf[SZ_HEAD];
204204

@@ -214,7 +214,6 @@ wr_ohead(head)
214214
put4(head->oh_nchar, c);
215215
OUTWRITE(PARTEMIT, buf, (long)SZ_HEAD);
216216
}
217-
else OUTWRITE(PARTEMIT, (char *)head, (long)SZ_HEAD);
218217
}
219218

220219
void
@@ -233,9 +232,6 @@ wr_sect(sect, cnt)
233232
}
234233
sect -= cnt;
235234
}
236-
#if BYTE_ORDER == 0x0123
237-
if (sizeof(struct outsect) != SZ_SECT)
238-
#endif
239235
while (cnt)
240236
{
241237
register char *c;
@@ -259,11 +255,6 @@ wr_sect(sect, cnt)
259255
__wr_flush(&__parts[PARTEMIT]);
260256
}
261257
}
262-
#if BYTE_ORDER == 0x0123
263-
else {
264-
OUTWRITE(PARTEMIT, (char *) sect, (long) cnt * SZ_SECT);
265-
}
266-
#endif
267258
}
268259

269260
void
@@ -313,9 +304,6 @@ wr_relo(relo, cnt)
313304
unsigned int cnt;
314305
{
315306

316-
#if BYTE_ORDER == 0x0123
317-
if (sizeof(struct outrelo) != SZ_RELO)
318-
#endif
319307
while (cnt)
320308
{
321309
register char *c;
@@ -327,8 +315,8 @@ wr_relo(relo, cnt)
327315
cnt -= i;
328316
__parts[PARTRELO].cnt -= (i*SZ_RELO);
329317
while (i--) {
330-
*c++ = relo->or_type;
331-
*c++ = relo->or_sect;
318+
put2(relo->or_type, c); c += 2;
319+
put2(relo->or_sect, c); c += 2;
332320
put2(relo->or_nami, c); c += 2;
333321
put4(relo->or_addr, c); c += 4;
334322
relo++;
@@ -338,21 +326,13 @@ wr_relo(relo, cnt)
338326
__wr_flush(&__parts[PARTRELO]);
339327
}
340328
}
341-
#if BYTE_ORDER == 0x0123
342-
else {
343-
OUTWRITE(PARTRELO, (char *) relo, (long) cnt * SZ_RELO);
344-
}
345-
#endif
346329
}
347330

348331
void
349332
wr_name(name, cnt)
350333
register struct outname *name;
351334
unsigned int cnt;
352335
{
353-
#if BYTE_ORDER == 0x0123
354-
if (sizeof(struct outname) != SZ_NAME)
355-
#endif
356336
while (cnt)
357337
{
358338
register char *c;
@@ -373,12 +353,6 @@ wr_name(name, cnt)
373353
__parts[PARTNAME].pnow = c;
374354
if (cnt) __wr_flush(&__parts[PARTNAME]);
375355
}
376-
#if BYTE_ORDER == 0x0123
377-
else {
378-
OUTWRITE(PARTNAME, (char *) name, (long)cnt * SZ_NAME);
379-
}
380-
#endif
381-
382356
}
383357

384358
void

modules/src/object/wr_ranlib.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ wr_ranlib(fd, ran, cnt1)
1010
struct ranlib *ran;
1111
long cnt1;
1212
{
13-
#if BYTE_ORDER == 0x0123
14-
if (sizeof (struct ranlib) != SZ_RAN)
15-
#endif
1613
{
1714
register long cnt = cnt1;
1815
register struct ranlib *r = ran;

util/led/ack.out.5

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ struct outrelo {
150150
uint16_t or_type; /* type of reference */
151151
uint16_t or_sect; /* referencing section */
152152
uint16_t or_nami; /* referenced symbol index */
153-
uint16_t _padding; /* padding for alignment; ignore */
154153
uint32_t or_addr; /* referencing address */
155154
};
156155
.fi
@@ -285,15 +284,6 @@ object file.
285284
.br
286285
The following miscellaneous defines might come in handy when reading
287286
object files:
288-
.PP
289-
.nf
290-
/*
291-
* structure format strings
292-
*/
293-
#define SF_HEAD "22222244"
294-
#define SF_SECT "44444"
295-
#define SF_RELO "1124"
296-
#define SF_NAME "4224"
297287
.fi
298288
.PP
299289
.nf
@@ -302,7 +292,7 @@ object files:
302292
*/
303293
#define SZ_HEAD 20
304294
#define SZ_SECT 20
305-
#define SZ_RELO 8
295+
#define SZ_RELO 10
306296
#define SZ_NAME 12
307297
.fi
308298
.PP

util/led/relocate.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,7 @@ static long get_vc4_valu(char* addr)
108108
* The bits in type indicate how many bytes the value occupies and what
109109
* significance should be attributed to each byte.
110110
*/
111-
static long
112-
getvalu(addr, type)
113-
char addr[];
114-
char type;
111+
static long getvalu(char* addr, uint16_t type)
115112
{
116113
switch (type & RELSZ) {
117114
case RELO1:
@@ -127,7 +124,7 @@ getvalu(addr, type)
127124
case RELOVC4:
128125
return get_vc4_valu(addr);
129126
default:
130-
fatal("bad relocation size");
127+
fatal("bad relocation type %x", type & RELSZ);
131128
}
132129
/* NOTREACHED */
133130
}
@@ -228,11 +225,7 @@ static void put_vc4_valu(char* addr, long value)
228225
* significance should be attributed to each byte.
229226
* We do not check for overflow.
230227
*/
231-
static
232-
putvalu(valu, addr, type)
233-
long valu;
234-
char addr[];
235-
char type;
228+
static putvalu(long valu, char* addr, uint16_t type)
236229
{
237230

238231
switch (type & RELSZ) {
@@ -259,7 +252,7 @@ putvalu(valu, addr, type)
259252
put_vc4_valu(addr, valu);
260253
break;
261254
default:
262-
fatal("bad relocation size");
255+
fatal("bad relocation type %x", type & RELSZ);
263256
}
264257
}
265258

0 commit comments

Comments
 (0)