[PATCH] gas: force a NULL value for BFD_RELOC_PPC*_TLSM on XCOFF.

Alan Modra amodra@gmail.com
Wed Jun 16 03:05:06 GMT 2021


On Tue, Jun 15, 2021 at 02:44:05PM +0000, CHIGOT, CLEMENT wrote:
> Hi Alan,
> 
> Indeed, I've checked only with one problematic symbol. Thus,
> the VMA was enough. I'll change that.
> 
> However, you might have an idea for a better approach.
> What I want to do is to ensure that any symbol's value which
> has a BFD_RELOC_PPC_TLSM relocation is always NULL.
> By default, bfd backend will set this value to the address of the
> symbol targeted by BFD_RELOC_PPC_TLSM.
> 
> For example, if "a" is a R_TLSM pointer to "b", I want "*a" to be
> NULL, but for now "*a" is "@b". AIX linker is refusing it.

If I understand you correctly, the section contents against which one
of these relocations applies, should be set to zero.

> The only way I've managed to fix that is to set addend to be the
> opposite of that bfd_install_relocation will put.

Except that what you have isn't quite correct yet.  That shouldn't be
too difficult to fix, just subtract S_GET_VALUE (fixP->fx_addsy) as
well I think.  Please change the comment to
    /* AIX ld expects the section contents for these relocations
       to be zero.  Arrange for that to occur when
       bfd_install_relocation is called.  */
Also, please add a testcase to gas/testsuite/gas/ppc that verifies the
assembler produces the expected values.

Another approach is to give the reloc howtos for these quite unusual
relocations a special_function entry, with that function setting the
section contents to zero and returning bfd_reloc_ok.  You don't need
to go in this direction, in fact I'm not recommending it.  (Mostly
because the the xcoff backend code ignores quite a lot of existing bfd
support.)

Something like the following

static bfd_reloc_status_type
always_zero (bfd *ibfd,
	     arelent *rel,
	     asymbol *sym ATTRIBUTE_UNUSED,
	     void *data,
	     asection *sec,
	     bfd *obfd ATTRIBUTE_UNUSED,
	     char **err ATTRIBUTE_UNUSED)
{
  bfd_byte *loc = (bfd_byte *) data + rel->address;
  bfd_put_32 (ibfd, 0, loc);
  rel->address += sec->output_offset;
  return bfd_reloc_ok;
}

There is some chance this might even work for ld -r and ld final
linking, but I haven't even compiled it let alone tested.

-- 
Alan Modra
Australia Development Lab, IBM


More information about the Binutils mailing list