[PATCH 3/3] test: adjust tst.pidprobes.sh to account for PIE executables

Kris Van Hees <[email protected]> Mon, 09 Feb 2026 15:43:50 -0500
Newsgroups dev.linux.lists.dtrace
Message-ID <DS0PR10MB7522B4C2136DC1C1BBE9EC54C265A@DS0PR10MB7522.namprd10.prod.outlook.com>
When the test executable is compiled as position independent code,
the comparison with expected reults fails unless the reported PC
values are adjusted based on the actual load address.  This is safe
to do in general, because for non-PIE cases the adjustment will be
0.

Signed-off-by: Kris Van Hees <[email protected]>
---
 test/unittest/usdt/tst.pidprobes.sh | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/test/unittest/usdt/tst.pidprobes.sh b/test/unittest/usdt/tst.pidprobes.sh
index 24fbd518..80de5140 100755
--- a/test/unittest/usdt/tst.pidprobes.sh
+++ b/test/unittest/usdt/tst.pidprobes.sh
@@ -1,7 +1,7 @@
 #!/bin/bash
 #
 # Oracle Linux DTrace.
-# Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2024, 2026, Oracle and/or its affiliates. All rights reserved.
 # Licensed under the Universal Permissive License v 1.0 as shown at
 # http://oss.oracle.com/licenses/upl.
 #
@@ -119,8 +119,11 @@ fi
 pcs=`awk '{print strtonum("0x"$1)}' disasm_foo.txt`
 pc0=`echo $pcs | awk '{print $1}'`
 
-# Construct D script:  add a pid$pid::-:$absoff probe for each PC in foo.
+# Construct D script:  add a pid$pid::-:$pc0 probe to determine base address.
+printf 'p*d$target::-:%x\n' $pc0 >> pidprobes.d
+printf '{\n\tbase = uregs[R_PC] - %s;\n}\n' $pc0 >> pidprobes.d
 
+# Construct D script:  add a pid$pid::-:$absoff probe for each PC in foo.
 for pc in $pcs; do
 	printf 'p*d$target::-:%x,\n' $pc >> pidprobes.d
 done
@@ -130,7 +133,7 @@ done
 cat >> pidprobes.d <<'EOF'
 p*d$target::foo:
 {
-	printf("%d %s:%s:%s:%s %x\n", pid, probeprov, probemod, probefunc, probename, uregs[R_PC]);
+	printf("%d %s:%s:%s:%s %x\n", pid, probeprov, probemod, probefunc, probename, uregs[R_PC] - base);
 }
 EOF
 
-- 
2.51.0