From 6f5f1f33fd896a65ae27909eda3c87686569d739 Mon Sep 17 00:00:00 2001 From: Jordi Alcaraz Date: Tue, 22 Oct 2024 02:37:33 -0700 Subject: [PATCH] Fix for Dyninst with armlinux64. When using armlinux64, only one parameter is passed correctly with Dyninst, but when registering functions, two are used. Used a string with the id, a comma as a separator and the name of the function. Then the id and the name is extracted from the string. This should be a temporary fix until Dyninst solves the issue. Former-commit-id: 64cd81a24e9e75ba6b6b57110fe73b6c4cb99d69 --- configure | 4 +++- include/Makefile.skel | 2 ++ src/Profile/Makefile.skel | 2 +- src/Profile/TauDisable.cpp | 13 +++++++++++++ src/Profile/TauHooks.cpp | 19 ++++++++++++++++++- utils/FixMakefile | 4 ++++ utils/Makefile | 2 +- utils/include/Makefile.skel | 3 ++- utils/tau_run.cpp | 12 +++++++++--- 9 files changed, 53 insertions(+), 8 deletions(-) diff --git a/configure b/configure index 16a3ba196..a0b498429 100755 --- a/configure +++ b/configure @@ -10883,7 +10883,6 @@ if [ "x$download_dyninst" = xyes ] ; then cd $prebfddir fi #dyninst=download - ###################################################################### # Check that the Sampling allocator code is supported by compiler ###################################################################### @@ -12461,6 +12460,9 @@ if [ $dyninst = yes ] ; then if [ ! -f $dyninstdir/$PLATFORM/lib/libdynDwarf.so ] ; then fixmakeargs="$fixmakeargs DYNINST14" fi + if [ $machine = arm64_linux ]; then + fixmakeargs="$fixmakeargs DYN_ARMLINUX64" + fi fi diff --git a/include/Makefile.skel b/include/Makefile.skel index aa1d075c3..a6b6d0178 100644 --- a/include/Makefile.skel +++ b/include/Makefile.skel @@ -435,6 +435,8 @@ OPARI_O = TauKojakOpariDisable.o #ENDIF# # DYNINST DEFAULT ARCH ############################################# DYNINST_PLATFORM = $(PLATFORM) +#Dyninst 13 has issues with ARMLINUX64 when there are more than one function parameters, compile slightly modified tau_run.cpp and TauHooks.cpp +#DYN_ARMLINUX64#DYNINST_ARCH = -DDYNINSTARMLINUX64 ############# OpenMP Fortran Option ######## TAU_OPENMP_OPTION = diff --git a/src/Profile/Makefile.skel b/src/Profile/Makefile.skel index 1ecc63ffb..a73976b8b 100644 --- a/src/Profile/Makefile.skel +++ b/src/Profile/Makefile.skel @@ -847,7 +847,7 @@ TauMapping.o : TauMapping.cpp $(HDRS) $(CXX) $(CXXFLAGS) -c $(@:.o=.cpp) TauHooks.o : TauHooks.cpp $(HDRS) - $(CXX) $(CXXFLAGS) -c $(@:.o=.cpp) + $(CXX) $(CXXFLAGS) $(DYNINST_ARCH) -c $(@:.o=.cpp) TauJava.o : TauJava.cpp $(CXX) $(CXXFLAGS) -c TauJava.cpp diff --git a/src/Profile/TauDisable.cpp b/src/Profile/TauDisable.cpp index 54770bcfb..46a3d3259 100644 --- a/src/Profile/TauDisable.cpp +++ b/src/Profile/TauDisable.cpp @@ -20,6 +20,8 @@ * invoke the corresponding C routines. *****************************************************************************/ #include +#include +#include typedef unsigned int TauGroup_t; @@ -728,6 +730,17 @@ void tau_trace_lib_exit(const char * func_name) void trace_register_func(char *origname, int id) { printf("TAU: trace_register_func : name = %s, id = %d\n", origname, id); } +#ifdef DYNINSTARMLINUX64 +void trace_register_func_dyn(char *id_origname) { + int id = std::stoi(strtok(id_origname, ",")); + char *origname = strtok(NULL, ","); + printf("TAU: trace_register_func : name = %s, id = %d\n", origname, id); +} +#else +void trace_register_func_dyn(char *origname, int id) { + printf("TAU: trace_register_func : name = %s, id = %d\n", origname, id); +} +#endif void tau_dyninst_cleanup() { printf("TAU: Inside tau_dyninst_cleanup\n"); diff --git a/src/Profile/TauHooks.cpp b/src/Profile/TauHooks.cpp index 3a05ae8d7..5a17b0aac 100644 --- a/src/Profile/TauHooks.cpp +++ b/src/Profile/TauHooks.cpp @@ -315,6 +315,7 @@ static inline int getTauDyninstEnabled(int tid){ void trace_register_func(char *origname, int id) { + static int invocations = 0; int i; int tid = RtsLayer::myThread(); @@ -410,6 +411,21 @@ void trace_register_func(char *origname, int id) TAU_VERBOSE("Exiting trace_register_func\n"); } +#ifdef DYNINSTARMLINUX64 +void trace_register_func_dyn(char *id_origname) +{ + + int id = std::stoi(strtok(id_origname, ",")); + char *origname = strtok(NULL, ","); +#else +void trace_register_func_dyn(char *origname, int id) +{ +#endif + trace_register_func(origname, id); +} + + + void traceEntry(int id) { TAU_VERBOSE("Inside traceEntry: id = %d\n", id); @@ -552,11 +568,13 @@ void tau_dyninst_cleanup() TAU_VERBOSE("Inside tau_dyninst_cleanup\n"); } + void tau_register_func(char **func, char** file, int* lineno, int id) { char * tmpstr = Tau_demangle_name(*func); if (*file == NULL){ TAU_VERBOSE("TAU: tau_register_func: name = %s, id = %d\n", *func, id); + trace_register_func(tmpstr, id); } else { char funcname[2048]; @@ -633,7 +651,6 @@ void tau_trace_register_loop(int id, char *loopname) { void tau_register_loop(char **func, char** file, int* lineno, int id) { - char lname[2048]; char *loopname; if (((*file) != (char *)NULL) && (*lineno != 0)) { diff --git a/utils/FixMakefile b/utils/FixMakefile index 287baf00e..6ecaae371 100755 --- a/utils/FixMakefile +++ b/utils/FixMakefile @@ -1947,6 +1947,10 @@ case $1 in echo "NOTE: Using newer version DYNINST 5.2 " echo "s/#$1#\(.*\)/$bs\1#$1#/g" >> $sedout ;; + DYN_ARMLINUX64) + echo "NOTE: Using modified version for ARMLINUX64 Dyninst" + echo "s/#$1#\(.*\)/$bs\1#$1#/g" >> $sedout + ;; JAVA) echo "NOTE: Using Java Virtual Machine Instrumentation ***" echo "s/#$1#\(.*\)/$bs\1#$1#/g" >> $sedout diff --git a/utils/Makefile b/utils/Makefile index 6b570dd00..a17820c94 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -115,7 +115,7 @@ tau_run: tau_run.o tau_selective_dyn.o tau_instrument.dyn.o $(CXX) $(CFLAGS) tau_run.o tau_selective_dyn.o tau_instrument.dyn.o -o $@ $(DYNLIBS) $(LEXTRAUTIL) $(TAU_BOOSTLIB) $(BFDLINK) tau_run.o: tau_run.cpp - $(CXX) $(CFLAGS) $(DYNINC) -DTAU_DYNINST -DTAU_DYNINST41PLUS $(DYN_PKG_OPT) -c tau_run.cpp $(TAU_BOOSTINC) + $(CXX) $(CFLAGS) $(DYNINC) $(DYNINST_ARCH) -DTAU_DYNINST -DTAU_DYNINST41PLUS $(DYN_PKG_OPT) -c tau_run.cpp $(TAU_BOOSTINC) tau_trace2json: tau_trace2json.o $(CXX) $(CFLAGS) tau_trace2json.o -o $@ -lm $(TAU_TRACE_INPUT_LIB) diff --git a/utils/include/Makefile.skel b/utils/include/Makefile.skel index a51cdf012..a0bb203b8 100644 --- a/utils/include/Makefile.skel +++ b/utils/include/Makefile.skel @@ -185,7 +185,8 @@ PDT_CFLAGS = $(PDTCFLAGS) $(PDT_COMPILE_FLAGS) #DYNINST8#DYN_PKG_OPT = -DTAU_DYNINSTAPI_8_PLUS #ENDIF# #DYNINST12#DYN_PKG_OPT = -DTAU_DYNINSTAPI_12_PLUS #ENDIF# #DYNINST8#DYNINST_PLATFORM= #ENDIF# - +#Dyninst 13 has issues with ARMLINUX64 when there are more than one function parameters, compile slightly modified tau_run.cpp and TauHooks.cpp +#DYN_ARMLINUX64#DYNINST_ARCH = -DDYNINSTARMLINUX64 #DEBUGPROF#DEBUGOPT = -DDEBUG #ENDIF# #GNU#GNUOPT = -DTAU_GNU -DTAU_DOT_H_LESS_HEADERS -fPIC #ENDIF# diff --git a/utils/tau_run.cpp b/utils/tau_run.cpp index b7032e748..2b7391556 100644 --- a/utils/tau_run.cpp +++ b/utils/tau_run.cpp @@ -80,12 +80,18 @@ BPatch_Vector funcNames; int addName(char *name) { static int funcID = 0; + #ifdef DYNINSTARMLINUX64 + string id_name = std::to_string(funcID)+","+name; + BPatch_constExpr *id_name_param = new BPatch_constExpr(id_name.c_str()); + BPatch_Vector params; + params.push_back(id_name_param); + #else BPatch_constExpr *name_param = new BPatch_constExpr(name); BPatch_constExpr *id_param = new BPatch_constExpr(funcID); BPatch_Vector params; params.push_back(name_param); params.push_back(id_param); - + #endif BPatch_funcCallExpr *call = new BPatch_funcCallExpr(*name_reg, params); funcNames.push_back(call); return funcID++; @@ -857,7 +863,7 @@ int tauRewriteLibrary(BPatch *bpatch, const char *mutateeName, char *outfile, ch dprintf("Searching for TAU functions\n"); BPatch_function* entryLibTrace = tauFindFunction(mutateeImage, "tau_trace_lib_entry"); BPatch_function* exitLibTrace = tauFindFunction(mutateeImage, "tau_trace_lib_exit"); - name_reg = tauFindFunction(mutateeImage, "trace_register_func"); + name_reg = tauFindFunction(mutateeImage, "trace_register_func_dyn"); if(!entryLibTrace || !exitLibTrace ) @@ -1004,7 +1010,7 @@ int tauRewriteBinary(BPatch *bpatch, const char *mutateeName, char *outfile, cha BPatch_function* setupFunc = tauFindFunction(mutateeImage, "tau_dyninst_init"); BPatch_function* cleanupFunc = tauFindFunction(mutateeImage, "tau_dyninst_cleanup"); BPatch_function* mainFunc = tauFindFunction(mutateeImage, "main"); - name_reg = tauFindFunction(mutateeImage, "trace_register_func"); + name_reg = tauFindFunction(mutateeImage, "trace_register_func_dyn"); // This heuristic guesses that debugging info. is available if main // is not defined in the DEFAULT_MODULE