Skip to content

Commit 294a50c

Browse files
yuyichaoKristofferC
authored andcommitted
Make sure all the relocations are filled in for partially cloned target (#44262)
We collect the relocations (i.e. the GOT slots that is used in the code) for each target in `tgt.relocs`. Needing a relocation, however, does not imply that the function is cloned for this target within the group (It does mean that at least one target in the group has it cloned). The previous version would miss the relocation in this case. This was triggerred with the following cloning situation caller: clone_1 callee: clone_1, clone_1.clone_3 Since caller.clone_1 may call either callee.clone_1 or callee.clone_1.clone_3 a relocation for callee will be used and is required to be initialized. In addition to target 1, target 2 (and in fact target 3) within group 1 will also use caller.clone_1. However, since callee isn't cloned for target 2 the previous version wouldn't have saved this slot in the relocation array. (cherry picked from commit 76fc067)
1 parent cf86fc6 commit 294a50c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/llvm-multiversioning.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -992,15 +992,15 @@ void CloneCtx::emit_metadata()
992992
idxs.push_back(baseidx);
993993
for (uint32_t j = 0; j < nfvars; j++) {
994994
auto base_f = grp->base_func(fvars[j]);
995-
if (shared_relocs.count(j)) {
995+
if (shared_relocs.count(j) || tgt->relocs.count(j)) {
996996
count++;
997997
idxs.push_back(jl_sysimg_tag_mask | j);
998998
auto f = map_get(*tgt->vmap, base_f, base_f);
999999
offsets.push_back(get_ptrdiff32(cast<Function>(f), fbase));
10001000
}
10011001
else if (auto f = map_get(*tgt->vmap, base_f)) {
10021002
count++;
1003-
idxs.push_back(tgt->relocs.count(j) ? (jl_sysimg_tag_mask | j) : j);
1003+
idxs.push_back(j);
10041004
offsets.push_back(get_ptrdiff32(cast<Function>(f), fbase));
10051005
}
10061006
}

0 commit comments

Comments
 (0)