Merge branch 'main'

This commit is contained in:
Scott Duensing 2026-08-14 18:12:17 -05:00
commit d9b8a98da2
2 changed files with 14 additions and 0 deletions

View file

View file

@ -549,9 +549,16 @@ static uint32_t relocWidth(uint8_t rtype) {
} }
unsigned long gDbgBareCalls = 0;
unsigned long gDbgTextCalls = 0;
static void applyReloc(std::vector<uint8_t> &buf, uint32_t off, static void applyReloc(std::vector<uint8_t> &buf, uint32_t off,
uint32_t patchAddr, uint32_t target, uint32_t patchAddr, uint32_t target,
uint8_t rtype, const std::string &symName) { uint8_t rtype, const std::string &symName) {
extern unsigned long gDbgBareCalls;
gDbgBareCalls++;
if (symName.find("gRnInPack") != std::string::npos) {
std::fprintf(stderr, "TRACE-BARE %s rtype=%u target=0x%X off=0x%X\n", symName.c_str(), rtype, target, off);
}
int64_t pcrelDisp; int64_t pcrelDisp;
switch (rtype) { switch (rtype) {
case R_W65816_IMM8: case R_W65816_IMM8:
@ -767,6 +774,12 @@ static void applyTextReloc(std::vector<uint8_t> &buf, uint32_t off,
} }
const TextSeg &pseg = segments[patchSeg - 1]; const TextSeg &pseg = segments[patchSeg - 1];
uint32_t targetSeg = findSegContaining(target, segments); uint32_t targetSeg = findSegContaining(target, segments);
gDbgTextCalls++;
// TEMP TRACE (RetroNet hunt): decisions for the mirror-pack refs.
if (symName.find("gRnInPack") != std::string::npos) {
std::fprintf(stderr, "TRACE %s rtype=%u patchSeg=%u targetSeg=%u target=0x%X rec=%d\n",
symName.c_str(), rtype, patchSeg, targetSeg, target, (int)gRecordSites);
}
// Cross-segment FUNCTION POINTER (IMM16 &func to a function in seg2+): // Cross-segment FUNCTION POINTER (IMM16 &func to a function in seg2+):
// clang forms the pointer as func's 16-bit offset + the $00BE seg1 bank, // clang forms the pointer as func's 16-bit offset + the $00BE seg1 bank,
// which is wrong for a function in another bank. Redirect the IMM16 to // which is wrong for a function in another bank. Redirect the IMM16 to
@ -2598,6 +2611,7 @@ int main(int argc, char **argv) {
L.bssBase, L.bssSize, L.bssBase, L.bssSize,
outPath.c_str(), image.size()); outPath.c_str(), image.size());
if (L.segments.size() > 1) { if (L.segments.size() > 1) {
std::fprintf(stderr, " [dbg: textReloc=%lu bare=%lu]", gDbgTextCalls, gDbgBareCalls);
std::fprintf(stderr, " + %zu extra segments", std::fprintf(stderr, " + %zu extra segments",
L.segments.size() - 1); L.segments.size() - 1);
for (size_t k = 1; k < L.segments.size(); ++k) { for (size_t k = 1; k < L.segments.size(); ++k) {