@@ -710,12 +710,23 @@ ProgramManager::collectDependentDeviceImagesForVirtualFunctions(
710710 }
711711 }
712712
713- // TODO: Complete this part about handling of incompatible device images.
714713 // If device image uses the same virtual function set, then we only
715714 // link it if it is compatible.
716715 // However, if device image provides virtual function set and it is
717716 // incompatible, then we should link its "dummy" version to avoid link
718717 // errors about unresolved external symbols.
718+ // Note: we only link when exactly one of
719+ // doesDevSupportDeviceRequirements(Dev, *BinImage) and
720+ // isDummyImage is true. We don't want to link every dummy image,
721+ // otherwise we could run into linking errors defining the same symbol
722+ // multiple times. For every image providing virtual functions that has
723+ // a dummy image, the dummy image will have the same device requirements
724+ // as the original image. So when the dummy image does support the
725+ // device requirements, we know that the corresponding image providing
726+ // actual definitions will be linked and not the dummy. And vice versa:
727+ // when the dummy image does not support the device requirements, we
728+ // know the corresponding image providing virtual functions was not
729+ // linked and we must link the dummy image.
719730 if (doesDevSupportDeviceRequirements (Dev, *BinImage) + isDummyImage == 1 )
720731 DeviceImagesToLink.insert (BinImage);
721732 }
0 commit comments