<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/92901>92901</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
How to understand the getTLSModel() function's selection of the TLSModel?
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Thrrreeee
</td>
</tr>
</table>
<pre>
I can't understand why, after assigning the variable TLSModel following the IR analysis, this function still performs a check on it. Additionally, why does it assign TLSModel based on this condition ( `if (SelectedModel > Model)` ), as the strictness increases with larger values?
Finally, what could happen if I forcibly change a variable's TLSModel judged as `LocalDynamic `to `GeneralDynamic`? What if I modify the IR directly to remove its `private` type, so that the variable's islocal check results in false? And then this variable'TLSModel can be `GeneralDynamic`.
Because JITlink does not yet support R_X86_64_TLSLD.
[code](https://github.com/llvm/llvm-project/blob/46d8bb08cfd3798977b4e22881514dc9d77425c2/llvm/lib/Target/TargetMachine.cpp#L237C1-L262C2)
```
TLSModel::Model TargetMachine::getTLSModel(const GlobalValue *GV) const {
bool IsPIE = GV->getParent()->getPIELevel() != PIELevel::Default;
Reloc::Model RM = getRelocationModel();
bool IsSharedLibrary = RM == Reloc::PIC_ && !IsPIE;
bool IsLocal = shouldAssumeDSOLocal(GV);
TLSModel::Model Model;
if (IsSharedLibrary) {
if (IsLocal)
Model = TLSModel::LocalDynamic;
else
Model = TLSModel::GeneralDynamic;
} else {
if (IsLocal)
Model = TLSModel::LocalExec;
else
Model = TLSModel::InitialExec;
}
// If the user specified a more specific model, use that.
TLSModel::Model SelectedModel = getSelectedTLSModel(GV);
if (SelectedModel > Model)
return SelectedModel;
return Model;
}
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVl1v4ygX_jXk5mgiG8dfF7lIm6ZvXmW0o7aa3bsKw3HMDAELcLv59ytwnKSZ0Wh3tVLVYA7nOc_5BOac3GvEJcnvSL6esc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