[PATCH] x86: Add tls check in gas

H.J. Lu hjl.tools@gmail.com
Wed Sep 4 11:20:38 GMT 2024


On Wed, Sep 4, 2024 at 12:46 AM Cui, Lili <lili.cui@intel.com> wrote:
>
> > > static bool
> > > x86_check_tls_relocation (unsigned int r_type)
> > >
> > > > > +{
> > > > > +  switch (r_type)
> > > > > +    {
> > > > > +    case BFD_RELOC_386_TLS_GOTDESC:
> > > > > +      /* Check transition from GDesc access model:
> > > > > +    leal x@tlsdesc(%ebx), %eax
> > > > > +    call *x@tlsdesc(%eax)
> > > > > +       */
> > > > > +      if (i.tm.mnem_off == MN_call)
> > > > > +   return true;
> > > >
> > > > There are two forms of CALL - I doubt both are allowed.
>
> H.J, I am confused about "call *x@tlsdesc(%eax)", I don’t know how to handle it in the current patch.
>
> For current gas, we bind it with BFD_RELOC_386_TLS_GOTDESC/ BFD_RELOC_X86_64_GOTPC32_TLSDESC. I also see it in the abi documentation.
> But for the linker, R_386_TLS_GOTDESC/ R_X86_64_GOTPC32_TLSDESC only allow lea. It seems that the linker does not support "call *x@tlsdesc(%eax)".

See:

https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=5a655b5291b3f56088409d34e9077e98af63de60

> > > > > +      /* fall through */
> > > > > +    case BFD_RELOC_386_TLS_GD:
> > > > > +      /*  Check transition from GD access model:
> > > > > +     leal foo@tlsgd(,%ebx,1), %eax
> > > > > +       */
> > > > > +    case BFD_RELOC_386_TLS_LDM:
> > > > > +      /*  Check transition from LDM access model:
> > > > > +     leal foo@tlsldm(%ebx), %eax
> > > > > +       */
> > > > > +      if (i.tm.mnem_off == MN_lea)
> > > > > +   return true;
> > > >
> > > > And which base/index registers are used doesn't matter? Nor operand
> > > > size?
> > >
> > > We need to check base and index registers as well as operand size.
> > > Only EBX is allowed.  This applies to all relocations.  Please check
> >
> > I was wrong.
> >
> >         leal    sh1@tlsldm(%ecx), %eax
> >         call    *___tls_get_addr@GOT(%ecx)
> >
> > is also allowed.
> >
>
> Yes.
>
>         leal foo@tlsldm(%reg), %eax --> Dest reg must be '%eax'
>                                                                   Memory reg can't be %eax and SIB
>                                                                   is not supported.
>
> Thanks,
> Lili.



-- 
H.J.


More information about the Binutils mailing list