Add section fragments

Fixes #517, and hopefully enables RGBDS as a SDCC back-end
This commit is contained in:
ISSOtm
2020-07-21 19:53:40 +02:00
parent aca00e4fce
commit 1f2f797cb9
17 changed files with 174 additions and 50 deletions

View File

@@ -367,7 +367,6 @@ This tells the assembler what kind of information follows and, if it is code, wh
.Pp
.Ar name
is a string enclosed in double quotes, and can be a new name or the name of an existing section.
All sections assembled at the same time that have the same name are considered to be the same section, and their code is put together in the object file generated by the assembler.
If the type doesn't match, an error occurs.
All other sections must have a unique name, even in different source files, or the linker will treat it as an error.
.Pp
@@ -655,7 +654,7 @@ The same unionized section (= having the same name) can be declared several time
invocation, and across several invocations.
Different declarations are treated and merged identically whether within the same invocation, or different ones.
.It
A section cannot be declared both as unionized or non-unionized.
If one section has been declared as unionized, all sections with the same name must be declared unionized as well.
.It
All declarations must have the same type.
For example, even if
@@ -679,6 +678,49 @@ or
Different declarations of the same unionized section are not appended, but instead overlaid on top of eachother, just like
.Sx Unions .
Similarly, the size of an unionized section is the largest of all its declarations.
.Ss Section Fragments
Section fragments are sections with a small twist: when several of the same name are encountered, they are concatenated instead of producing an error.
This works within the same file (paralleling the behavior "plain" sections has in previous versions), but also across object files.
However, similarly to
.Sx Unionized Sections ,
some rules must be followed:
.Bl -bullet -offset indent
.It
If one section has been declared as fragment, all sections with the same name must be declared fragments as well.
.It
All declarations must have the same type.
For example, even if
.Xr rgblink 1 Ap s
.Fl w
flag is used,
.Ic WRAM0
and
.Ic WRAMX
types are still considered different.
.It
Different constraints (alignment, bank, etc.) can be specified for each unionized section declaration, but they must all be compatible.
For example, alignment must be compatible with any fixed address, all specified banks must be the same, etc.
.It
A section fragment may not be unionized; after all, that wouldn't make much sense.
.El
.Pp
When RGBASM merges two fragments, the one encountered later is appended to the one encountered earlier.
.Pp
When RGBLINK merges two fragments, the one whose file was specified last is appended to the one whose file was specified first.
For example, assuming
.Ql bar.o ,
.Ql baz.o ,
and
.Ql foo.o
all contain a fragment with the same name, the command
.Dl rgblink -o rom.gb baz.o foo.o bar.o
would produce the fragment from
.Ql baz.o
first, followed by the one from
.Ql foo.o ,
and the one from
.Ql bar.o
last.
.Sh SYMBOLS
.Pp
RGBDS supports several types of symbols: