Paul Nasrat
2008-Mar-11 23:00 UTC
[dtrace-discuss] Bad instruction on x86_64 build on OS X with DTRACE_PROBE
I was looking at mod_trace (http://prefetch.net/projects/apache_modtrace/index.html ) and playing with getting it to compile on OS X. When building for x86_64 with -arch x86_64 we get bad instructions generated: gcc -o foo -arch x86_64 foo.c /var/folders/rV/rV1x2DafFr0R6tGG+1bbk++++TM/-Tmp-//ccnykQ1o.s:11:bad register name `%%esi)'' Using gcc -S I can definitely see we are not generating correct code: LCFI1: __dtrace_probe$6_foo___probe__noargs: nop leal 0(%%esi), %%esi Building with -arch i386 works, DTRACE_PROBE1, etc also seem to work on OS X based on the building mod_trace. I attach a simple reproducer, changing the Makefile to build with - arch i386 works. Simply extract onto a Leopard box, cd into the extracted dir and run make to see the failure. make foo.s will create the generated asm. $ gcc -v Using built-in specs. Target: i686-apple-darwin9 Configured with: /var/tmp/gcc/gcc-5465~16/src/configure --disable- checking -enable-werror --prefix=/usr --mandir=/share/man --enable- languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/ $/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/ lib --build=i686-apple-darwin9 --with-arch=apple --with-tune=generic -- host=i686-apple-darwin9 --target=i686-apple-darwin9 Thread model: posix gcc version 4.0.1 (Apple Inc. build 5465) $ dtrace -V dtrace: Sun D 1.2.2 Paul -------------- next part -------------- A non-text attachment was scrubbed... Name: dtrace-osx-bug.tgz Type: application/octet-stream Size: 464 bytes Desc: not available URL: <http://mail.opensolaris.org/pipermail/dtrace-discuss/attachments/20080311/9d464630/attachment.obj> -------------- next part --------------
James McIlree
2008-Mar-11 23:19 UTC
[dtrace-discuss] Bad instruction on x86_64 build on OS X with DTRACE_PROBE
On Mar 11, 2008, at 4:00 PM, Paul Nasrat wrote:> I was looking at mod_trace (http://prefetch.net/projects/apache_modtrace/index.html > ) and playing with getting it to compile on OS X. > > When building for x86_64 with -arch x86_64 we get bad instructions > generated: > > gcc -o foo -arch x86_64 foo.c > /var/folders/rV/rV1x2DafFr0R6tGG+1bbk++++TM/-Tmp-//ccnykQ1o.s:11:bad > register name `%%esi)'' > > > Using gcc -S I can definitely see we are not generating correct code: > > LCFI1: > __dtrace_probe$6_foo___probe__noargs: > nop > leal 0(%%esi), %%esi > > Building with -arch i386 works, DTRACE_PROBE1, etc also seem to work > on OS X based on the building mod_trace. > > I attach a simple reproducer, changing the Makefile to build with - > arch i386 works. Simply extract onto a Leopard box, cd into the > extracted dir and run make to see the failure. make foo.s will > create the generated asm. > > $ gcc -v > Using built-in specs. > Target: i686-apple-darwin9 > Configured with: /var/tmp/gcc/gcc-5465~16/src/configure --disable- > checking -enable-werror --prefix=/usr --mandir=/share/man --enable- > languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/ > s/$/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/ > usr/lib --build=i686-apple-darwin9 --with-arch=apple --with- > tune=generic --host=i686-apple-darwin9 --target=i686-apple-darwin9 > Thread model: posix > gcc version 4.0.1 (Apple Inc. build 5465) > $ dtrace -V > dtrace: Sun D 1.2.2Paul, The DTRACE_PROBE# macros are not supported on OS X. That is why you''re running into issues. James M
Paul Nasrat
2008-Mar-12 07:27 UTC
[dtrace-discuss] Bad instruction on x86_64 build on OS X with DTRACE_PROBE
On 11 Mar 2008, at 23:19, James McIlree wrote:> > >> I was looking at mod_trace (http://prefetch.net/projects/apache_modtrace/index.html >> ) and playing with getting it to compile on OS X. >> >> When building for x86_64 with -arch x86_64 we get bad instructions >> generated: >> >> gcc -o foo -arch x86_64 foo.c >> /var/folders/rV/rV1x2DafFr0R6tGG+1bbk++++TM/-Tmp-//ccnykQ1o.s: >> 11:bad register name `%%esi)'' >> > > The DTRACE_PROBE# macros are not supported on OS X. That is why > you''re running into issues.If they''re not supported shouldn''t I at least get a warning. Any pointers to the right way to do things? I note that the root cause is actually a bad define in /usr/include/mach/i386/sdt_isa.h: #ifdef __x86_64__ #define DTRACE_NOPS \ "nop" "\n\t" \ "leal 0(%%esi), %%esi" "\n\t" Paul
Steve Peters
2008-Mar-12 16:15 UTC
[dtrace-discuss] Bad instruction on x86_64 build on OS X with DTRACE_PROBE
On Mar 12, 2008, at 12:27 AM, Paul Nasrat wrote:> Any > pointers to the right way to do things?% man dtrace ... "BUILDING CODE CONTAINING USDT PROBES The process of adding USDT probes to code is slightly different than documented in the Solaris Dynamic Tracing Guide. The steps for adding probes are as follows:" ... SCP -- Steve Peters scp at mac.com
Paul Nasrat
2008-Mar-12 16:19 UTC
[dtrace-discuss] Bad instruction on x86_64 build on OS X with DTRACE_PROBE
On 12 Mar 2008, at 16:15, Steve Peters wrote:> > On Mar 12, 2008, at 12:27 AM, Paul Nasrat wrote: > >> Any >> pointers to the right way to do things? > > % man dtrace > ... > "BUILDING CODE CONTAINING USDT PROBES > The process of adding USDT probes to code is slightly > different than documented in the Solaris Dynamic > Tracing Guide. The steps for adding probes are as follows:"Yeah thanks I''d already figured that out. Is it worth updating http://wikis.sun.com/display/DTrace/Statically+Defined+Tracing+for+User+Applications ? Paul
Adam Leventhal
2008-Mar-12 17:32 UTC
[dtrace-discuss] Bad instruction on x86_64 build on OS X with DTRACE_PROBE
On Wed, Mar 12, 2008 at 04:19:05PM +0000, Paul Nasrat wrote:> Yeah thanks I''d already figured that out. > > Is it worth updating http://wikis.sun.com/display/DTrace/Statically+Defined+Tracing+for+User+ApplicationsYes. Here''s another example: http://blogs.sun.com/ahl/entry/user_land_tracing_gets_better Adam -- Adam Leventhal, Fishworks http://blogs.sun.com/ahl
James McIlree
2008-Mar-12 17:43 UTC
[dtrace-discuss] Bad instruction on x86_64 build on OS X with DTRACE_PROBE
On Mar 12, 2008, at 12:27 AM, Paul Nasrat wrote:> > On 11 Mar 2008, at 23:19, James McIlree wrote: >> >> >>> I was looking at mod_trace (http://prefetch.net/projects/apache_modtrace/index.html >>> ) and playing with getting it to compile on OS X. >>> >>> When building for x86_64 with -arch x86_64 we get bad instructions >>> generated: >>> >>> gcc -o foo -arch x86_64 foo.c >>> /var/folders/rV/rV1x2DafFr0R6tGG+1bbk++++TM/-Tmp-//ccnykQ1o.s: >>> 11:bad register name `%%esi)'' >>> >> >> The DTRACE_PROBE# macros are not supported on OS X. That is why >> you''re running into issues. > > If they''re not supported shouldn''t I at least get a warning. Any > pointers to the right way to do things? > > I note that the root cause is actually a bad define in > > /usr/include/mach/i386/sdt_isa.h: > > #ifdef __x86_64__ > > #define DTRACE_NOPS \ > "nop" "\n\t" \ > "leal 0(%%esi), %%esi" "\n\t"I thought we had #ifdef''d these so they wouldn''t be available without some hackery, but I''m not seeing the guards. Yes, you should have gotten a warning :-). I filed: <rdar://problem/5795255> Disallow use of DTRACE_PROBE macros James M