Kingcom / armips

An assembler for various ARM and MIPS platforms. Builds available at http://buildbot.orphis.net/armips/
MIT License
363 stars 77 forks source link

.importobj fails to correctly relocate static variables on wrapover boundaries #161

Closed mzxrules closed 4 years ago

mzxrules commented 4 years ago

test case https://github.com/TestRunnerSRL/OoT-Randomizer/commit/7f890241740f2d9c4fdb63ace7b73422412803fd

relevant bundle.o objdump info

00003c60 <text_init>:
3c60:   27bdffe8    addiu   sp,sp,-24
3c64:   afbf0014    sw  ra,20(sp)
3c68:   0c000000    jal 0 <get_chest_override_size>
3c6c:   24040400    li  a0,1024
3c70:   3c030000    lui v1,0x0
3c74:   ac620050    sw  v0,80(v1)
3c78:   3c030000    lui v1,0x0
3c7c:   ac620054    sw  v0,84(v1)
3c80:   8fbf0014    lw  ra,20(sp)
3c84:   03e00008    jr  ra
3c88:   27bd0018    addiu   sp,sp,24

RELOCATION RECORDS FOR [.text]:
OFFSET   TYPE              VALUE 
...
00003c70 R_MIPS_HI16       .sbss
00003c74 R_MIPS_LO16       .sbss
00003c78 R_MIPS_HI16       .sbss
00003c7c R_MIPS_LO16       .sbss
...

function text references two static .sbss variables that are relocated to address 80408000 and 80408004 respectively. however the lui/sw pair generated is lui 0x8040, sw 0x8000, referencing 803F8000. removing the static keyword fixes this.

Edit: actual problem is that the .sbss block is straddling the boundary. seems to not recognize that .sbss start + 0x50 will result in a negative sw immediate