On Friday, April 8, 2022 at 8:55:32 AM UTC-7, Johnny Billquist wrote:
(snip, I wrote)
> > Reminds me that the OS/360 (and still in use) object file format
> > allows for relocation factors of -1, 0, 1, and 2. I can figure
> > out how to write one with -1 or 2, but have never seen that in
> > an actual program. I suspect you could look at a very large
> > number of files, and not find out that existed.
> > As well as I know, no other object file format allows for it.
> I don't even know what that means. :-)
> The object file formats I know about allows for individual symbols to be
> referenced, and even used in various complex expressions in the object
> file, without knowing the value of the symbol. All resolved at linking time.
For usual assemblers, symbols are either absolute (don't change with
the address of the module) or relocatable (do change). Absolute
addresses have relocation factor 0.
The assembler starts (usually) at address zero for each object file.
When it is linked, the linker gives it a different starting address, and
adds that to all the relocatable addresses (with relocation factor 1).
If your "various complex expression" adds two relocatable values,
then the linker has to add twice the offset. If you negate a
relocatable value, the linker has to subtract the offset,
instead of adding. Most linkers don't do that, and so the
assembler has no way to ask for it to be done.