From ef8e6e25e035ac91fc8f89dc54eaa1eb3e253225 Mon Sep 17 00:00:00 2001 From: David Given Date: Fri, 18 Mar 2016 21:46:55 +0100 Subject: [PATCH] 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 --- h/out.h | 15 +------------- mach/proto/as/comm6.c | 4 ++-- modules/src/object/obj.h | 36 +++++++--------------------------- modules/src/object/rd.c | 30 +++++++++------------------- modules/src/object/rd_ranlib.c | 3 --- modules/src/object/wr.c | 32 +++--------------------------- modules/src/object/wr_ranlib.c | 3 --- util/led/ack.out.5 | 12 +----------- util/led/relocate.c | 15 ++++---------- 9 files changed, 27 insertions(+), 123 deletions(-) diff --git a/h/out.h b/h/out.h index 16c22be51..30cb6ba69 100644 --- a/h/out.h +++ b/h/out.h @@ -43,7 +43,6 @@ struct outrelo { uint16_t or_type; /* type of reference */ uint16_t or_sect; /* referencing section */ uint16_t or_nami; /* referenced symbol index */ - uint16_t _padding; /* padding for alignment */ uint32_t or_addr; /* referencing address */ }; @@ -102,18 +101,6 @@ struct outname { 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_*) * 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_SECT 20 -#define SZ_RELO 8 +#define SZ_RELO 10 #define SZ_NAME 12 /* diff --git a/mach/proto/as/comm6.c b/mach/proto/as/comm6.c index 5c51d34e5..f5bd87f39 100644 --- a/mach/proto/as/comm6.c +++ b/mach/proto/as/comm6.c @@ -281,8 +281,8 @@ newrelo(s, n) return; } s &= ~S_VAR; - outrelo.or_type = (char)n; - outrelo.or_sect = (char)DOTTYP; + outrelo.or_type = n; + outrelo.or_sect = DOTTYP; #ifndef ASLD if (s == S_UND || iscomm) { assert(relonami != 0); diff --git a/modules/src/object/obj.h b/modules/src/object/obj.h index a725ed5bd..8f7fd8d32 100644 --- a/modules/src/object/obj.h +++ b/modules/src/object/obj.h @@ -15,38 +15,16 @@ #define CHAR_UNSIGNED 0 #endif -#if CHAR_UNSIGNED -#define Xchar(ch) (ch) -#else -#define Xchar(ch) ((ch) & 0377) -#endif +#define Xchar(ch) (uint32_t)(uint8_t)(ch) -#if ! defined(BYTE_ORDER) -#define BYTE_ORDER 0x3210 -#endif -#if (BYTE_ORDER == 0x3210 || BYTE_ORDER == 0x1032) -#define uget2(c) (Xchar((c)[0]) | ((unsigned) Xchar((c)[1]) << 8)) -#define Xput2(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 uget2(c) (Xchar((c)[0]) | (Xchar((c)[1])<<8)) +#define get2(c) ((int16_t) uget2(c)) +#define put2(i, c) (((c)[0] = i), ((c)[1] = i>>8)) -#define get2(c) ((short) uget2(c)) - -#if BYTE_ORDER != 0x0123 -#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 uget4(c) (uget2(c) | (uget2((c)+2)<<16)) +#define get4(c) ((int32_t) uget4(c)) +#define put4(i, c) (put2(i, c), put2((i)>>16, (c)+2)) #define SECTCNT 3 /* number of sections with own output buffer */ #if BIGMACHINE diff --git a/modules/src/object/rd.c b/modules/src/object/rd.c index 55f67bb8d..7790a4720 100644 --- a/modules/src/object/rd.c +++ b/modules/src/object/rd.c @@ -109,9 +109,6 @@ rd_ohead(head) register long off; 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); @@ -157,16 +154,13 @@ rd_sect(sect, cnt) offcnt += cnt; while (cnt--) { sect--; -#if BYTE_ORDER == 0x0123 - if (sizeof(struct outsect) != SZ_SECT) -#endif - { - c -= 4; sect->os_lign = get4(c); - c -= 4; sect->os_flen = get4(c); - c -= 4; sect->os_foff = get4(c); - c -= 4; sect->os_size = get4(c); - c -= 4; sect->os_base = get4(c); - } + + c -= 4; sect->os_lign = get4(c); + c -= 4; sect->os_flen = 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; } } @@ -197,9 +191,6 @@ rd_relo(relo, cnt) { 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; @@ -208,8 +199,8 @@ rd_relo(relo, cnt) relo--; c -= 4; relo->or_addr = get4(c); c -= 2; relo->or_nami = uget2(c); - relo->or_sect = *--c; - relo->or_type = *--c; + c -= 2; relo->or_sect = uget2(c); + c -= 2; relo->or_type = uget2(c); } } } @@ -221,9 +212,6 @@ rd_name(name, cnt) { 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; diff --git a/modules/src/object/rd_ranlib.c b/modules/src/object/rd_ranlib.c index 63bc6964a..0a3d4d760 100644 --- a/modules/src/object/rd_ranlib.c +++ b/modules/src/object/rd_ranlib.c @@ -11,9 +11,6 @@ rd_ranlib(fd, ran, cnt) register long cnt; { 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; diff --git a/modules/src/object/wr.c b/modules/src/object/wr.c index 53267d0ee..20e5132f2 100644 --- a/modules/src/object/wr.c +++ b/modules/src/object/wr.c @@ -198,7 +198,7 @@ wr_ohead(head) BEGINSEEK(PARTDBUG, off); #endif } - if (BYTE_ORDER != 0x0123 || sizeof(struct outhead) != SZ_HEAD) + { char buf[SZ_HEAD]; @@ -214,7 +214,6 @@ wr_ohead(head) put4(head->oh_nchar, c); OUTWRITE(PARTEMIT, buf, (long)SZ_HEAD); } - else OUTWRITE(PARTEMIT, (char *)head, (long)SZ_HEAD); } void @@ -233,9 +232,6 @@ wr_sect(sect, cnt) } sect -= cnt; } -#if BYTE_ORDER == 0x0123 - if (sizeof(struct outsect) != SZ_SECT) -#endif while (cnt) { register char *c; @@ -259,11 +255,6 @@ wr_sect(sect, cnt) __wr_flush(&__parts[PARTEMIT]); } } -#if BYTE_ORDER == 0x0123 - else { - OUTWRITE(PARTEMIT, (char *) sect, (long) cnt * SZ_SECT); - } -#endif } void @@ -313,9 +304,6 @@ wr_relo(relo, cnt) unsigned int cnt; { -#if BYTE_ORDER == 0x0123 - if (sizeof(struct outrelo) != SZ_RELO) -#endif while (cnt) { register char *c; @@ -327,8 +315,8 @@ wr_relo(relo, cnt) cnt -= i; __parts[PARTRELO].cnt -= (i*SZ_RELO); while (i--) { - *c++ = relo->or_type; - *c++ = relo->or_sect; + put2(relo->or_type, c); c += 2; + put2(relo->or_sect, c); c += 2; put2(relo->or_nami, c); c += 2; put4(relo->or_addr, c); c += 4; relo++; @@ -338,11 +326,6 @@ wr_relo(relo, cnt) __wr_flush(&__parts[PARTRELO]); } } -#if BYTE_ORDER == 0x0123 - else { - OUTWRITE(PARTRELO, (char *) relo, (long) cnt * SZ_RELO); - } -#endif } void @@ -350,9 +333,6 @@ wr_name(name, cnt) register struct outname *name; unsigned int cnt; { -#if BYTE_ORDER == 0x0123 - if (sizeof(struct outname) != SZ_NAME) -#endif while (cnt) { register char *c; @@ -373,12 +353,6 @@ wr_name(name, cnt) __parts[PARTNAME].pnow = c; if (cnt) __wr_flush(&__parts[PARTNAME]); } -#if BYTE_ORDER == 0x0123 - else { - OUTWRITE(PARTNAME, (char *) name, (long)cnt * SZ_NAME); - } -#endif - } void diff --git a/modules/src/object/wr_ranlib.c b/modules/src/object/wr_ranlib.c index f55cef3cd..91274d71c 100644 --- a/modules/src/object/wr_ranlib.c +++ b/modules/src/object/wr_ranlib.c @@ -10,9 +10,6 @@ wr_ranlib(fd, ran, cnt1) struct ranlib *ran; long cnt1; { -#if BYTE_ORDER == 0x0123 - if (sizeof (struct ranlib) != SZ_RAN) -#endif { register long cnt = cnt1; register struct ranlib *r = ran; diff --git a/util/led/ack.out.5 b/util/led/ack.out.5 index 3932a7f25..8e34c1a06 100644 --- a/util/led/ack.out.5 +++ b/util/led/ack.out.5 @@ -150,7 +150,6 @@ struct outrelo { uint16_t or_type; /* type of reference */ uint16_t or_sect; /* referencing section */ uint16_t or_nami; /* referenced symbol index */ - uint16_t _padding; /* padding for alignment; ignore */ uint32_t or_addr; /* referencing address */ }; .fi @@ -285,15 +284,6 @@ object file. .br The following miscellaneous defines might come in handy when reading object files: -.PP -.nf -/* - * structure format strings - */ -#define SF_HEAD "22222244" -#define SF_SECT "44444" -#define SF_RELO "1124" -#define SF_NAME "4224" .fi .PP .nf @@ -302,7 +292,7 @@ object files: */ #define SZ_HEAD 20 #define SZ_SECT 20 -#define SZ_RELO 8 +#define SZ_RELO 10 #define SZ_NAME 12 .fi .PP diff --git a/util/led/relocate.c b/util/led/relocate.c index 3cc9ff904..b49e1c549 100644 --- a/util/led/relocate.c +++ b/util/led/relocate.c @@ -108,10 +108,7 @@ static long get_vc4_valu(char* addr) * The bits in type indicate how many bytes the value occupies and what * significance should be attributed to each byte. */ -static long -getvalu(addr, type) - char addr[]; - char type; +static long getvalu(char* addr, uint16_t type) { switch (type & RELSZ) { case RELO1: @@ -127,7 +124,7 @@ getvalu(addr, type) case RELOVC4: return get_vc4_valu(addr); default: - fatal("bad relocation size"); + fatal("bad relocation type %x", type & RELSZ); } /* NOTREACHED */ } @@ -228,11 +225,7 @@ static void put_vc4_valu(char* addr, long value) * significance should be attributed to each byte. * We do not check for overflow. */ -static -putvalu(valu, addr, type) - long valu; - char addr[]; - char type; +static putvalu(long valu, char* addr, uint16_t type) { switch (type & RELSZ) { @@ -259,7 +252,7 @@ putvalu(valu, addr, type) put_vc4_valu(addr, valu); break; default: - fatal("bad relocation size"); + fatal("bad relocation type %x", type & RELSZ); } }