gbdev / rgbds

Rednex Game Boy Development System - An assembly toolchain for the Nintendo Game Boy and Game Boy Color
https://rgbds.gbdev.io
MIT License
1.35k stars 172 forks source link

rgblink scramble hides mistakes #1149

Open zlago opened 1 year ago

zlago commented 1 year ago

while the scramble flag does serve its purpose of showing when you forget to bankswitch, it introduces two new issues:

  1. it hides alignment mistakes, as sections generally get placed at $4000
  2. it hides mistakes where data is read out of bounds, since all data past a section is usually $ff

possible solutions for each issue:

  1. try to put sections at the end of a bank, or avoid putting sections at $4000 (the former is probably better)
  2. allow for randomising section banks instead of putting each section in its own bank

the second one probably isnt as much of an issue as the first, as its me not testing the non-scrambled build..

aaaaaa123456789 commented 1 year ago

I'd say that a better fix would be to randomize all ROM padding in scramble mode, and to possibly shift sections by a few bytes when there's free space to do so. However, shifting sections would probably require rerunning the linker...

evie-calico commented 1 year ago

That’s the issue I see with this. No matter how it’s implemented, the misalignment would cause fragmentation, which might cause a scrambled build to fail when a normal one wouldn’t.

ISSOtm commented 1 year ago

The way I see it, allocating sections primarily towards the end of ROMX would help catch OOB accesses there, as then those accesses would tend to fall in VRAM (then it's a die roll as to whether a VRAM access exception is triggered, but better than nothing) or SRAM (which is most often locked).

Additionally, I see no harm in doing thins by default outside of -x mode. (Sure, that would change section order, but this should not be as breaking a change since #136's resolution.)

evie-calico commented 1 year ago

Putting the sections at the end is a really good idea, I didn't consider that.

zlago commented 1 year ago

i didnt intend on solving both problems.. i only really thought of it as "should be a cheap way to put a section at somewhere other than the start"