zilch-lang / nstar

The compiler for N⋆, a statically typed assembly language used as a compiler backend for Zilch
BSD 3-Clause "New" or "Revised" License
28 stars 2 forks source link

Sections and static data #19

Closed Mesabloo closed 3 years ago

Mesabloo commented 3 years ago

All assembly languages do have sections (one for code, one for read-only data, one for zero-initialized data, etc). I believe the reason is that object files do also have those sections (taking a look the ELF object file format), and that without them it isn't really easy to, for example, have global variables etc. We will need to have sections too. The problem being how to represent them in the source file. We may do

.section text {

}
.section data {
    x: s64
      0x0
}

(with or without the braces) Further referencing x in the text section would yield a *s64 (for example, mov (x), %rax would yield %rax: s64).

Mesabloo commented 3 years ago

Both to complete the issue, and to have a link for the ELF object file format: https://wiki.osdev.org/ELF

Mesabloo commented 3 years ago

There is one problem with this: sections names are not necessarily the same across object file formats (for example, the .text section might be named differently in the ELF format and the PE format). We might need to select special identifiers and handle those internally, generating the correct sections depending on the target object file format.

Mesabloo commented 3 years ago

Quick recap of available sections (taken from the specification):

(*): the type of binding is given using a special dyn quantifier placed right before the name of the binding.