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
This commit is contained in:
parent
fd7e9f9046
commit
ef8e6e25e0
15
h/out.h
15
h/out.h
|
@ -43,7 +43,6 @@ struct outrelo {
|
||||||
uint16_t or_type; /* type of reference */
|
uint16_t or_type; /* type of reference */
|
||||||
uint16_t or_sect; /* referencing section */
|
uint16_t or_sect; /* referencing section */
|
||||||
uint16_t or_nami; /* referenced symbol index */
|
uint16_t or_nami; /* referenced symbol index */
|
||||||
uint16_t _padding; /* padding for alignment */
|
|
||||||
uint32_t or_addr; /* referencing address */
|
uint32_t or_addr; /* referencing address */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -102,18 +101,6 @@ struct outname {
|
||||||
reserved for debuggers
|
reserved for debuggers
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
* structure format strings
|
|
||||||
*/
|
|
||||||
#if 0
|
|
||||||
/* The following strings only make sense on 32-bit platforms, so we're going
|
|
||||||
* to try and deprecate them. */
|
|
||||||
#define SF_HEAD "22222244"
|
|
||||||
#define SF_SECT "44444"
|
|
||||||
#define SF_RELO "1124"
|
|
||||||
#define SF_NAME "4224"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* structure sizes on disk (bytes in file; add digits in SF_*)
|
* structure sizes on disk (bytes in file; add digits in SF_*)
|
||||||
* Note! These are NOT the sizes in memory (64-bit architectures will have
|
* Note! These are NOT the sizes in memory (64-bit architectures will have
|
||||||
|
@ -121,7 +108,7 @@ struct outname {
|
||||||
*/
|
*/
|
||||||
#define SZ_HEAD 20
|
#define SZ_HEAD 20
|
||||||
#define SZ_SECT 20
|
#define SZ_SECT 20
|
||||||
#define SZ_RELO 8
|
#define SZ_RELO 10
|
||||||
#define SZ_NAME 12
|
#define SZ_NAME 12
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -281,8 +281,8 @@ newrelo(s, n)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
s &= ~S_VAR;
|
s &= ~S_VAR;
|
||||||
outrelo.or_type = (char)n;
|
outrelo.or_type = n;
|
||||||
outrelo.or_sect = (char)DOTTYP;
|
outrelo.or_sect = DOTTYP;
|
||||||
#ifndef ASLD
|
#ifndef ASLD
|
||||||
if (s == S_UND || iscomm) {
|
if (s == S_UND || iscomm) {
|
||||||
assert(relonami != 0);
|
assert(relonami != 0);
|
||||||
|
|
|
@ -15,38 +15,16 @@
|
||||||
#define CHAR_UNSIGNED 0
|
#define CHAR_UNSIGNED 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CHAR_UNSIGNED
|
#define Xchar(ch) (uint32_t)(uint8_t)(ch)
|
||||||
#define Xchar(ch) (ch)
|
|
||||||
#else
|
|
||||||
#define Xchar(ch) ((ch) & 0377)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if ! defined(BYTE_ORDER)
|
|
||||||
#define BYTE_ORDER 0x3210
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (BYTE_ORDER == 0x3210 || BYTE_ORDER == 0x1032)
|
#define uget2(c) (Xchar((c)[0]) | (Xchar((c)[1])<<8))
|
||||||
#define uget2(c) (Xchar((c)[0]) | ((unsigned) Xchar((c)[1]) << 8))
|
#define get2(c) ((int16_t) uget2(c))
|
||||||
#define Xput2(i, c) (((c)[0] = (i)), ((c)[1] = (i) >> 8))
|
#define put2(i, c) (((c)[0] = i), ((c)[1] = i>>8))
|
||||||
#define put2(i, c) { register int j = (i); Xput2(j, c); }
|
|
||||||
#else
|
|
||||||
#define uget2(c) (* ((unsigned short *) (c)))
|
|
||||||
#define Xput2(i, c) (* ((short *) (c)) = (i))
|
|
||||||
#define put2(i, c) Xput2(i, c)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define get2(c) ((short) uget2(c))
|
#define uget4(c) (uget2(c) | (uget2((c)+2)<<16))
|
||||||
|
#define get4(c) ((int32_t) uget4(c))
|
||||||
#if BYTE_ORDER != 0x0123
|
#define put4(i, c) (put2(i, c), put2((i)>>16, (c)+2))
|
||||||
#define get4(c) (uget2(c) | ((long) uget2((c)+2) << 16))
|
|
||||||
#define put4(l, c) { register long x=(l); \
|
|
||||||
Xput2((int)x,c); \
|
|
||||||
Xput2((int)(x>>16),(c)+2); \
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#define get4(c) (* ((long *) (c)))
|
|
||||||
#define put4(l, c) (* ((long *) (c)) = (l))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define SECTCNT 3 /* number of sections with own output buffer */
|
#define SECTCNT 3 /* number of sections with own output buffer */
|
||||||
#if BIGMACHINE
|
#if BIGMACHINE
|
||||||
|
|
|
@ -109,9 +109,6 @@ rd_ohead(head)
|
||||||
register long off;
|
register long off;
|
||||||
|
|
||||||
OUTREAD(PARTEMIT, (char *) head, (long) SZ_HEAD);
|
OUTREAD(PARTEMIT, (char *) head, (long) SZ_HEAD);
|
||||||
#if BYTE_ORDER == 0x0123
|
|
||||||
if (sizeof(struct outhead) != SZ_HEAD)
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
register char *c = (char *) head + (SZ_HEAD-4);
|
register char *c = (char *) head + (SZ_HEAD-4);
|
||||||
|
|
||||||
|
@ -157,16 +154,13 @@ rd_sect(sect, cnt)
|
||||||
offcnt += cnt;
|
offcnt += cnt;
|
||||||
while (cnt--) {
|
while (cnt--) {
|
||||||
sect--;
|
sect--;
|
||||||
#if BYTE_ORDER == 0x0123
|
|
||||||
if (sizeof(struct outsect) != SZ_SECT)
|
c -= 4; sect->os_lign = get4(c);
|
||||||
#endif
|
c -= 4; sect->os_flen = get4(c);
|
||||||
{
|
c -= 4; sect->os_foff = get4(c);
|
||||||
c -= 4; sect->os_lign = get4(c);
|
c -= 4; sect->os_size = get4(c);
|
||||||
c -= 4; sect->os_flen = get4(c);
|
c -= 4; sect->os_base = get4(c);
|
||||||
c -= 4; sect->os_foff = get4(c);
|
|
||||||
c -= 4; sect->os_size = get4(c);
|
|
||||||
c -= 4; sect->os_base = get4(c);
|
|
||||||
}
|
|
||||||
offset[--offcnt] = sect->os_foff + rd_base;
|
offset[--offcnt] = sect->os_foff + rd_base;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -197,9 +191,6 @@ rd_relo(relo, cnt)
|
||||||
{
|
{
|
||||||
|
|
||||||
OUTREAD(PARTRELO, (char *) relo, (long) cnt * SZ_RELO);
|
OUTREAD(PARTRELO, (char *) relo, (long) cnt * SZ_RELO);
|
||||||
#if BYTE_ORDER == 0x0123
|
|
||||||
if (sizeof(struct outrelo) != SZ_RELO)
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
register char *c = (char *) relo + (long) cnt * SZ_RELO;
|
register char *c = (char *) relo + (long) cnt * SZ_RELO;
|
||||||
|
|
||||||
|
@ -208,8 +199,8 @@ rd_relo(relo, cnt)
|
||||||
relo--;
|
relo--;
|
||||||
c -= 4; relo->or_addr = get4(c);
|
c -= 4; relo->or_addr = get4(c);
|
||||||
c -= 2; relo->or_nami = uget2(c);
|
c -= 2; relo->or_nami = uget2(c);
|
||||||
relo->or_sect = *--c;
|
c -= 2; relo->or_sect = uget2(c);
|
||||||
relo->or_type = *--c;
|
c -= 2; relo->or_type = uget2(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -221,9 +212,6 @@ rd_name(name, cnt)
|
||||||
{
|
{
|
||||||
|
|
||||||
OUTREAD(PARTNAME, (char *) name, (long) cnt * SZ_NAME);
|
OUTREAD(PARTNAME, (char *) name, (long) cnt * SZ_NAME);
|
||||||
#if BYTE_ORDER == 0x0123
|
|
||||||
if (sizeof(struct outname) != SZ_NAME)
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
register char *c = (char *) name + (long) cnt * SZ_NAME;
|
register char *c = (char *) name + (long) cnt * SZ_NAME;
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,6 @@ rd_ranlib(fd, ran, cnt)
|
||||||
register long cnt;
|
register long cnt;
|
||||||
{
|
{
|
||||||
rd_bytes(fd, (char *) ran, cnt * SZ_RAN);
|
rd_bytes(fd, (char *) ran, cnt * SZ_RAN);
|
||||||
#if BYTE_ORDER == 0x0123
|
|
||||||
if (sizeof (struct ranlib) != SZ_RAN)
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
register char *c = (char *) ran + cnt * SZ_RAN;
|
register char *c = (char *) ran + cnt * SZ_RAN;
|
||||||
|
|
||||||
|
|
|
@ -198,7 +198,7 @@ wr_ohead(head)
|
||||||
BEGINSEEK(PARTDBUG, off);
|
BEGINSEEK(PARTDBUG, off);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (BYTE_ORDER != 0x0123 || sizeof(struct outhead) != SZ_HEAD)
|
|
||||||
{
|
{
|
||||||
char buf[SZ_HEAD];
|
char buf[SZ_HEAD];
|
||||||
|
|
||||||
|
@ -214,7 +214,6 @@ wr_ohead(head)
|
||||||
put4(head->oh_nchar, c);
|
put4(head->oh_nchar, c);
|
||||||
OUTWRITE(PARTEMIT, buf, (long)SZ_HEAD);
|
OUTWRITE(PARTEMIT, buf, (long)SZ_HEAD);
|
||||||
}
|
}
|
||||||
else OUTWRITE(PARTEMIT, (char *)head, (long)SZ_HEAD);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -233,9 +232,6 @@ wr_sect(sect, cnt)
|
||||||
}
|
}
|
||||||
sect -= cnt;
|
sect -= cnt;
|
||||||
}
|
}
|
||||||
#if BYTE_ORDER == 0x0123
|
|
||||||
if (sizeof(struct outsect) != SZ_SECT)
|
|
||||||
#endif
|
|
||||||
while (cnt)
|
while (cnt)
|
||||||
{
|
{
|
||||||
register char *c;
|
register char *c;
|
||||||
|
@ -259,11 +255,6 @@ wr_sect(sect, cnt)
|
||||||
__wr_flush(&__parts[PARTEMIT]);
|
__wr_flush(&__parts[PARTEMIT]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if BYTE_ORDER == 0x0123
|
|
||||||
else {
|
|
||||||
OUTWRITE(PARTEMIT, (char *) sect, (long) cnt * SZ_SECT);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -313,9 +304,6 @@ wr_relo(relo, cnt)
|
||||||
unsigned int cnt;
|
unsigned int cnt;
|
||||||
{
|
{
|
||||||
|
|
||||||
#if BYTE_ORDER == 0x0123
|
|
||||||
if (sizeof(struct outrelo) != SZ_RELO)
|
|
||||||
#endif
|
|
||||||
while (cnt)
|
while (cnt)
|
||||||
{
|
{
|
||||||
register char *c;
|
register char *c;
|
||||||
|
@ -327,8 +315,8 @@ wr_relo(relo, cnt)
|
||||||
cnt -= i;
|
cnt -= i;
|
||||||
__parts[PARTRELO].cnt -= (i*SZ_RELO);
|
__parts[PARTRELO].cnt -= (i*SZ_RELO);
|
||||||
while (i--) {
|
while (i--) {
|
||||||
*c++ = relo->or_type;
|
put2(relo->or_type, c); c += 2;
|
||||||
*c++ = relo->or_sect;
|
put2(relo->or_sect, c); c += 2;
|
||||||
put2(relo->or_nami, c); c += 2;
|
put2(relo->or_nami, c); c += 2;
|
||||||
put4(relo->or_addr, c); c += 4;
|
put4(relo->or_addr, c); c += 4;
|
||||||
relo++;
|
relo++;
|
||||||
|
@ -338,11 +326,6 @@ wr_relo(relo, cnt)
|
||||||
__wr_flush(&__parts[PARTRELO]);
|
__wr_flush(&__parts[PARTRELO]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if BYTE_ORDER == 0x0123
|
|
||||||
else {
|
|
||||||
OUTWRITE(PARTRELO, (char *) relo, (long) cnt * SZ_RELO);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -350,9 +333,6 @@ wr_name(name, cnt)
|
||||||
register struct outname *name;
|
register struct outname *name;
|
||||||
unsigned int cnt;
|
unsigned int cnt;
|
||||||
{
|
{
|
||||||
#if BYTE_ORDER == 0x0123
|
|
||||||
if (sizeof(struct outname) != SZ_NAME)
|
|
||||||
#endif
|
|
||||||
while (cnt)
|
while (cnt)
|
||||||
{
|
{
|
||||||
register char *c;
|
register char *c;
|
||||||
|
@ -373,12 +353,6 @@ wr_name(name, cnt)
|
||||||
__parts[PARTNAME].pnow = c;
|
__parts[PARTNAME].pnow = c;
|
||||||
if (cnt) __wr_flush(&__parts[PARTNAME]);
|
if (cnt) __wr_flush(&__parts[PARTNAME]);
|
||||||
}
|
}
|
||||||
#if BYTE_ORDER == 0x0123
|
|
||||||
else {
|
|
||||||
OUTWRITE(PARTNAME, (char *) name, (long)cnt * SZ_NAME);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -10,9 +10,6 @@ wr_ranlib(fd, ran, cnt1)
|
||||||
struct ranlib *ran;
|
struct ranlib *ran;
|
||||||
long cnt1;
|
long cnt1;
|
||||||
{
|
{
|
||||||
#if BYTE_ORDER == 0x0123
|
|
||||||
if (sizeof (struct ranlib) != SZ_RAN)
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
register long cnt = cnt1;
|
register long cnt = cnt1;
|
||||||
register struct ranlib *r = ran;
|
register struct ranlib *r = ran;
|
||||||
|
|
|
@ -150,7 +150,6 @@ struct outrelo {
|
||||||
uint16_t or_type; /* type of reference */
|
uint16_t or_type; /* type of reference */
|
||||||
uint16_t or_sect; /* referencing section */
|
uint16_t or_sect; /* referencing section */
|
||||||
uint16_t or_nami; /* referenced symbol index */
|
uint16_t or_nami; /* referenced symbol index */
|
||||||
uint16_t _padding; /* padding for alignment; ignore */
|
|
||||||
uint32_t or_addr; /* referencing address */
|
uint32_t or_addr; /* referencing address */
|
||||||
};
|
};
|
||||||
.fi
|
.fi
|
||||||
|
@ -285,15 +284,6 @@ object file.
|
||||||
.br
|
.br
|
||||||
The following miscellaneous defines might come in handy when reading
|
The following miscellaneous defines might come in handy when reading
|
||||||
object files:
|
object files:
|
||||||
.PP
|
|
||||||
.nf
|
|
||||||
/*
|
|
||||||
* structure format strings
|
|
||||||
*/
|
|
||||||
#define SF_HEAD "22222244"
|
|
||||||
#define SF_SECT "44444"
|
|
||||||
#define SF_RELO "1124"
|
|
||||||
#define SF_NAME "4224"
|
|
||||||
.fi
|
.fi
|
||||||
.PP
|
.PP
|
||||||
.nf
|
.nf
|
||||||
|
@ -302,7 +292,7 @@ object files:
|
||||||
*/
|
*/
|
||||||
#define SZ_HEAD 20
|
#define SZ_HEAD 20
|
||||||
#define SZ_SECT 20
|
#define SZ_SECT 20
|
||||||
#define SZ_RELO 8
|
#define SZ_RELO 10
|
||||||
#define SZ_NAME 12
|
#define SZ_NAME 12
|
||||||
.fi
|
.fi
|
||||||
.PP
|
.PP
|
||||||
|
|
|
@ -108,10 +108,7 @@ static long get_vc4_valu(char* addr)
|
||||||
* The bits in type indicate how many bytes the value occupies and what
|
* The bits in type indicate how many bytes the value occupies and what
|
||||||
* significance should be attributed to each byte.
|
* significance should be attributed to each byte.
|
||||||
*/
|
*/
|
||||||
static long
|
static long getvalu(char* addr, uint16_t type)
|
||||||
getvalu(addr, type)
|
|
||||||
char addr[];
|
|
||||||
char type;
|
|
||||||
{
|
{
|
||||||
switch (type & RELSZ) {
|
switch (type & RELSZ) {
|
||||||
case RELO1:
|
case RELO1:
|
||||||
|
@ -127,7 +124,7 @@ getvalu(addr, type)
|
||||||
case RELOVC4:
|
case RELOVC4:
|
||||||
return get_vc4_valu(addr);
|
return get_vc4_valu(addr);
|
||||||
default:
|
default:
|
||||||
fatal("bad relocation size");
|
fatal("bad relocation type %x", type & RELSZ);
|
||||||
}
|
}
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
|
@ -228,11 +225,7 @@ static void put_vc4_valu(char* addr, long value)
|
||||||
* significance should be attributed to each byte.
|
* significance should be attributed to each byte.
|
||||||
* We do not check for overflow.
|
* We do not check for overflow.
|
||||||
*/
|
*/
|
||||||
static
|
static putvalu(long valu, char* addr, uint16_t type)
|
||||||
putvalu(valu, addr, type)
|
|
||||||
long valu;
|
|
||||||
char addr[];
|
|
||||||
char type;
|
|
||||||
{
|
{
|
||||||
|
|
||||||
switch (type & RELSZ) {
|
switch (type & RELSZ) {
|
||||||
|
@ -259,7 +252,7 @@ putvalu(valu, addr, type)
|
||||||
put_vc4_valu(addr, valu);
|
put_vc4_valu(addr, valu);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fatal("bad relocation size");
|
fatal("bad relocation type %x", type & RELSZ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue