|
From: Kingsley, J. L. <jki...@WP...> - 2013-08-06 18:32:09
|
Attempting to use valgrind on my system gives me an 'unrecognised instruction' error. I am reasonably sure that it's a valgrind issue
Minimal working example:
----------------
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main(int argc, char* argv[]) {
double val = atof(argv[1]);
printf("the log of %lf is %lf\n", val, log(val));
return 0;
}
-----------------------
Compiled and executed with:
$ gcc -o logtest logtest.c -lm
$ ./logtest 32
the log of 32.000000 is 3.465736
$ valgrind --tool=callgrind ./logtest 32
==25013== Callgrind, a call-graph generating cache profiler
==25013== Copyright (C) 2002-2012, and GNU GPL'd, by Josef Weidendorfer et al.
==25013== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==25013== Command: ./logtest 32
==25013==
==25013== For interactive control, run 'callgrind_control -h'.
vex amd64->IR: unhandled instruction bytes: 0xC4 0xE3 0xD9 0x6B 0x3D 0x4E 0x19 0x6
vex amd64->IR: REX=0 REX.W=1 REX.R=0 REX.X=0 REX.B=0
vex amd64->IR: VEX=1 VEX.L=0 VEX.nVVVV=0x4 ESC=0F3A
vex amd64->IR: PFX.66=1 PFX.F2=0 PFX.F3=0
==25013== valgrind: Unrecognised instruction at address 0x4c37a00.
==25013== at 0x4C37A00: __ieee754_log_sse2 (in /lib64/libm-2.15.so)
==25013== by 0x400674: main (in /home/jkingsley/foo/logtest)
==25013== Your program just tried to execute an instruction that Valgrind
==25013== did not recognise. There are two possible reasons for this.
==25013== 1. Your program has a bug and erroneously jumped to a non-code
==25013== location. If you are running Memcheck and you just saw a
==25013== warning about a bad jump, it's probably your program's fault.
==25013== 2. The instruction is legitimate but Valgrind doesn't handle it,
==25013== i.e. it's Valgrind's fault. If you think this is the case or
==25013== you are not sure, please let us know and we'll try to fix it.
==25013== Either way, Valgrind will now raise a SIGILL signal which will
==25013== probably kill your program.
==25013==
==25013== Process terminating with default action of signal 4 (SIGILL)
==25013== Illegal opcode at address 0x4C37A00
==25013== at 0x4C37A00: __ieee754_log_sse2 (in /lib64/libm-2.15.so)
==25013== by 0x400674: main (in /home/jkingsley/foo/logtest)
==25013==
==25013== Events : Ir
==25013== Collected : 116873
==25013==
==25013== I refs: 116,873
Illegal instruction
------------------------
Other tools have the same issue.
I am running this on a AMD FX(tm)-8150, and libm would have been compiled with gcc 4.6.3 `-O2 -pipe -march=native -mtune=native`, which gives settings flags
$ gcc -c -Q -march=native --help=target
The following options are target specific:
-m128bit-long-double [disabled]
-m32 [disabled]
-m3dnow [disabled]
-m3dnowa [disabled]
-m64 [enabled]
-m80387 [enabled]
-m8bit-idiv [disabled]
-m96bit-long-double [enabled]
-mabi=
-mabm [enabled]
-maccumulate-outgoing-args [disabled]
-maes [enabled]
-malign-double [disabled]
-malign-functions=
-malign-jumps=
-malign-loops=
-malign-stringops [enabled]
-mandroid [disabled]
-march= bdver1
-masm=
-mavx [enabled]
-mavx256-split-unaligned-load [disabled]
-mavx256-split-unaligned-store [disabled]
-mbionic [disabled]
-mbmi [disabled]
-mbranch-cost=
-mcld [disabled]
-mcmodel=
-mcpu=
-mcrc32 [disabled]
-mcx16 [enabled]
-mdispatch-scheduler [disabled]
-mf16c [disabled]
-mfancy-math-387 [enabled]
-mfentry [enabled]
-mfma [disabled]
-mfma4 [enabled]
-mforce-drap [disabled]
-mfp-ret-in-387 [enabled]
-mfpmath=
-mfsgsbase [disabled]
-mfused-madd
-mglibc [enabled]
-mhard-float [enabled]
-mieee-fp [enabled]
-mincoming-stack-boundary=
-minline-all-stringops [disabled]
-minline-stringops-dynamically [disabled]
-mintel-syntax
-mlarge-data-threshold=
-mlwp [enabled]
-mmmx [disabled]
-mmovbe [disabled]
-mms-bitfields [disabled]
-mno-align-stringops [disabled]
-mno-fancy-math-387 [disabled]
-mno-push-args [disabled]
-mno-red-zone [disabled]
-mno-sse4 [disabled]
-momit-leaf-frame-pointer [disabled]
-mpc
-mpclmul [enabled]
-mpopcnt [enabled]
-mprefer-avx128 [disabled]
-mpreferred-stack-boundary=
-mpush-args [enabled]
-mrdrnd [disabled]
-mrecip [disabled]
-mred-zone [enabled]
-mregparm=
-mrtd [disabled]
-msahf [enabled]
-msoft-float [disabled]
-msse [enabled]
-msse2 [enabled]
-msse2avx [disabled]
-msse3 [enabled]
-msse4 [enabled]
-msse4.1 [enabled]
-msse4.2 [enabled]
-msse4a [enabled]
-msse5
-msseregparm [disabled]
-mssse3 [enabled]
-mstack-arg-probe [disabled]
-mstackrealign [enabled]
-mstringop-strategy=
-mtbm [disabled]
-mtls-dialect=
-mtls-direct-seg-refs [enabled]
-mtune= bdver1
-muclibc [disabled]
-mveclibabi=
-mvect8-ret-in-mem [disabled]
-mvzeroupper [disabled]
-mxop [enabled]
---------------------
Any suggestions on fixing this? I'm not entirely sure how I would go about making a valgrind-friendly libm, and don't really want to recompile my system without SSE just to do a bit of debugging...
Thanks,
James Kingsley
|
|
From: Florian K. <br...@ac...> - 2013-08-06 20:07:16
|
On 08/06/2013 08:02 PM, Kingsley, James Leonard wrote: > Attempting to use valgrind on my system gives me an 'unrecognised instruction' error. I am reasonably sure that it's a valgrind issue > Yes, it is. > vex amd64->IR: unhandled instruction bytes: 0xC4 0xE3 0xD9 0x6B 0x3D 0x4E 0x19 0x6 > vex amd64->IR: REX=0 REX.W=1 REX.R=0 REX.X=0 REX.B=0 > vex amd64->IR: VEX=1 VEX.L=0 VEX.nVVVV=0x4 ESC=0F3A > vex amd64->IR: PFX.66=1 PFX.F2=0 PFX.F3=0 > ==25013== valgrind: Unrecognised instruction at address 0x4c37a00. > ==25013== at 0x4C37A00: __ieee754_log_sse2 (in /lib64/libm-2.15.so) This function has caused trouble before. See https://bugs.kde.org/show_bug.cgi?id=320965 > > Any suggestions on fixing this? No work-around really, other than recompiling libm with a suitable set of compiler flags (I would not know what those are). If you're brave and have some time, you might be interested in adding support for this instruction to valgrind. The code to look at would be in <valgrind>/VEX/priv/guest_amd64_toIR.c, function disInstr_AMD64_WRK and underneath. Florian |
|
From: Julian S. <js...@ac...> - 2013-08-06 20:32:13
|
On 08/06/2013 10:07 PM, Florian Krohm wrote: > No work-around really, other than recompiling libm with a suitable set > of compiler flags (I would not know what those are). I'm pretty sure this is caused by an AMD-specific insn set extension, but I don't know which one. If you constrain the compiler to avoid AMD-specifics you might be better off. Also, try using the valgrind svn trunk as the insn set support has been updated since 3.8.1. I'd say it's less likely to help, but is worth a try. svn co svn://svn.valgrind.org/valgrind/trunk cd trunk ./autogen.sh Then configure and build as with the tarball. J |