mkst / maspsx

MIT License
5 stars 4 forks source link

Further gprel sym+offset fixes #72

Closed dezgeg closed 6 months ago

dezgeg commented 6 months ago

The previous logic for whether to allow gp addressing for symbol+offset seems incomplete. I tested this C with vec declared in different ways:

extern VECTOR vec;
void Test(SVECTOR* v) {
    vec.vx = v->vx;
    vec.vy = v->vy;
    vec.vz = v->vz;
}

and results for gcc 2.7.2.SN32.3.7.0002 + aspsx 2.56 are:

C variable type                    | gp used?        | asm declaration
-----------------------------------+-----------------+---------------------------
extern                             | never           | .extern vec, 16
func static initialized            | always          | .sdata; vec.2: .word 1,2,3
func static uninitialized          | always          | .lcomm vec.2,16
global static initialized          | always          | .sdata; vec: .word 1,2,3
global static uninitialized        | always          | .lcomm vec,16
global initialized                 | always          | .sdata; vec: .word 1,2,3
global uninitialized               | only w/o offset | .comm vec,16
global uninitialized w/-fno-common | always          | .sdata; vec: .space 16

so it seems only symbols declared with .comm shouldn't be allowed to use offset in older aspsx.

mkst commented 6 months ago

Ok, so there's a distinction between .comm and .lcomm. I'll have a look at this tomorrow and add some new tests based on my findings, thanks for raising this.