Ticket #537 (Open)Mon Nov 22 14:36:46 UTC 2021
Link: Optional page alignment for read-write area
Reported by: | Stuart Swales (8827) | Severity: | Enhancement |
Part: | RISC OS: C/C++ toolchain | Release: | |
Milestone: | Status | Open |
Details by Stuart Swales (8827):
Would it be feasible/sensible to add an option to Link to align the output’s Image$$RW$$Base to a specified power-of-two boundary? I’m particularly thinking of 4KB here, so that there is no chance of any legitimate write to non-const DATA affecting a (modern-sized) page containing read-only CODE.
Changelog:
Modified by Stuart Swales (8827) Mon, November 22 2021 - 14:41:00 GMT
I did try !Xpand on link (DDE30c) to see if there was some undocumented option in there, but xpand crashed :-(
Modified by Stuart Swales (8827) Mon, November 22 2021 - 15:31:56 GMT
Any such alignment would have to be done by increasing the size of the underlying RO area for AIF.
Modified by Jeffrey Lee (213) Fri, November 26 2021 - 12:21:24 GMT
As a workaround, you could write a wrapper script which links the code once, then reads the AIF header to work out how much padding is needed, and then re-links it with an extra object file containing the right amount of padding.
There is a -RW-base argument that can be used to explicitly set the address of the RW segment (and -RO-base for the RO segment), but I don’t think they’re much help here because the AIFs they produce can’t be loaded directly; they need the help of a loader which will copy the segments to the right addresses.
Modified by Jeffrey Lee (213) Fri, November 26 2021 - 12:27:51 GMT
Actually, maybe the default AIF relocation code will allow -RO-base to work. But if the RW area doesn’t directly follow the RO area (which is what you’re after) then I’m not sure if it will work out of the box. At the least, I know that fileswitch will need updating, since the code which grows the wimpslot when loading an AIF currently ignores the “data base” field (offset &34) which the -RW-base option populates.