This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: TLS relocations in PPC

> I'm not sure if this is the right place to ask. I'm trying
> For example, if I assemble "li 0, foo@l+8", it encodes as
> 0x38000008 with an R_PPC_ADDR16_LO reloc on foo with an
> addend of 8. I don't really understand why it encodes the 8
> in the instruction if PPC uses RELA relocations and it's
> just going to be overwritten later (i.e. 0x38000000 should
> work the same I would think), but I've been ignoring that.
> However, "li 0, foo@tls+8" encodes as 0x38000002. Where did
> the 2 come from? It seems to encode the @tls field as a 2 no
> matter what, which makes me think maybe the encoding of the
> field is important even if it's going to be rewritten by a
> relocation later. Does it mean anything, or is it just a
> side-effect of some other processing?

I think the "2" is in a register field, not part of the immediate
operand field. Register r2 is the thread pointer, so the instruction
is actually loading an offset relative to the contents of tp. The
resulting effective address will be the address of the thread-local

> As a side-note, are the TLS relocations documented
> somewhere? Almost all of the relocs I haven't been able to
> find in the spec or elsewhere are TLS-related, it feels like
> there must be some document somewhere that lists them all
> and what they mean that I'm just missing

These ought to be documented in the psABI for the architecture, but I
can't dig up any psABI for PPC32 newer than 1995, and that doesn't
mention TLS at all. There is a PPC64 ABI here that might be of some
help, even though it won't directly apply to the 32-bit ABI:

Ulrich Drepper wrote a comprehensive paper that describes TLS on a
variety of platforms. Unfortunately, his paper doesn't cover PPC, but
it may also help you understand what's going on -- the basic concepts
of TLS are pretty much the same across all platforms:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]