Hello,
I have code with a special section which is assembled to an ELF object file, for which I do not want any ELF relocations to happen.
Tricks like passing "--section-start=.somespecialsection=0" to ld don't work here, I really want the code to be generated without relocation (selective or for the whole section/file all works for me).
I have code similar to this:
SECTION .somespecialsection progbits alloc exec nowrite align=16
somevar: DB 0
somefunc:
...
someotherfunc:
...
MOV eax, somevar
CALL somefunc
For this, NASM creates an object file that will cause the linker to later relocate the value of "somevar" and "somefunc" relative to the section start defined by the linker. I tried several things to turn that off:
ORG. ORG is plain not accepted for ELF, so something like "ORG 0" at the start of the section does not work.
WRT. I tried e.g. replacing the call with "CALL somefunc WRT 0", which I think would make some sense. However, NASM does not seem to accept absolute constants for WRT and instead wants a segment. I also tried to create an "absolute" pseudo segment, but did not find any way.
Subtract the section start. For the MOV, this actually seems to work at first:
MOV eax, somevar-$$ ; $$ = section start
However, while this ultimately has the desired effect, NASM still marks the symbol to be relocated at that place, and we just cancel the effect of the relocation. So as soon as I do this (knowing that the address relative to the section start would be small enough to fit into 16 bits):
MOV ax, somevar-$$
The linker throws an error, because it's still applying the relocation, which in this case does not fit into the operand size.
Is there any way I can just turn off relocation? For a whole file, section, or per symbol individually?