To enable TLS local-dynamic on AIX, according to docs, this patch need to generate below sequence of code:
.tc foo[TC],foo[TL]@ld # Variable offset, ld relocation specifier .tc mh[TC],mh[TC]@ml # Module handle for the caller lwz 3,mh[TC](2) $$ For 64-bit: ld 3,mh[TC](2) bla .__tls_get_mod # Modifies r0,r3,r4,r5,r11,lr,cr0 #r3 = &TLS for module lwz 4,foo[TC](2) $$ For 64-bit: ld 4,foo[TC](2) add 5,3,4 # Compute &foo .rename mh[TC], "_$TLSML" # Symbol for the module handle must have the name "_$TLSML"
I noticed AIX assembler only accepts TC storage mapping class for the "_$TLSML" symbol, which is different from all other variables in large code model, so I handled this in an explicit way...