Previously, GlobalAlias::copyAttributesFrom did not preserve ThreadLocalMode,
causing incorrect IR generation in IR linking flows. This patch pushes the code
responsible for copying this attribute from GlobalVariable::copyAttributesFrom
down to GlobalValue::copyAttributesFrom so that it is shared by GlobalAlias.
Fixes PR46297.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
It looks like this is on an old version of clang, as this method is now in GlobalIndirectSymbol. You'll want to check this behavior and submit a patch for the latest clang. For the test, you could probably add an llvm-link based test in llvm/test/Linker/.
llvm/include/llvm/IR/GlobalAlias.h | ||
---|---|---|
63 ↗ | (On Diff #269916) | It seems like this belongs in GlobalValue::copyAttributesFrom, since it is a property of the GlobalValue. Interestingly I do see code in the IRMover (used when linking IR in LTO) that copies it over (in llvm/lib/Linker/IRMover.cpp). Are we missing places there? In any case, it seems reasonable to add this into GlobalValue::copyAttributesFrom. |
Added inline reply about IRMover and where the copying belongs.
I think it least bug-prone to push the ThreadLocalMode copying from GlobalVariable::copyAttributesFrom down to GlobalValue::copyAttributesFrom.
Values in the hierarchy for which the attribute is not relevant will ignore it. What do you think?
Regarding patch applicability to master:
You're right, I prepared the patch on an LLVM-9-derived branch. Will fix according to the decided-upon changes, and add the relevant test.
llvm/include/llvm/IR/GlobalAlias.h | ||
---|---|---|
63 ↗ | (On Diff #269916) | Regarding where it belongs: Regarding the code in IRMover: |
llvm/include/llvm/IR/GlobalAlias.h | ||
---|---|---|
63 ↗ | (On Diff #269916) | I agree that since this property is defined on the GlobalValue it makes most sense to copy it in the GlobalValue::copyAttributesFrom. I am not an expert on this particular attribute though. I discovered that Hans Wennborg added it some years ago (circa 2012-2014!). Added him to the review here to comment. I'm guessing that it was meant to apply to variables but leaving it off of aliases was an oversight? |
Changed the fix to push the ThreadLocalMode copying from derived class GlobalVariable down to base class GlobalValue.
Added an appropriate test under llvm/test/Linker.
LGTM. If @hans has any comments they can be addressed in a follow on change. Two things to fix before submitting though:
- A small change to the test comments is needed as noted below before submitting.
- The patch description needs updating. Doesn't need a full test case etc like it currently has, but does just need a general overview of the problem and fix.
llvm/test/Linker/alias-threadlocal.ll | ||
---|---|---|
3 | Please fix the bug number. https://bugs.llvm.org/show_bug.cgi?id=81605 is not a valid bug. In addition, please add a one sentence description at the top of what this is testing. |
Updated title and description.
Added description for test, created PR in bugzilla, corrected PR reference to point at it.
While creating this PR, I noted that this looks slightly related to https://bugs.llvm.org/show_bug.cgi?id=33846, but I am yet to check whether they are truly related or not. It doesn't mention aliases or anything of the sort, and changing linkers worked around the issue there.
When I added the TLS mode attribute, it only applied to GlobalVariables. Later, in 59f7eba2b546e4118434b0ea9de5e08c316a64b1, it was moved to also apply to aliases, but it seems that commit forgot to move the attribute copying. The current patch looks like a good fix to me.
Alright, looks like it's settled and ready then :)
I cannot commit the patch myself because I don't have commit access, so might I trouble one of you with that?
In another PR I was asked for an Author line for the git commit, including it preemptively.
Author: Itay Bookstein <itay.bookstein@nextsilicon.com>
Please fix the bug number. https://bugs.llvm.org/show_bug.cgi?id=81605 is not a valid bug. In addition, please add a one sentence description at the top of what this is testing.