summaryrefslogtreecommitdiff
path: root/databases/libcouchbase/files/patch-cmake_dtrace-instr-link.pl
blob: 743fcee62d202ff04cc6bdf90b471183dc141824 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
--- cmake/dtrace-instr-link.pl.orig	2016-08-05 21:38:44 UTC
+++ cmake/dtrace-instr-link.pl
@@ -3,7 +3,7 @@ use strict;
 use warnings;
 use Digest::MD5 qw(md5_hex);
 
-my $HDR = "** $0:";
+my $HDR = "** $0 ($$):";
 $\="\n";
 
 my $DT_SRC = shift @ARGV;
@@ -16,23 +16,36 @@ if (!scalar @O_FILES) {
     exec($CMD,@ARGV);
 }
 
+# Copy .o files to a temporary location before DTrace messes with them
+chomp(my $tmpdir = `mktemp -d -t $$`);
+if (system("tar cf - @O_FILES | tar xf - -C $tmpdir") != 0) {
+    system("rm -r $tmpdir");
+    exit(1);
+}
+
 my $ss = join('_', @O_FILES);
 my $hexstr = md5_hex($ss);
 
-my $INSTRUMENTED = "generated/probes_${hexstr}.o";
+# From now, we work with files in the temporary location, update @ARGV
+map { $_ =~ s,.+\.o$,$tmpdir/$&, } @ARGV;
+
+my $INSTRUMENTED = "generated/probes_${hexstr}_$$.o";
 # Run DTrace instrumentation. Assuming running from build directory:
 my @args = (
     'dtrace', '-C', '-G',
     '-s', $DT_SRC,
     '-o', $INSTRUMENTED,
-    @O_FILES);
+    grep { $_ =~ /\.o$/ } @ARGV);
 
 print "$HDR: Creating instrumented DTrace object: @args";
 if (system(@args) != 0) {
+    system("rm -r $tmpdir");
     exit(1);
 }
 
 unshift @ARGV, $CMD;
 push @ARGV, $INSTRUMENTED;
 print "$HDR: Linking with instrumented DTrace object: @ARGV";
-exit(system(@ARGV));
+my $rc = system(@ARGV);
+system("rm -r $tmpdir");
+exit($rc);