[PATCH] TLS support for Windows 32+64bit

Happy new year to all!

The attached patch adds TLS support for x86_64-pc-win32 and x86-pc-win32. Implemented is the implicit TLS model (__declspec(thread) in Visual C++).
Please review. Thanks!

Regards
Kai

tls20120101.diff (17.5 KB)

Rough review: looks like the patch is in the right direction; please
take out all tabs, please take out all commented-out code.

-Eli

Hi!

Thanks for your answer!
I reworked the patch: the tabs and the commented-out is gone. I also tried to limit line-length to 80 chars. Applies cleanly to r147775 now.

Kai

tls20120109.diff (16.6 KB)

Hi!

I added 2 more tests and also refined an assert statement. Applies cleanly to r148473 now. Are there more comments on the code? Thank you!!

Regards
Kai

tls-20120119.diff (19.1 KB)

+ assert(Inst.getOperand(0).isReg() &&
+ (Inst.getOperand(ImmOp).isImm() ||
+ (Inst.getOperand(ImmOp).isExpr() &&
+ Inst.getOperand(ImmOp).getExpr()->getKind() == MCExpr::SymbolRef) &&
+ static_cast<const
MCSymbolRefExpr*>(Inst.getOperand(ImmOp).getExpr())->getKind() ==
MCSymbolRefExpr::VK_SECREL) &&

Just asserting "Inst.getOperand(ImmOp).isImm() ||
(Inst.getOperand(ImmOp).isExpr()" should be sufficient here; in
theory, a wide variety of relocatable expressions are legal here, even
if we don't actually generate code like that at the moment.

I would prefer if someone more familiar with COFF MC stuff could take
a look to make sure there isn't anything obviously wrong; otherwise,
the patch looks good.

-Eli

Hi!

I added 2 more tests and also refined an assert statement. Applies cleanly
to r148473 now. Are there more comments on the code? Thank you!!

+ assert(Inst.getOperand(0).isReg()&&
+ (Inst.getOperand(ImmOp).isImm() ||
+ (Inst.getOperand(ImmOp).isExpr()&&
+ Inst.getOperand(ImmOp).getExpr()->getKind() == MCExpr::SymbolRef)&&
+ static_cast<const
MCSymbolRefExpr*>(Inst.getOperand(ImmOp).getExpr())->getKind() ==
MCSymbolRefExpr::VK_SECREL)&&

Just asserting "Inst.getOperand(ImmOp).isImm() ||
(Inst.getOperand(ImmOp).isExpr()" should be sufficient here; in
theory, a wide variety of relocatable expressions are legal here, even
if we don't actually generate code like that at the moment.

I changed the assert as you proposed.

I would prefer if someone more familiar with COFF MC stuff could take
a look to make sure there isn't anything obviously wrong; otherwise,
the patch looks good.

I think the "big change" is that I changed the relocation type from IMAGE_REL_AMD64_SREL32 to IMAGE_REL_AMD64_SECREL for 64bit systems. I believe that there are currently no uses of this relocation type, but I may be wrong here.

-Eli

Regards
Kai

tls-20120126.diff (19 KB)