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

DTrace support broken on OS X #14808

Closed
p5pRT opened this issue Jul 18, 2015 · 11 comments
Closed

DTrace support broken on OS X #14808

p5pRT opened this issue Jul 18, 2015 · 11 comments

Comments

@p5pRT
Copy link

p5pRT commented Jul 18, 2015

Migrated from rt.perl.org#125639 (status was 'rejected')

Searchable as RT125639$

@p5pRT
Copy link
Author

p5pRT commented Jul 18, 2015

From @sevan

Mac OS X uses MACH-O rather than ELF as a binary format.
This means that the dtrace command does not have the -G flag which instructs dtrace to generate a ELF binary.
Instead, dtrace on OS X has the -arch flag which takes the supported arch parameter obtained from arch(1)
By replacing the instance of -G in the calls to dtrace (found in Makefile.SH), I was able to build perl 5.22.0 successfully on OS X 10.9.5 with dtrace support enabled.

Inline Patch
--- Makefile.SH.orig	2015-07-18 19:06:10.000000000 +0100
+++ Makefile.SH	2015-07-18 19:07:37.000000000 +0100
@@ -226,7 +226,7 @@
 case "$usedtrace" in
 define|true)
 	dtrace_h='perldtrace.h' 
-	$dtrace -G -s perldtrace.d -o perldtrace.tmp >/dev/null 2>&1 \
+	$dtrace -arch i386 -s perldtrace.d -o perldtrace.tmp >/dev/null 2>&1 \
 		&& rm -f perldtrace.tmp && dtrace_o='perldtrace$(OBJ_EXT)' \
 		&& minidtrace_o='miniperldtrace$(OBJ_EXT)'
 	;;
@@ -814,10 +814,10 @@
 	?*)
 		$spitshell >>$Makefile <<'!NO!SUBS!'
 $(DTRACE_O): perldtrace.d $(ndt_obj)
-	$(DTRACE) -G -s perldtrace.d -o $(DTRACE_O) $(ndt_obj)
+	$(DTRACE) -arch i386 -s perldtrace.d -o $(DTRACE_O) $(ndt_obj)
 
 $(MINIDTRACE_O): perldtrace.d $(minindt_obj) perlmini$(OBJ_EXT)
-	$(DTRACE) -G -s perldtrace.d -o $(MINIDTRACE_O) $(minindt_obj) perlmini$(OBJ_EXT)
+	$(DTRACE) -arch i386 -s perldtrace.d -o $(MINIDTRACE_O) $(minindt_obj) perlmini$(OBJ_EXT)
 
 !NO!SUBS!


$ sudo dtrace -ln 'perl$target:::sub-entry, perl$target:::sub-return { printf("%s %s (%s:%d)\n", probename == "sub-entry" ? "->" : "<-", copyinstr(arg0), copyinstr(arg1), arg2); }' -c /Users/sme/p5hd/bin/perl   ID PROVIDER MODULE FUNCTION NAME 4834 perl10995 libperl\.dylib Perl\_pp\_sort sub\-entry 4835 perl10995 libperl\.dylib S\_regmatch sub\-entry 4836 perl10995 libperl\.dylib Perl\_pp\_dbstate sub\-entry 4837 perl10995 libperl\.dylib Perl\_pp\_entersub sub\-entry 4838 perl10995 libperl\.dylib Perl\_pp\_sort sub\-return 4839 perl10995 libperl\.dylib Perl\_pp\_last sub\-return 4840 perl10995 libperl\.dylib Perl\_pp\_leavesublv sub\-return 4841 perl10995 libperl\.dylib S\_return\_lvalues sub\-return 4842 perl10995 libperl\.dylib Perl\_pp\_return sub\-return 4843 perl10995 libperl\.dylib Perl\_dounwind sub\-return 4844 perl10995 libperl\.dylib Perl\_pp\_leavesub sub\-return

Ofcourse this change has now broken support for Solaris & FreeBSD or any OS in the future that may have DTrace support or OS X on x86_64.
Support in Makefile.SH needs to be extended to use -G by default, unless it's on OS X, in which case use -arch with the necessary parameter obtained from arch(1) or user specified.

@p5pRT
Copy link
Author

p5pRT commented Jul 18, 2015

From @jkeenan

On Sat Jul 18 11​:23​:57 2015, venture37@​geeklan.co.uk wrote​:

Mac OS X uses MACH-O rather than ELF as a binary format.
This means that the dtrace command does not have the -G flag which
instructs dtrace to generate a ELF binary.
Instead, dtrace on OS X has the -arch flag which takes the supported
arch parameter obtained from arch(1)
By replacing the instance of -G in the calls to dtrace (found in
Makefile.SH), I was able to build perl 5.22.0 successfully on OS X
10.9.5 with dtrace support enabled.

--- Makefile.SH.orig 2015-07-18 19​:06​:10.000000000 +0100
+++ Makefile.SH 2015-07-18 19​:07​:37.000000000 +0100
@​@​ -226,7 +226,7 @​@​
case "$usedtrace" in
define|true)
dtrace_h='perldtrace.h'
- $dtrace -G -s perldtrace.d -o perldtrace.tmp >/dev/null 2>&1 \
+ $dtrace -arch i386 -s perldtrace.d -o perldtrace.tmp

/dev/null 2>&1 \
&& rm -f perldtrace.tmp &&
dtrace_o='perldtrace$(OBJ_EXT)' \
&& minidtrace_o='miniperldtrace$(OBJ_EXT)'
;;
@​@​ -814,10 +814,10 @​@​
?*)
$spitshell >>$Makefile <<'!NO!SUBS!'
$(DTRACE_O)​: perldtrace.d $(ndt_obj)
- $(DTRACE) -G -s perldtrace.d -o $(DTRACE_O) $(ndt_obj)
+ $(DTRACE) -arch i386 -s perldtrace.d -o $(DTRACE_O) $(ndt_obj)

$(MINIDTRACE_O)​: perldtrace.d $(minindt_obj) perlmini$(OBJ_EXT)
- $(DTRACE) -G -s perldtrace.d -o $(MINIDTRACE_O) $(minindt_obj)
perlmini$(OBJ_EXT)
+ $(DTRACE) -arch i386 -s perldtrace.d -o $(MINIDTRACE_O)
$(minindt_obj) perlmini$(OBJ_EXT)

!NO!SUBS!

$ sudo dtrace -ln 'perl$target​::​:sub-entry, perl$target​::​:sub-return {
printf("%s %s (%s​:%d)\n", probename == "sub-entry" ? "->" : "<-",
copyinstr(arg0), copyinstr(arg1), arg2); }' -c
/Users/sme/p5hd/bin/perl
ID PROVIDER MODULE FUNCTION
NAME
4834 perl10995 libperl.dylib Perl_pp_sort
sub-entry
4835 perl10995 libperl.dylib S_regmatch
sub-entry
4836 perl10995 libperl.dylib Perl_pp_dbstate
sub-entry
4837 perl10995 libperl.dylib Perl_pp_entersub
sub-entry
4838 perl10995 libperl.dylib Perl_pp_sort
sub-return
4839 perl10995 libperl.dylib Perl_pp_last
sub-return
4840 perl10995 libperl.dylib Perl_pp_leavesublv
sub-return
4841 perl10995 libperl.dylib S_return_lvalues
sub-return
4842 perl10995 libperl.dylib Perl_pp_return
sub-return
4843 perl10995 libperl.dylib Perl_dounwind
sub-return
4844 perl10995 libperl.dylib Perl_pp_leavesub
sub-return

Ofcourse this change has now broken support for Solaris & FreeBSD or
any OS in the future that may have DTrace support or OS X on x86_64.
Support in Makefile.SH needs to be extended to use -G by default,
unless it's on OS X, in which case use -arch with the necessary
parameter obtained from arch(1) or user specified.

Let me make sure I understand the intent of your patch. The revisions you made to Makefile.SH were made in order to build perl with dtrace support on Mac OSX on the i386 architecture -- correct?

Without these revisions, you were *not* able to build perl with dtrace support on Mac OSX/i386 -- correct?

If so, then while this patch wouldn't be suitable for other architectures, it might provide some guidance toward a patch that would cover this OS/architecture as well as others.

Do you happen to know what, if anything, has to be done to build perl with dtrace support on Mac OS X/x86_64?

(I'm assuming Darwin/PPC is too old to support dtrace at all, and I suspect that x86_64 is more common than i386 these days.)

Thank you for advancing the discussion.

--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented Jul 18, 2015

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Jul 19, 2015

From @sevan

On 18/07/2015 19​:59, James E Keenan via RT wrote​:

Let me make sure I understand the intent of your patch. The
revisions you made to Makefile.SH were made in order to build perl
with dtrace support on Mac OSX on the i386 architecture -- correct?

Correct

Without these revisions, you were *not* able to build perl with
dtrace support on Mac OSX/i386 -- correct?

Correct

If so, then while this patch wouldn't be suitable for other
architectures, it might provide some guidance toward a patch that
would cover this OS/architecture as well as others.

Correct, this is not a proposed fix, just demonstrating the changes
required to resolve the issue in one case.

Do you happen to know what, if anything, has to be done to build perl
with dtrace support on Mac OS X/x86_64?

So here's the confusing part. The mac I ran this on is a 2012 MacBook
Air with a i7 CPU and 8GB of RAM.

uname -a reports
13.4.0 Darwin Kernel Version 13.4.0​: Wed Mar 18 16​:20​:14 PDT 2015;
root​:xnu-2422.115.14~1/RELEASE_X86_64 x86_64

arch(1) reports
i386

(I'm assuming Darwin/PPC is too old to support dtrace at all, and I
suspect that x86_64 is more common than i386 these days.)

Actually, 10.5 which runs on both intel & powerpc systems comes with
DTrace. I have a powerpc system running it which I can try & provide
feedback.

Thank you for advancing the discussion.

@p5pRT
Copy link
Author

p5pRT commented Jul 21, 2015

From @tonycoz

On Sat Jul 18 23​:10​:48 2015, venture37@​geeklan.co.uk wrote​:

On 18/07/2015 19​:59, James E Keenan via RT wrote​:

Let me make sure I understand the intent of your patch. The
revisions you made to Makefile.SH were made in order to build perl
with dtrace support on Mac OSX on the i386 architecture -- correct?

Correct

Without these revisions, you were *not* able to build perl with
dtrace support on Mac OSX/i386 -- correct?

Correct

If so, then while this patch wouldn't be suitable for other
architectures, it might provide some guidance toward a patch that
would cover this OS/architecture as well as others.

Correct, this is not a proposed fix, just demonstrating the changes
required to resolve the issue in one case.

Do you happen to know what, if anything, has to be done to build perl
with dtrace support on Mac OS X/x86_64?

So here's the confusing part. The mac I ran this on is a 2012 MacBook
Air with a i7 CPU and 8GB of RAM.

uname -a reports
13.4.0 Darwin Kernel Version 13.4.0​: Wed Mar 18 16​:20​:14 PDT 2015;
root​:xnu-2422.115.14~1/RELEASE_X86_64 x86_64

arch(1) reports
i386

What does​:

  perl -V​:ptrsize

produce?

On my Mac, running 10.10.4, for a default build of bleadperl I see​:

  pallas​:perl tony$ ./perl -Ilib -V​:ptrsize
  ptrsize='8';

It also builds a dtrace enabled perl successfully, *without* your patch.

pallas​:perl tony$ sudo dtrace -ln 'perl$target​::​:sub-entry, perl$target​::​:sub-return { printf("%s %s (%s​:%d)\n", probename == "sub-entry" ? "->" : "<-", copyinstr(arg0), copyinstr(arg1), arg2); }' -c /Users/tony/dev/perl/git/perl/perl
Password​:
  ID PROVIDER MODULE FUNCTION NAME
11503 perl28269 perl Perl_pp_sort sub-entry
11504 perl28269 perl S_regmatch sub-entry
11505 perl28269 perl Perl_pp_dbstate sub-entry
11506 perl28269 perl Perl_pp_entersub sub-entry
11507 perl28269 perl Perl_pp_sort sub-return
11508 perl28269 perl Perl_pp_leavesublv sub-return
11509 perl28269 perl Perl_dounwind sub-return
11510 perl28269 perl Perl_pp_leavesub sub-return

I'm testing on a Mac mini server (Mid 2011) (which has a Core i7), and a iMac (20-inch, Early 2008) (Core 2 Duo). Both built a -Dusedtrace build or bleadperl without errors.

Tony

@p5pRT
Copy link
Author

p5pRT commented Jul 21, 2015

From @sevan

On 21/07/2015 08​:01, Tony Cook via RT wrote​:

What does​:

perl -V​:ptrsize

produce?

ptrsize='4';

It also builds a dtrace enabled perl successfully, *without* your patch.

What does sudo dtrace --h say, on 10.9.5 there is no -G option.

Usage​: dtrace [-aACeFHlqSvVwZ] [-arch i386|x86_64] [-b bufsz] [-c cmd]
[-D name[=def]]
  [-I path] [-L path] [-o output] [-p pid] [-s script] [-U name]
  [-x opt[=val]]

  [-P provider [[ predicate ] action ]]
  [-m [ provider​: ] module [[ predicate ] action ]]
  [-f [[ provider​: ] module​: ] func [[ predicate ] action ]]
  [-n [[[ provider​: ] module​: ] func​: ] name [[ predicate ] action ]]
  [-i probe-id [[ predicate ] action ]] [ args ... ]

  predicate -> '/' D-expression '/'
  action -> '{' D-statements '}'

  -arch Generate programs and Mach-O files for the specified architecture

  -a claim anonymous tracing state
  -A generate plist(5) entries for anonymous tracing
  -b set trace buffer size
  -c run specified command and exit upon its completion
  -C run cpp(1) preprocessor on script files
  -D define symbol when invoking preprocessor
  -e exit after compiling request but prior to enabling probes
  -f enable or list probes matching the specified function name
  -F coalesce trace output by function
  -h generate a header file with definitions for static probes
  -H print included files when invoking preprocessor
  -i enable or list probes matching the specified probe id
  -I add include directory to preprocessor search path
  -l list probes matching specified criteria
  -L add library directory to library search path
  -m enable or list probes matching the specified module name
  -n enable or list probes matching the specified probe name
  -o set output file
  -p grab specified process-ID and cache its symbol tables
  -P enable or list probes matching the specified provider name
  -q set quiet mode (only output explicitly traced data)
  -s enable or list probes according to the specified D script
  -S print D compiler intermediate code
  -U undefine symbol when invoking preprocessor
  -v set verbose mode (report stability attributes, arguments)
  -V report DTrace API version
  -w permit destructive actions
  -x enable or modify compiler and tracing options
  -Z permit probe descriptions that match zero probes

@p5pRT
Copy link
Author

p5pRT commented Jul 21, 2015

From @tonycoz

On Tue Jul 21 05​:13​:36 2015, venture37@​geeklan.co.uk wrote​:

On 21/07/2015 08​:01, Tony Cook via RT wrote​:

What does​:

perl -V​:ptrsize

produce?

ptrsize='4';

Is that the Apple supplied system perl, or from a separate packaged perl?

What bit-ness are your system processes running at?

You can see it in Activity Monitor, you may need to use View, Columns, Kind to add a column to display it, but I recall older OS X displayed the bitness as part of the process name.

It also builds a dtrace enabled perl successfully, *without* your patch.

What does sudo dtrace --h say, on 10.9.5 there is no -G option.

I get​:

pallas​:~ tony$ dtrace --h
Usage​: dtrace [-aACeFHlqSvVwZ] [-arch i386|x86_64] [-b bufsz] [-c cmd] [-D name[=def]]
  [-I path] [-L path] [-o output] [-p pid] [-s script] [-U name]
  [-x opt[=val]]

  [-P provider [[ predicate ] action ]]
  [-m [ provider​: ] module [[ predicate ] action ]]
  [-f [[ provider​: ] module​: ] func [[ predicate ] action ]]
  [-n [[[ provider​: ] module​: ] func​: ] name [[ predicate ] action ]]
  [-i probe-id [[ predicate ] action ]] [ args ... ]

  predicate -> '/' D-expression '/'
  action -> '{' D-statements '}'

  -arch Generate programs and Mach-O files for the specified architecture

  -a claim anonymous tracing state
  -A generate plist(5) entries for anonymous tracing
  -b set trace buffer size
  -c run specified command and exit upon its completion
  -C run cpp(1) preprocessor on script files
  -D define symbol when invoking preprocessor
  -e exit after compiling request but prior to enabling probes
  -f enable or list probes matching the specified function name
  -F coalesce trace output by function
  -h generate a header file with definitions for static probes
  -H print included files when invoking preprocessor
  -i enable or list probes matching the specified probe id
  -I add include directory to preprocessor search path
  -l list probes matching specified criteria
  -L add library directory to library search path
  -m enable or list probes matching the specified module name
  -n enable or list probes matching the specified probe name
  -o set output file
  -p grab specified process-ID and cache its symbol tables
  -P enable or list probes matching the specified provider name
  -q set quiet mode (only output explicitly traced data)
  -s enable or list probes according to the specified D script
  -S print D compiler intermediate code
  -U undefine symbol when invoking preprocessor
  -v set verbose mode (report stability attributes, arguments)
  -V report DTrace API version
  -w permit destructive actions
  -x enable or modify compiler and tracing options
  -Z permit probe descriptions that match zero probes

There are actually four platforms with dtrace support of some sort​:

- Solaris
- OS X
- FreeBSD (currently broken in perl, seemed to be a FreeBSD issue last time I looked)
- Linux - emulated by systemtap, needs more setup than we supply

To handle the OS X alternate generate option, I think we'd add a new config variable, say dtrace_generate, which defaults to "-G", and hints/darwin.sh can modify it to suit the current architecture, we just need a way to work out the correct architecture.

From your previous messages we can't use arch to detect the architecture to supply to dtrace, since arch on my 64-bit systems produces "i386".

Tony

@p5pRT
Copy link
Author

p5pRT commented Jul 22, 2015

From @craigberry

On Tue, Jul 21, 2015 at 6​:51 PM, Tony Cook via RT
<perlbug-followup@​perl.org> wrote​:

From your previous messages we can't use arch to detect the architecture to supply to dtrace, since arch on my 64-bit systems produces "i386".

That's just the architecture family. uname -m will give you x86_64 if
that's what you've got.

@p5pRT
Copy link
Author

p5pRT commented Jul 21, 2016

From @sevan

Please close this bug report, issue turned out to related to pkgsrc which is now fixed. Perl 5 with dtrace support works without issue on Leopard & newer (personally tested on 10.5.8 & 10.9.5 (powerpc & x86_64)).

@p5pRT
Copy link
Author

p5pRT commented Jul 22, 2016

From @jkeenan

On Thu Jul 21 06​:56​:13 2016, venture37@​geeklan.co.uk wrote​:

Please close this bug report, issue turned out to related to pkgsrc
which is now fixed. Perl 5 with dtrace support works without issue on
Leopard & newer (personally tested on 10.5.8 & 10.9.5 (powerpc &
x86_64)).

Closing per request from original poster.

--
James E Keenan (jkeenan@​cpan.org)

@p5pRT p5pRT closed this as completed Jul 22, 2016
@p5pRT
Copy link
Author

p5pRT commented Jul 22, 2016

@jkeenan - Status changed from 'open' to 'rejected'

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

1 participant