tkchia / gcc-ia16

Fork of Lambertsen & Jenner (& al.)'s IA-16 (Intel 16-bit x86) port of GNU compilers ― added far pointers & more • use https://github.com/tkchia/build-ia16 to build • Ubuntu binaries at https://launchpad.net/%7Etkchia/+archive/ubuntu/build-ia16/ • DJGPP/MS-DOS binaries at https://gitlab.com/tkchia/build-ia16/-/releases • mirror of https://gitlab.com/tkchia/gcc-ia16
GNU General Public License v2.0
173 stars 13 forks source link

Question: can i have variables in code segment? #79

Open LowLevelMahn opened 3 years ago

LowLevelMahn commented 3 years ago

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?

tkchia commented 3 years ago

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!

ghaerr commented 3 years ago

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!

tkchia commented 3 years ago

@ghaerr : that is so. Thank you!

LowLevelMahn commented 2 years ago

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

asiekierka commented 2 years ago

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