still trying to use TLS
I have successfully fixed the problem of the code generated by one thread being invalid for another. The solution is to generate code with the gs prefix and compute the offsets from gs:0.
One think that is missing is to simulate the per thread gdt that the kernel maintains (ie. alter the simulated gdt when clone is called with CLONE_SETTLS). I will study how qemu simulates the segments and see if I can implement that.
Rafael