Incorrect local-dynamic TLS linker optimization with clang-generated code on PowerPC

Bill Schmidt wschmidt at
Wed Jan 28 10:06:11 PST 2015

On Wed, 2015-01-28 at 11:30 -0600, Bill Schmidt wrote:
> The issue is that we are generating two calls to __get_tls_addr in
> different basic blocks.  CSE at the MI level recognizes that the address
> computation can be commoned.  So r29 is copied to r3 before both of the
> __get_tls_addr calls.
> I think it would probably be somewhat difficult to avoid this commoning
> (would have to be specific to these address ops and only when accessing
> TLS vars for local/global-dynamic).  And in general it's a good thing to
> do.  Alan, does this complicate matters beyond what the linker can
> handle?

Part of the issue here is the late modeling of the call to
__get_tls_addr as a true call.  The MachineCSE pass does not have any
logic to common idempotent calls (presumably that is handled at the IR
level), so the addis/addi get commoned but the __get_tls_call does not.

Originally we modeled __get_tls_addr as a special target-specific opcode
that was expanded late.  We had problems with keeping the register
copies lined up correctly in the presence of multiple TLS variable
accesses, and we fixed this by using the regular call machinery instead.
In retrospect, it appears that although this is a much cleaner
implementation, it limits the ability to CSE the __get_tls_addr calls.

We can work on a fix to go back to the old model and fix the register
copies with glue instead, but this would be a pretty substantial change
to backport to 3.6.  However, if the linker can't handle the code as is,
then this would seem to be the only way forward.



> Bill
> > 
> > Chandler, as a workaround it should be possible to use the initial-exec TLS
> > model for this variable; this should work fine (at least on Linux).   Using
> > the following line:
> > 
> > static __thread __attribute__((tls_model("initial-exec"))) const
> >   PrettyStackTraceEntry *PrettyStackTraceHead = nullptr;
> > 
> > I was able to complete a bootstrap on powerpc64le-linux (Ubuntu 14.04).
> > 
> > 
> > Mit freundlichen Gruessen / Best Regards
> > 
> > Ulrich Weigand
> > 
> > --
> >   Dr. Ulrich Weigand | Phone: +49-7031/16-3727
> >   STSM, GNU/Linux compilers and toolchain
> >   IBM Deutschland Research & Development GmbH
> >   Vorsitzende des Aufsichtsrats: Martina Koederitz | Geschäftsführung: Dirk
> > Wittkopp
> >   Sitz der Gesellschaft: Böblingen | Registergericht: Amtsgericht
> > Stuttgart, HRB 243294
> > 

More information about the llvm-commits mailing list