As discussed in #1120, and more recently in Discord #asm-rgbds, anonymous sections are a desirable feature that currently gets handled with macros. However, such macros are hard to write reliably, since \@ is not unique across translation units, and we ended up rejecting #1460 as an alternative to __FILE__.
The best we can currently do is to manually define a unique symbol per translation unit, which can be done automatically with build system cooperation, e.g. @ISSOtm's Makefile example:
obj/%.o: src/%.c
rgbasm ${ASFLAGS} $< -o $@ -DUNIT_NAME='$*' # or ${*F} if you want just the file name.
MACRO ANON_SECTION
SECTION "ANON {UNIT_NAME} \@", \#
ENDM
This issue proposes to allow just omitting the section name. The resulting anonymous section would have an internal unique identifier instead. And the linker knows which section comes from which translation unit, so it could avoid conflicts.
SECTION ROM0[$100]
jp EntryPoint
SECTION ROM0[$38]
CrashRst::
jp _CrashHandler
SECTION WRAM0, ALIGN[256]
wBuffer:: ds 512
Of course, anonymous sections can't be UNION or FRAGMENT, and can't be referred to from a linker script, but if you need any of those, you just give it a name.
This would require an update to the object file format, so it would have to wait for v2.0. (We could, for example, leave the STRING Name as an empty null-terminated string, and set one of the unused BYTE Type bits to indicate it's an anonymous section, which RGBLINK would then be responsible for tracking.)
As discussed in #1120, and more recently in Discord
#asm-rgbds, anonymous sections are a desirable feature that currently gets handled with macros. However, such macros are hard to write reliably, since\@is not unique across translation units, and we ended up rejecting #1460 as an alternative to__FILE__.The best we can currently do is to manually define a unique symbol per translation unit, which can be done automatically with build system cooperation, e.g. @ISSOtm's Makefile example:
This issue proposes to allow just omitting the section name. The resulting anonymous section would have an internal unique identifier instead. And the linker knows which section comes from which translation unit, so it could avoid conflicts.
Of course, anonymous sections can't be
UNIONorFRAGMENT, and can't be referred to from a linker script, but if you need any of those, you just give it a name.This would require an update to the object file format, so it would have to wait for v2.0. (We could, for example, leave the
STRING Nameas an empty null-terminated string, and set one of the unusedBYTE Typebits to indicate it's an anonymous section, which RGBLINK would then be responsible for tracking.)