From 6fd6d5e29bc5bca65c3483fccbddf97809f903f0 Mon Sep 17 00:00:00 2001 From: Stan Cox Date: Wed, 13 Oct 2021 12:43:35 -0400 Subject: [PATCH] Support softfloat by dyninst backend. The softfloat library has conflicting types for some types defined in stdint.h, which -dyninst includes, so avoid by using cpp to redefine them. Add a float test to sdt_types.c. Only test dyninst with V3_uprobe. Add x8664 float registers to register definition used by dyninst. --- runtime/loc2c-runtime.h | 18 +++++++++++++++- runtime/softfloat.c | 11 ++++++++++ testsuite/systemtap.base/sdt_misc.exp | 29 ++++++++++++++++++++++---- testsuite/systemtap.base/sdt_types.c | 12 +++++++++++ testsuite/systemtap.base/sdt_types.stp | 24 +++++++++++++++++++++ 5 files changed, 89 insertions(+), 5 deletions(-) diff --git a/runtime/loc2c-runtime.h b/runtime/loc2c-runtime.h index e6c624d37..073ba04d2 100644 --- a/runtime/loc2c-runtime.h +++ b/runtime/loc2c-runtime.h @@ -164,7 +164,23 @@ #define pt_dwarf_register_13(regs) regs->r13 #define pt_dwarf_register_14(regs) regs->r14 #define pt_dwarf_register_15(regs) regs->r15 -#define pt_regs_maxno 15 +#define pt_dwarf_register_17(regs) ({uint64_t v; __asm__ __volatile__("movq %%xmm0, %0" : "=r"(v)); v;}) +#define pt_dwarf_register_18(regs) ({uint64_t v; __asm__ __volatile__("movq %%xmm1, %0" : "=r"(v)); v;}) +#define pt_dwarf_register_19(regs) ({uint64_t v; __asm__ __volatile__("movq %%xmm2, %0" : "=r"(v)); v;}) +#define pt_dwarf_register_20(regs) ({uint64_t v; __asm__ __volatile__("movq %%xmm3, %0" : "=r"(v)); v;}) +#define pt_dwarf_register_21(regs) ({uint64_t v; __asm__ __volatile__("movq %%xmm4, %0" : "=r"(v)); v;}) +#define pt_dwarf_register_22(regs) ({uint64_t v; __asm__ __volatile__("movq %%xmm5, %0" : "=r"(v)); v;}) +#define pt_dwarf_register_23(regs) ({uint64_t v; __asm__ __volatile__("movq %%xmm6, %0" : "=r"(v)); v;}) +#define pt_dwarf_register_24(regs) ({uint64_t v; __asm__ __volatile__("movq %%xmm7, %0" : "=r"(v)); v;}) +#define pt_dwarf_register_25(regs) ({uint64_t v; __asm__ __volatile__("movq %%xmm8, %0" : "=r"(v)); v;}) +#define pt_dwarf_register_26(regs) ({uint64_t v; __asm__ __volatile__("movq %%xmm9, %0" : "=r"(v)); v;}) +#define pt_dwarf_register_27(regs) ({uint64_t v; __asm__ __volatile__("movq %%xmm10, %0" : "=r"(v)); v;}) +#define pt_dwarf_register_28(regs) ({uint64_t v; __asm__ __volatile__("movq %%xmm11, %0" : "=r"(v)); v;}) +#define pt_dwarf_register_29(regs) ({uint64_t v; __asm__ __volatile__("movq %%xmm12, %0" : "=r"(v)); v;}) +#define pt_dwarf_register_30(regs) ({uint64_t v; __asm__ __volatile__("movq %%xmm13, %0" : "=r"(v)); v;}) +#define pt_dwarf_register_31(regs) ({uint64_t v; __asm__ __volatile__("movq %%xmm14, %0" : "=r"(v)); v;}) +#define pt_dwarf_register_32(regs) ({uint64_t v; __asm__ __volatile__("movq %%xmm15, %0" : "=r"(v)); v;}) +#define pt_regs_maxno 32 #elif defined __powerpc__ diff --git a/runtime/softfloat.c b/runtime/softfloat.c index 695193370..709e45d2f 100644 --- a/runtime/softfloat.c +++ b/runtime/softfloat.c @@ -35,6 +35,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. //#include //#include +/* --dyninst includes stdint.h so avoid stdint.h conflicts + * INT64_C and UINT64_C are macros so undef them + * *fast* are typedefs so define them + * TODO: Consider changing softfloat to use stdint defs + */ +#undef INT64_C +#undef UINT64_C +#define int_fast16_t sf_int_fast16_t +#define uint_fast16_t sf_uint_fast16_t +#define int_fast32_t sf_int_fast32_t +#define uint_fast32_t sf_uint_fast32_t #include "softfloat/platform.h" #include "softfloat/internals.h" #include "softfloat.h" diff --git a/testsuite/systemtap.base/sdt_misc.exp b/testsuite/systemtap.base/sdt_misc.exp index 3d7b40040..f90daa9c5 100644 --- a/testsuite/systemtap.base/sdt_misc.exp +++ b/testsuite/systemtap.base/sdt_misc.exp @@ -101,6 +101,8 @@ for {set i 0} {$i < [llength $pbtype_flags]} {incr i} { # 1. Test executable built with dtrace generated header file foreach runtime [get_runtime_list] { + if {$runtime == "dyninst" && $pbtype_mssg != "V3_uprobe"} { + continue } set test_xtra "" if {$runtime != ""} { set test_xtra " ($runtime)" @@ -158,6 +160,8 @@ for {set i 0} {$i < [llength $pbtype_flags]} {incr i} { } foreach runtime [get_runtime_list] { + if {$runtime == "dyninst" && $pbtype_mssg != "V3_uprobe"} { + continue } set test_xtra "" if {$runtime != ""} { set test_xtra " ($runtime)" @@ -280,9 +284,7 @@ for {set i 0} {$i < [llength $pbtype_flags]} {incr i} { # On ARM these tests are known to fail with timeout for V1 # and V2 probes. Skip them altogether to speed execution. if {[istarget "arm*-*-*"] \ - && ($pbtype_mssg == "V1_uprobe" \ - || $pbtype_mssg == "V2_kprobe" \ - || $pbtype_mssg == "V2_uprobe")} { + && ($pbtype_mssg == "V1_uprobe" || $pbtype_mssg == "V2_uprobe")} { xfail "$test types $test_suffix" continue } @@ -306,6 +308,8 @@ for {set i 0} {$i < [llength $pbtype_flags]} {incr i} { } foreach runtime [get_runtime_list] { + if {$runtime == "dyninst" && $pbtype_mssg != "V3_uprobe"} { + continue } set test_xtra "" if {$runtime != ""} { set test_xtra " ($runtime)" @@ -324,6 +328,7 @@ for {set i 0} {$i < [llength $pbtype_flags]} {incr i} { set notok 0 set fail "" set uns_notok 0 + set float_notok 0 expect { -timeout 180 # i386 unsigned may xfail because of sign extension @@ -333,6 +338,8 @@ for {set i 0} {$i < [llength $pbtype_flags]} {incr i} { set s $expect_out(1,string); if {[regexp "unsigned" $s] && [istarget "i*86-*-*"]} { incr uns_notok } + if {[regexp "float" $s] || [regexp "double" $s]} { + incr float_notok } incr notok; set fail "$fail $s"; exp_continue } -re {^[^\r]*\r\n} { incr notok; exp_continue } timeout { fail "$test types (timeout) $test_suffix" } @@ -341,7 +348,15 @@ for {set i 0} {$i < [llength $pbtype_flags]} {incr i} { catch {close}; catch {wait} if { $notok != 0 || $ok == 0} { - if { [lindex $type_xfail $j] || $notok == $uns_notok} { + if { $notok == $float_notok } { + # Ignore float failures for V1, V2, and dyninst + if { $pbtype_mssg != "V3_uprobe" || $runtime == "dyninst" } { + pass "$test types $test_suffix" + } else { + incr fail_count + fail "$test types $fail $test_suffix" + } + } elseif { [lindex $type_xfail $j] || $notok == $uns_notok } { xfail "$test types $fail $test_suffix" } else { incr fail_count @@ -379,6 +394,8 @@ for {set i 0} {$i < [llength $pbtype_flags]} {incr i} { } foreach runtime [get_runtime_list] { + if {$runtime == "dyninst" && $pbtype_mssg != "V3_uprobe"} { + continue } set test_xtra "" if {$runtime != ""} { set test_xtra " ($runtime)" @@ -444,6 +461,8 @@ for {set i 0} {$i < [llength $pbtype_flags]} {incr i} { } foreach runtime [get_runtime_list] { + if {$runtime == "dyninst" && $pbtype_mssg != "V3_uprobe"} { + continue } set test_xtra "" if {$runtime != ""} { set test_xtra " ($runtime)" @@ -568,6 +587,8 @@ for {set i 0} {$i < [llength $pbtype_flags]} {incr i} { # 7. Test V3 $$parms support foreach runtime [get_runtime_list] { + if {$runtime == "dyninst" && $pbtype_mssg != "V3_uprobe"} { + continue } set test_xtra "" if {$runtime != ""} { set test_xtra " ($runtime)" diff --git a/testsuite/systemtap.base/sdt_types.c b/testsuite/systemtap.base/sdt_types.c index 6d99ccdcb..060bc0235 100644 --- a/testsuite/systemtap.base/sdt_types.c +++ b/testsuite/systemtap.base/sdt_types.c @@ -1,6 +1,7 @@ #include "sys/sdt.h" #include #include +#include struct opaque; @@ -48,6 +49,7 @@ main (int argc, char **argv) long int * volatile long_int_ptr_volatile_var = &long_int_var; /* c89 doesn't define __STDC_VERSION. With -pedantic warns about long long. */ + #if ! defined NO_LONG_LONG && __SIZEOF_SIZE_T__ == 8 long long int long_long_int_var = 0x7fffffffffffffffLL; const long long int const_long_long_int_var = -0x7fffffffffffffffLL; @@ -106,6 +108,12 @@ main (int argc, char **argv) struct opaque_struct *incomplete_struct_type = 0; # endif + float float_var; + double double_var; + /* Avoid float_var being treated as .Label(Reg) which is not supported by stap */ + sscanf("3.14159", "%f", &float_var); + double_var = (double)float_var; + /* gnu90 and gnu99 don't support this so for now don't test it enum opaque_enum *incomplete_enum_type = 0; */ @@ -152,6 +160,10 @@ main (int argc, char **argv) STAP_PROBE2(provider,ptr_volatile_long_int_var,ptr_volatile_long_int_var,&long_int_var); STAP_PROBE2(provider,long_int_ptr_volatile_var,long_int_ptr_volatile_var,&long_int_var); + /* float / double */ + STAP_PROBE1(provider,float_var,float_var); + STAP_PROBE1(provider,double_var,double_var); + /* long long */ #if ! defined NO_LONG_LONG && __SIZEOF_SIZE_T__ == 8 STAP_PROBE1(provider,long_long_int_var,long_long_int_var); diff --git a/testsuite/systemtap.base/sdt_types.stp b/testsuite/systemtap.base/sdt_types.stp index 6bb2ecc8e..4e2230114 100644 --- a/testsuite/systemtap.base/sdt_types.stp +++ b/testsuite/systemtap.base/sdt_types.stp @@ -6,6 +6,18 @@ function check(name, value, expected) printf ("sdt_types FAIL: %s (%#x != %#x)\n", name, value, expected) } +function check_float(name, value, expected, need_double) +{ + if (need_double) + value = fp32_to_fp64(value) + range = string_to_fp("0.00001") + /* Check that value is in the interval [expected - range < x < expected + range] */ + if (fp_le(fp_sub(expected,range),value) && fp_le(value,fp_add(expected,range))) + printf ("sdt_types PASS: %s\n", name) + else + printf ("sdt_types FAIL: %s (%s != %s)\n", name, fp_to_string(value,8), fp_to_string(expected,8)) +} + function check_string(name, value, expected) { if (value == expected) @@ -232,6 +244,18 @@ probe process(@1).mark("long_int_ptr_volatile_var") } +/********** float / double **********/ + +probe process(@1).mark("float_var") +{ + check_float($$name, $arg1, string_to_fp("3.14159"),1) +} + +probe process(@1).mark("double_var") +{ + check_float($$name, $arg1, string_to_fp("3.14159"),0) +} + /********** long long **********/ probe process(@1).mark("long_long_int_var") ? -- 2.43.5