X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=rmac;a=blobdiff_plain;f=mark.c;h=7378c8a6916aee2d8804c39901c042e39908e93b;hp=7495c71c1eeecf571b26b7031dba32ae97495495;hb=582df8950c285e1746d0c4a9e3ead6545c962dc8;hpb=d1f5f1caccb26da6a3da7fc00b94b79000a55302 diff --git a/mark.c b/mark.c index 7495c71..7378c8a 100644 --- a/mark.c +++ b/mark.c @@ -377,6 +377,12 @@ printf(" validsegment: raddr = $%08X\n", loc); if (w & MMOVEI) rflag |= 0x00000001; + // This tells the linker to do a WORD relocation (otherwise it + // defaults to doing a LONG, throwing things off for WORD sized + // fixups) + if (!(w & MLONG)) + rflag |= 0x00000002; + if (symbol != NULL) { // Deposit external reference @@ -414,7 +420,7 @@ printf(" validsegment(3): rflag = $%08X\n", rflag); if (from == DATA) dp += tsize; - uint32_t diff = GETBE32(dp, 0); + uint32_t diff = (rflag & 0x02 ? GETBE16(dp, 0) : GETBE32(dp, 0)); DEBUG printf("diff=%uX ==> ", diff); #ifdef DEBUG_IMAGE_MARKING printf(" validsegment(4): diff = $%08X --> ", diff); @@ -430,7 +436,21 @@ printf(" validsegment(4): diff = $%08X --> ", diff); if (rflag & 0x01) diff = WORDSWAP32(diff); - SETBE32(dp, 0, diff); + // Make sure to deposit the correct size payload + // N.B.: The braces around the SETBExx macros are needed + // because the macro supplies its own set of braces, + // thus leaving a naked semicolon afterwards to + // screw up the if/else structure. This is the price + // you pay when using macros pretending to be code. + if (rflag & 0x02) + { + SETBE16(dp, 0, diff); + } + else + { + SETBE32(dp, 0, diff); + } + DEBUG printf("%uX\n", diff); #ifdef DEBUG_IMAGE_MARKING printf("$%08X\n", diff); @@ -463,6 +483,7 @@ uint32_t CreateELFRelocationRecord(uint8_t * buf, uint8_t * secBuf, uint16_t sec // Setup pointer for D_long/word/byte macros chptr = buf; + ch_size = 0; for(MCHUNK * mch=firstmch; mch!=NULL; mch=mch->mcnext) {