On Thu, Nov 19, 2015 at 06:47:28PM +0300, Ilya Verbin wrote: > I will add this: > > diff --git a/liboffloadmic/plugin/libgomp-plugin-intelmic.cpp > b/liboffloadmic/plugin/libgomp-plugin-intelmic.cpp > index 6ee585e..f8c1725 100644 > --- a/liboffloadmic/plugin/libgomp-plugin-intelmic.cpp > +++ b/liboffloadmic/plugin/libgomp-plugin-intelmic.cpp > @@ -71,7 +71,7 @@ struct TargetImageDesc { > /* 10 characters is enough for max int value. */ > char name[sizeof ("lib0000000000.so")]; > char data[]; > -} __attribute__ ((packed)); > +}; > > /* Image descriptors, indexed by a pointer obtained from libgomp. */ > typedef std::map<const void *, TargetImageDesc *> ImgDescMap; > @@ -313,9 +313,8 @@ offload_image (const void *target_image) > target_image, image_start, image_end); > > int64_t image_size = (uintptr_t) image_end - (uintptr_t) image_start; > - TargetImageDesc *image > - = (TargetImageDesc *) malloc (sizeof (int64_t) + sizeof > ("lib0000000000.so") > - + image_size); > + TargetImageDesc *image = (TargetImageDesc *) malloc (offsetof > (TargetImageDesc, data) > + + image_size); > if (!image) > { > fprintf (stderr, "%s: Can't allocate memory\n", __FILE__);
LGTM. > > What is the point of this hunk? Is there any point in unregistering the > > main target image? I mean at that point the process is exiting anyway. > > The importance of unregistering target images registered from shared > > libraries is that they should be unregistered when they are dlclosed. > > liboffloadmic performs correct finalization of the target process in > __offload_fini_library, which is called only during unregistration of the main > target image. > Without this finalization the target process will be destroyed after unloading > libcoi_host.so. And then some DSO may call GOMP_offload_unregister_ver from > its > destructor, which will try to unload target image from the already destroyed > process. This issue is reproducible only using real COI. Ok then. Jakub