gcc-ia16 icon indicating copy to clipboard operation
gcc-ia16 copied to clipboard

Question: can i have variables in code segment?

Open LowLevelMahn opened this issue 4 years ago • 5 comments
trafficstars

Watcom supports something like __based( __segname("_CODE") ) to bind definition or extern of variables to the code segment

is there somethin similar available with gcc ia 16? is attribute ((section ("segXYZ"))) useable?

LowLevelMahn avatar Jun 12 '21 16:06 LowLevelMahn

Hello @LowLevelMahn,

Well, sort of. You can say something like

int __far __attribute__ ((section (".text"))) x;

int
f (void)
{
  return x;
}

(Note: The __far is important.)

However, gcc-ia16 is not (yet) smart enough to recognize that --- in this case --- x can be accessed via a %cs: segment override, because it is in the same section (.text) as the function referring to it. Thus the above code will cause a segment relocation to be emitted. (I see that Open Watcom does know about such special cases.)

Thank you!

tkchia avatar Jun 12 '21 18:06 tkchia

Hello @tkchia,

Thus the above code will cause a segment relocation to be emitted.

I see the code emitted which causes a segment relocation to be:

    movw    $"x!"@SEG,  %ax
    movw    %ax,    %ds

Out of curiosity, then, the linker will correctly emit the relocation table entry such that %AX gets loaded with the same value as the CS segment, but that this would only work if the OS and executable format support relocation table relocations at load time, correct?

That is, this would produce an extended header (that which is being used for the medium model support) on ELKS, and work correctly if CONFIG_EXEC_MMODEL is turned on, and the same for MSDOS MZ format exes, right?

Thank you!

ghaerr avatar Jun 12 '21 19:06 ghaerr

@ghaerr : that is so. Thank you!

tkchia avatar Jun 13 '21 06:06 tkchia

close for now - solved my problem using watcom long time ago

LowLevelMahn avatar Jun 29 '22 10:06 LowLevelMahn

Should probably be reopened - that the problem was solved doesn't mean it's still not an outstanding feature request in gcc-ia16.

asiekierka avatar Jun 29 '22 12:06 asiekierka