[DTrace-devel] [PATCH] test: Detect correct libc "start main" frame depending on glibc version

eugene.loh at oracle.com eugene.loh at oracle.com
Wed Jan 12 22:14:38 UTC 2022


From: Eugene Loh <eugene.loh at oracle.com>

Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
 test/unittest/ustack/tst.ustack_profile.r   |  2 +-
 test/unittest/ustack/tst.ustack_profile.r.p | 24 +++++++++++++++++----
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/test/unittest/ustack/tst.ustack_profile.r b/test/unittest/ustack/tst.ustack_profile.r
index 79b1cfbb..f24b0162 100644
--- a/test/unittest/ustack/tst.ustack_profile.r
+++ b/test/unittest/ustack/tst.ustack_profile.r
@@ -62,4 +62,4 @@
               ustack-tst-basic`myfunc_1+{ptr}
               ustack-tst-basic`myfunc_0+{ptr}
               ustack-tst-basic`main+{ptr}
-              libc.so.6`__libc_start_main+{ptr}
+              libc.so.6`XXXSTART_MAINXXX+{ptr}
diff --git a/test/unittest/ustack/tst.ustack_profile.r.p b/test/unittest/ustack/tst.ustack_profile.r.p
index 9c6a0dfb..0504cbef 100755
--- a/test/unittest/ustack/tst.ustack_profile.r.p
+++ b/test/unittest/ustack/tst.ustack_profile.r.p
@@ -1,11 +1,27 @@
-#!/usr/bin/gawk -f
+#!/bin/bash
 # Oracle Linux DTrace.
-# Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2021, 2022, 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.
 
-# if we get to a frame we do not recognize, but we saw "main", exit
+# Determine if glibc version is at least 2.34.
+read VERSMAJOR VERSMINOR <<< `ldd --version | awk '/^ldd/ {print $NF}' | tr '.' ' '`
+if [ $VERSMAJOR -lt 2 ]; then
+        VERS234=0
+elif [ $VERSMAJOR -gt 2 ]; then
+        VERS234=1
+elif [ $VERSMINOR -lt 34 ]; then
+        VERS234=0
+else
+        VERS234=1
+fi
+
+# If we get to a frame we do not recognize, but we saw "main", exit.
+# Rename the __libc_start_main frame, depending on glibc version.
+awk '
 BEGIN { saw_main = 0 }
 !/myfunc_/ && !/main/ && saw_main { exit(0) }
+  '$VERS234' { sub("__libc_start_call_main", "XXXSTART_MAINXXX") }
+! '$VERS234' { sub("__libc_start_main",      "XXXSTART_MAINXXX") }
 { print }
-/main/ { saw_main = 1 }
+/main/ { saw_main = 1 }'
-- 
2.18.4




More information about the DTrace-devel mailing list