Imagemagick: "Error: X unsupported relocations" when resizing on radeon hardware

Created on 15 Oct 2018  路  9Comments  路  Source: ImageMagick/ImageMagick

Prerequisites

  • [x] I have written a descriptive issue title
  • [x] I have verified that I am using the latest version of ImageMagick
  • [x] I have searched open and closed issues to ensure it has not already been reported

Previously mentioned at http://www.imagemagick.org/discourse-server/viewtopic.php?t=34758

Description

Trying to convert -resize any image results in a failure like this:

Error: 8 unsupported relocations
Error: 8 unsupported relocations
Error: 8 unsupported relocations
Error: 8 unsupported relocations
Error: 8 unsupported relocations
Segmentation fault (core dumped)

The full gdb backtrace for one such failed invocation is up at https://gist.github.com/stuartpb/1f7885c33938551461085ff383410dd5.

Based on this, @loqs tracked this down on the Arch Linux forums to an error coming out of Mesa (right around here) about the shader ImageMagick is handing it.

The number of unsupported relocations crashing the magick process appears to vary from machine to machine: it might be tied to the number of cores available (the gdb dump I'm linking here is from a system with an 8-core processor).

Steps to Reproduce

From the looks of things, this happens any time you try to downscale an image on an up-to-date Arch Linux install with an AMD graphics card: for example, dylanaraps/pywal#299 points to one notable invocation that triggers it on the affected hardware.

System Configuration

Present on ImageMagick 7.0.8-12 Q16 x86_64 2018-09-23 https://imagemagick.org

The current version of Mesa in Arch Linux (where this error started getting reported) is 18.2.2-1.

bug

All 9 comments

This looks like a bug inside the ImageMagick code. We recursively call DestroyMagickCLCacheInfoAndPixels when the status is not CL_COMPLETE:

if ((status == CL_SUCCESS) && (event_status != CL_COMPLETE))
  {
    openCL_library->clSetEventCallback(info->events[i],CL_COMPLETE,
      &DestroyMagickCLCacheInfoAndPixels,info);
    return;
  }

But it turns out that we can also get a negative value (https://www.khronos.org/registry/OpenCL/sdk/1.1/docs/man/xhtml/clGetEventInfo.html) when an error occurred. We need to correct this check.

But I don't understand why you get that error message or if we have caused that. And are you able to test a patch to check if we no longer get a segmentation fault after our patch has been applied to the master?

Sure, I can test a patch.

What happens when you change the check to: if ((status == CL_SUCCESS) && (event_status > CL_COMPLETE))?

Shouldn't that be (event_status < CL_COMPLETE && event_status > 0)? And shouldn't there be a check for what the error return code (if any) is?

CL_COMPLETE is zero so that is the same check. We cannot really do anything with the error code so we don't need to check what it is. We are here only checking that all events have been completed.

Oh, I misread the documentation (I thought it said the states go from smallest to largest, not the other way around).

I'll give it a shot (I've never manually patched a compiled package before, so this might take a few hours). I take it the line to patch is here (MagickCore/opencl.c line 2901)?

That is indeed the correct spot to patch. And thanks for helping me test this.

Looks like that patch fixes it: I just ran a build that includes a convert line to produce smaller icons that had the failure that originally prompted me to file this issue (and ImageMagick's in-tree tests/validate-convert.tap failed on the pre-patch code), and it's working now (as is validate-convert.tap).

Just pushed a patch to resolve this issue. And thanks again for helping me out!

Was this page helpful?
0 / 5 - 0 ratings