[csl-arm] TLS base corrupted before use
Paul Brook
paul@codesourcery.com
Tue Aug 30 17:18:00 GMT 2005
The TLS base register can get corrupted before use when a thread local
variable is used in a function argument.
arm_load_tp uses r0 directly for the TLS base register. This value can then
get corrupted (eg. by setting up annother function argument) before it is
used. We need to use the r0 in the load_tp_soft insn otherwise sched1 can
move the insn somewhere inconvenient, and reload is unable to spill r0. This
is gcc.dg/tls/opt-5.c
The attached patch fixes this by copying the tls base into a pseudo. In most
cases this copy will be optimized away, giving the same code as before.
For example:
int __thread i;
void foo()
{
bar(0, i);
}
Before the patch wwe get:
ldr r3, .L2
mov r0, #0
ldr r1, [r0, r3]
bl bar
With the patch we get:
bl __aeabi_read_tp @ load_tp_soft
mov r2, r0
ldr r3, .L2
mov r0, #0
ldr r1, [r2, r3]
bl bar
Tested with cross to arm-none-eabi.
Applied to csl-arm-branch.
Paul
2005-08-30 Paul Brook <paul@codesourcery.com>
* config/arm/arm.c (arm_load_tp): Copy result to pseudo.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.tp_r0
Type: text/x-diff
Size: 1174 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20050830/135f3059/attachment.bin>
More information about the Gcc-patches
mailing list