[PATCH 5/6] aix: implement R_TOCU and R_TOCL relocations
Mon Mar 1 09:20:26 GMT 2021
> + if (rel->r_type == R_TOCU)
> + *relocation = (*relocation & 0xffff0000) >> 16 ;
> Please double-check this. The doc might say "the high-order 16 bits
> of the displacement" but I suspect that isn't 100% correct. If the
> code in your testcases is proper usage, and I expect it is, then the
> high 16 bits needs to be adjusted for the low 16 bits being signed.
> You probably want:
> *relocation = ((*relocation + 0x8000) >> 16) & 0xffff;
Yes, you're right. I wasn't aware of that.
> +#ifdef OBJ_XCOFF
> + /* AIX often generates addis instructions using "addis RT, D(RA)"
> + format instead of the classic "addis RT, RA, SI" one.
> + Restore it to the default format as it's the one encoded
> + in ppc opcodes. */
> + if (!strcmp (opcode->name, "addis") && strchr (str, '(') != NULL)
> + ppc_xcoff_fixup_addis (&str);
> Yikes, can't you tell people to fix their code? I see so many ways
> for this to go wrong, for example, if an expression calculating an
> offset happened to use parentheses. Also, ppc_xcoff_fixup_addis does
> no sanity checking and can easily cause buffer overflows.
Sadly no... AIX assembler wants the 3rd argument of an addis to be absolute.
Thus, it's using a different syntax when it's not.
To be precise, "addis RT, RA, SI" is allowed only if SI is an absolute and
"addis RT, D(RA)" is allowed only if D is a label/symbol having a relocation.
Thus, I need to find a way to allow both in GNU as.
I agree that my solution isn't the best one, but I didn't find any way to
add an opcode in ppc-opc.c.
If you have any idea how to do it properly, I would be glad. Otherwise,
I will have to use this approach..
More information about the Binutils