immortalvm / ivm-implementations

iVM contemporary implementations
5 stars 0 forks source link

Absolute labels in static data declarations #3

Closed ivar-rummelhoff closed 5 years ago

ivar-rummelhoff commented 5 years ago

[Received from Oscar October 1.]

Consider for example this C code:

char *s="hello";
main{ return 0; }

Compiling with gcc produces this assembly code:

    .file   "hello.c"
    ...
LC0:
    .string "hello!"
    ...
s:
    .quad   LC0
    ...
main:
    ...

which is equivalent to the following declarations of the VM64 assembler (ivm as-trace):

LC0: data1 [104   101   108   108   111] # ascci chars
s:   data8 [LC0]

These assembler lines is currently failing as label LC0 is unknown until the linker/loading stage (Error "Non-constant data expression on line ...").

As this kind of patterns are not only valid but commonly used in C programs, the assembler/linker/loader needs to be able to deal with them.