Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <43572387.10269431.1553951888420.JavaMail.zimbra@redhat.com>
Date: Sat, 30 Mar 2019 09:18:08 -0400 (EDT)
From: Frediano Ziglio <fziglio@...hat.com>
To: musl@...ts.openwall.com
Subject: Re: Does TD point to itself intentionally?

> On Sat, Mar 30, 2019 at 07:11:41AM -0400, Frediano Ziglio wrote:
> > But "lea" how? It would be a rdfsbase instruction as "standard" registers
> > are used for other purposes. But as you said you cannot assume rdfsbase
> > would
> > work so it's hard to inline it. Doing that way you can inline that single
> > assembly instruction easily.
> >
> > Frediano
> 
> I don't understand the objection. I was talking about replacing
> __pthread_self() with:
> 
> asm ("lea %%fs:0, %0" : "=r"(self));
> 
> In case you are unfamilliar with that instruction: If the %0 were
> replaced with %rax, this would assemble to the opcode:
> 
> 64 40 8d 04 25 00 00 00 00
> 
> My god... having written this down, it would apparently be cheaper (code
> size wise) to encode
> 
> xorl %eax,%eax
> leaq %fs:(%rax),%rax
> 

The base is not taken into account, this will produce a 0.

> Because in 64-bit mode you need a SIB byte to encode absolute addresses,
> and the SIB byte in this mode only does 32-bit displacements. Let's see...
> 
> 31 C0
> 64 40 8d 00
> 
> Yep. 9 bytes vs. 6 bytes. But now I'm micro-optimizing. Though this
> optimization would also be valid for the current implementation.
> Something like:
> 
> static inline struct pthread *__pthread_self()
> {
> #ifdef MY_PATCH
> #define INST "lea"
> #else
> #define INST "mov"
> #endif
> 	struct pthread *self = 0;
> 	__asm__ (INST " %%fs:0,%0" : "+r" (self) );
> 	return self;
> }
> 
> My question was more about removing this conceptual hurdle, and making
> it more clear that FS indeed points to the thread descriptor, and not a
> pointer to the thread descriptor. I know full well we can't remove
> "self", nor skip the initialization, since both of these are ABI.
> 
> Ciao,
> Markus
> 

Frediano

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.