Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Illegal instruction when executing under valgrind #12

Closed
DRMacIver opened this issue May 26, 2013 · 2 comments
Closed

Illegal instruction when executing under valgrind #12

DRMacIver opened this issue May 26, 2013 · 2 comments

Comments

@DRMacIver
Copy link

If I run the following program to emit an executable from terra then run it under valgrind, valgrind complains about there being an illegal instruction:

stdlib = terralib.includec("stdlib.h")

local length = 8

local struct Entry{
  key : int,
}

local struct Table{
  occupancy : uint64,
  entries : &Entry
}

terra Table:find_entry(key : int) : &Entry
  if self.occupancy >= 6.0  then
    self:find_entry(key)
    return self:find_entry(key)
  else
    self.entries.key = key
    return self.entries
  end
end

terra main()
  var x : Table
  x.occupancy = 0
  x.entries = [&Entry](stdlib.calloc(length, sizeof(Entry)))
  x:find_entry(1)
  return 0
end

terralib.saveobj("bug", {main=main})

Valgrind error:

vex amd64->IR: unhandled instruction bytes: 0xC5 0xFA 0x7E 0x3 0xC5 0xF9 0x62 0x5
==22573== valgrind: Unrecognised instruction at address 0x400518.
==22573==    at 0x400518: Table_methods_find_entry0 (in /home/david/projects/terra/bug)
==22573== Your program just tried to execute an instruction that Valgrind
==22573== did not recognise.  There are two possible reasons for this.
==22573== 1. Your program has a bug and erroneously jumped to a non-code
==22573==    location.  If you are running Memcheck and you just saw a
==22573==    warning about a bad jump, it's probably your program's fault.
==22573== 2. The instruction is legitimate but Valgrind doesn't handle it,
==22573==    i.e. it's Valgrind's fault.  If you think this is the case or
==22573==    you are not sure, please let us know and we'll try to fix it.
==22573== Either way, Valgrind will now raise a SIGILL signal which will
==22573== probably kill your program.
==22573== 
==22573== Process terminating with default action of signal 4 (SIGILL)
==22573==  Illegal opcode at address 0x400518
==22573==    at 0x400518: Table_methods_find_entry0 (in /home/david/projects/terra/bug)
@zdevito
Copy link
Collaborator

zdevito commented May 26, 2013

The instruction bytes correspond to: vmovq xmm0,QWORD PTR [rbx], which is an AVX instruction that is relatively new. valgrind (or the version installed) might not know it yet. Does the code actually run for you? We currently just assume AVX instructions are available, but that wouldn't be too difficult to fix.

@DRMacIver
Copy link
Author

Ah, I beg your pardon, you're entirely right. The code runs fine, and upgrading valgrind causes it to stop complaining.

The one I had was the latest version packaged with Ubuntu, so this will probably be a fairly common problem until the new version makes it into various repos, but as long as there's a version that works I don't really mind upgrading.

@zdevito zdevito closed this as completed Jun 21, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants