When exif writes a 'modified' JPEG file from an original with XMP information (e.g. as per the attached file), then the new file does not contain XMP information.
Such as running the exif tool to insert any thumbnail image eg:
exif -n=thumb.jpg blank-xmp.jpg
Checking the XMP information can be viewed via recent versions of eog or any version of exiftool e.g.:
exiftool -xmp blank-xmp.jpg exiftool -xmp blank-xmp.jpg.modified.jpeg
Indeed creating/inserting XMP information on any image file (this was how the attachment was created) can be done with exiftool:
exiftool -xmp:usercomment=XMP Test Comment' <file.jpg> -overwrite_original
I believe that libexif doesn't specifically support XMP information, but I think that XMP information is in the APP1 section of a JPEG file, so then the exif tool should maintain it.
The attached image doesn't have an XMP section but I was able to easily reproduce the problem. The issue is probably that XMP and EXIF are both stored in an APP1 but exif only cares about EXIF. I agree, it should preserve any sections it doesn't recognize, including APP1 sections that are not EXIF.
Diff: