Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature proposal] Weak sections #985

Open
aaaaaa123456789 opened this issue Mar 2, 2022 · 0 comments
Open

[Feature proposal] Weak sections #985

aaaaaa123456789 opened this issue Mar 2, 2022 · 0 comments
Labels
enhancement Typically new features; lesser priority than bugs rgbasm This affects RGBASM rgblink This affects RGBLINK
Milestone

Comments

@aaaaaa123456789
Copy link
Member

aaaaaa123456789 commented Mar 2, 2022

[Note: proposal taken from the debate in gbdev's #asm on 2022-03-02.]

Fixing some data across many banks is easy. For instance, consider placing the current bank number at the end of each ROMX bank:

for ___bank, 1, $80
SECTION "Bank ID {d:___bank}", ROMX[$7fff], BANK[___bank]
  db ___bank
endr

However, this has the side effect of extending the ROM to add banks that contain nothing but this fixed data, which will most likely be irrelevant for those otherwise unused banks.
Therefore, a new section type could be created (like SECTION UNION and SECTION FRAGMENT), which for this proposal I'll call SECTION WEAK:

for ___bank, 1, $100
SECTION WEAK "Bank ID {d:___bank}", ROMX[$7fff], BANK[___bank]
  db ___bank
endr

Semantics:

  • After linking and placing all sections, if the last bank of any section type contains only weak sections, discard them all and repeat this check until it fails.
  • Sections discarded this way don't emit any data or symbols, nor they should show up in map files.
  • If a symbol defined by a section discarded this way is referenced from a non-discarded section, a link error occurs. (Symbols from a weak section referenced in another section shouldn't be resolved at assembly time, if possible.)
  • A weak section whose placement isn't fully defined (both bank and address) at link time, either through attributes or through a linker script, should raise a link warning, enabled by default. A weak section whose section type is unbanked should also raise this warning.
  • If a weak section's bank number isn't fully defined at link time, and its section type is banked, it is always discarded. This is equivalent to placing it in a new bank and discarding that bank. (Note that this will raise the warning described in the previous bullet point.)
  • As WEAK is a kind of section, it doesn't combine with UNION and FRAGMENT. This is intentional. (If this combination would be desirable, WEAK could be made an attribute, like BANK or ALIGN.)
  • It is possible to define weak sections for section types that don't belong in ROM ("no output section types" borrowing the terminology from [Feature request/proposal] Hardware layout description files (custom mapper support) #524). This is simply to make the semantics simpler (no special cases) and to avoid blocking [Feature request/proposal] Hardware layout description files (custom mapper support) #524. Of course, a no output weak section can only output symbols, but it can also reserve space in each bank, which may be useful for some strange use cases.
@ISSOtm ISSOtm added enhancement Typically new features; lesser priority than bugs rgbasm This affects RGBASM rgblink This affects RGBLINK labels Mar 10, 2022
@Rangi42 Rangi42 added this to the v1.0.0 milestone Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Typically new features; lesser priority than bugs rgbasm This affects RGBASM rgblink This affects RGBLINK
Projects
None yet
Development

No branches or pull requests

3 participants