Skip to content

Data from different banks being conflated #404

@wendelscardua

Description

@wendelscardua

The repro below shows the issue (compiled with mos-nes-unrom-clang++ -Os -flto -g -gdwarf-4 -std=c++23 -Wl,-Map,repro.map repro.cpp -o repro.nes).

It defines two identical arrays, foo on bank 1 and bar on bank 2. The main loop calls functions (one on each bank) that prints an element from the respective array.

The thing is, the test1() calls print only zeroes. I think the arrays are being conflated - no sign of foo in either repro.map or repro.mlb, only bar shows up. Whatever test1() is accessing isn't foo (instead it's probably accessing bar's equivalent address on bank 1)

#include <cstdio>
#include <mapper.h>

#pragma clang section text = ".prg_rom_fixed.text"

void put_digit(unsigned char h) { putchar('0' + h); }

#pragma clang section rodata = ".prg_rom_1.rodata"
const unsigned char foo[] = {4, 1, 3};

#pragma clang section rodata = ".prg_rom_2.rodata"
const unsigned char bar[] = {4, 1, 3};

#pragma clang section text = ".prg_rom_1.text"
void test1(unsigned char index) {
  puts("test1");
  put_digit(foo[index]);
  putchar('\n');
}

#pragma clang section text = ".prg_rom_2.text"
void test2(unsigned char index) {
  puts("test2");
  put_digit(bar[index]);
  putchar('\n');
}

#pragma clang section text = ".prg_rom_fixed.text"
int main() {
  for (unsigned char i = 0; i < 3; i++) {
    set_prg_bank(1);
    [[clang::noinline]] test1(i);
    set_prg_bank(2);
    [[clang::noinline]] test2(i);
    set_prg_bank(0);
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions