From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2041) id 4B83C3857346; Thu, 15 Sep 2022 01:44:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4B83C3857346 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1663206245; bh=8RZDJxbqz60o85s2rHs6pHKEIdvEWomNystFYKV7/ws=; h=From:To:Subject:Date:From; b=kRfKJSgd5uvpuk7V8lA1kXpShHyeUxFyDkPaGRaaYNdnFkLy4p1hPXuS8s1kkhOGK PojmGZKK1UVTkCRjtIubva7ue3UiHs8ROcDgpq6GKXSNnvDn5qtn0IeUr0/9q3kO4a 1lKgoVU87ujPRBCndT1cO2Rg9kiRlkEhTWhPLqtY= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Vladimir Mezentsev To: bfd-cvs@sourceware.org, gdb-cvs@sourceware.org Subject: [binutils-gdb] gprofng: fix build issues on musl X-Act-Checkin: binutils-gdb X-Git-Author: Vladimir Mezentsev X-Git-Refname: refs/heads/master X-Git-Oldrev: 8422cbe455d762f068ed1edefc717f36a105da42 X-Git-Newrev: fe39ffdc202f04397f31557f17170b40bc42b77a Message-Id: <20220915014405.4B83C3857346@sourceware.org> Date: Thu, 15 Sep 2022 01:44:05 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dfe39ffdc202f= 04397f31557f17170b40bc42b77a commit fe39ffdc202f04397f31557f17170b40bc42b77a Author: Vladimir Mezentsev Date: Wed Sep 14 01:11:45 2022 -0700 gprofng: fix build issues on musl =20 gprofng/ChangeLog 2022-09-14 Vladimir Mezentsev =20 PR gprofng/29477 * configure.ac: Set __MUSL_LIBC. * configure: Rebuild. * common/config.h.in: Rebuild. * src/collector_module.h: Fix compiler errors because mmap64, o= pen64, pwrite64 are macros and getcontext() is absent on musl. * libcollector/collector.c: Likewise. * libcollector/hwprofile.c: Likewise. * libcollector/iolib.c: Likewise. * libcollector/libcol_util.c: Likewise. * libcollector/linetrace.c: Likewise. * libcollector/memmgr.c: Likewise. * libcollector/profile.c: Likewise. * libcollector/unwind.c: Likewise. * libcollector/dispatcher.c: Likewise. * src/Experiment.cc: Likewise. * libcollector/collector.h: Use dlsym() because dlvsym() is not= defined on musl. * libcollector/iotrace.c: Remove interposition of versioned fun= ctions. * libcollector/mmaptrace.c: Likewise. * libcollector/libcol_util.h: Fix -Wint-to-pointer-cast warning= s. * libcollector/jprofile.c: Likewise. * libcollector/synctrace.c: Include "collector.h". * src/Print.cc: Use get_basename() because basename() is not de= fined on musl. * common/hwcdrv.c: Fix -Wformat=3D warnings. Diff: --- gprofng/common/config.h.in | 3 + gprofng/common/hwcdrv.c | 6 +- gprofng/configure | 30 ++++++- gprofng/configure.ac | 27 +++++- gprofng/libcollector/collector.c | 9 +- gprofng/libcollector/collector.h | 6 +- gprofng/libcollector/dispatcher.c | 4 +- gprofng/libcollector/hwprofile.c | 11 ++- gprofng/libcollector/iolib.c | 52 +++++------ gprofng/libcollector/iotrace.c | 179 +++++++++++++++++++--------------= ---- gprofng/libcollector/jprofile.c | 6 -- gprofng/libcollector/libcol_util.c | 19 ++-- gprofng/libcollector/libcol_util.h | 9 +- gprofng/libcollector/linetrace.c | 4 +- gprofng/libcollector/memmgr.c | 2 +- gprofng/libcollector/mmaptrace.c | 132 +++++++++++---------------- gprofng/libcollector/profile.c | 2 +- gprofng/libcollector/synctrace.c | 3 +- gprofng/libcollector/unwind.c | 2 +- gprofng/src/Experiment.cc | 4 +- gprofng/src/Print.cc | 6 +- gprofng/src/collector_module.h | 6 +- 22 files changed, 277 insertions(+), 245 deletions(-) diff --git a/gprofng/common/config.h.in b/gprofng/common/config.h.in index 8409ce74a57..f8484f238fd 100644 --- a/gprofng/common/config.h.in +++ b/gprofng/common/config.h.in @@ -118,3 +118,6 @@ =20 /* Define to 1 if you need to in order for `stat' and other things to work= . */ #undef _POSIX_SOURCE + +/* Build with musl-libc. */ +#undef __MUSL_LIBC diff --git a/gprofng/common/hwcdrv.c b/gprofng/common/hwcdrv.c index caab9839b49..05390e239df 100644 --- a/gprofng/common/hwcdrv.c +++ b/gprofng/common/hwcdrv.c @@ -440,7 +440,7 @@ typedef struct { // per-thread context counter_state_t *ctr_list; int signal_fd; // fd that caused the most recent signal - pthread_t tid; // for debugging signal delivery problems + pid_t tid; // for debugging signal delivery problems } hdrv_pcl_ctx_t; =20 /*------------------------------------------------------------------------= ---*/ @@ -1321,7 +1321,7 @@ hwcdrv_free_counters () // note: only performs shutdo= wn for this thread for (int ii =3D 0; ii < hdrv_pcl_state.hwcdef_cnt; ii++) if (stop_one_ctr (ii, ctr_list)) hwc_rc =3D HWCFUNCS_ERROR_GENERIC; - TprintfT (DBG_LT1, "hwcdrv: hwcdrv_free_counters(tid=3D0x%lx).\n", pctx-= >tid); + TprintfT (DBG_LT1, "hwcdrv: hwcdrv_free_counters(tid=3D0x%lx).\n", (long= ) pctx->tid); pctx->ctr_list =3D NULL; return hwc_rc; } @@ -1351,7 +1351,7 @@ hwcdrv_start (void) /* must be called from each threa= d ? */ return HWCFUNCS_ERROR_UNEXPECTED; } pctx->tid =3D hwcdrv_gettid (); - TprintfT (DBG_LT1, "hwcdrv: hwcdrv_start(tid=3D0x%lx)\n", pctx->tid); + TprintfT (DBG_LT1, "hwcdrv: hwcdrv_start(tid=3D0x%lx)\n", (long) pctx->t= id); =20 /* * create per-thread counter list diff --git a/gprofng/configure b/gprofng/configure index fad5b030072..301ac10050b 100755 --- a/gprofng/configure +++ b/gprofng/configure @@ -16572,7 +16572,7 @@ class Simple{ } } EOF - if { ac_try=3D'$JAVAC conftest.java &5 2>&1' + if { ac_try=3D'$JAVAC configtest.java &5 2>&1' { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5 (eval $ac_try) 2>&5 ac_status=3D$? @@ -16608,6 +16608,34 @@ $as_echo "#define DEBUG 1" >>confdefs.h =20 fi =20 +cat > "dummy.c" << EOF +#include +#if defined(__UCLIBC__) +LIBC=3Duclibc +#elif defined(__dietlibc__) +LIBC=3Ddietlibc +#elif defined(__GLIBC__) +LIBC=3Dgnu +#else +#include +/* First heuristic to detect musl libc. */ +#ifdef __DEFINED_va_list +LIBC=3Dmusl +#else +LIBC=3Dgnu +#endif +#endif +EOF +cc_set_libc=3D`$CC -E "dummy.c" 2>/dev/null | grep '^LIBC=3D' | sed 's, ,,= g'` +eval "$cc_set_libc" +echo "cc_set_libc=3D$cc_set_libc;" +if test "$LIBC" =3D musl; then + +$as_echo "#define __MUSL_LIBC 1" >>confdefs.h + +fi + + # Check if linker supports --as-needed and --no-as-needed options. { $as_echo "$as_me:${as_lineno-$LINENO}: checking linker --as-needed suppo= rt" >&5 $as_echo_n "checking linker --as-needed support... " >&6; } diff --git a/gprofng/configure.ac b/gprofng/configure.ac index e9453109602..2d7640dfdc8 100644 --- a/gprofng/configure.ac +++ b/gprofng/configure.ac @@ -142,7 +142,7 @@ class Simple{ } } EOF - if AC_TRY_COMMAND($JAVAC conftest.java &AS_MESSAGE_LOG_FD 2>&1); then + if AC_TRY_COMMAND($JAVAC configtest.java &AS_MESSAGE_LOG_FD 2>&1); t= hen GPROFNG_BROKEN_JAVAC=3Dno else GPROFNG_BROKEN_JAVAC=3Dyes @@ -159,6 +159,31 @@ if test "${enable_gprofng_debug}" =3D yes; then AC_DEFINE(DEBUG, 1, [Enable debugging output.]) fi =20 +cat > "dummy.c" << EOF +#include +#if defined(__UCLIBC__) +LIBC=3Duclibc +#elif defined(__dietlibc__) +LIBC=3Ddietlibc +#elif defined(__GLIBC__) +LIBC=3Dgnu +#else +#include +/* First heuristic to detect musl libc. */ +#ifdef __DEFINED_va_list +LIBC=3Dmusl +#else +LIBC=3Dgnu +#endif +#endif +EOF +cc_set_libc=3D`$CC -E "dummy.c" 2>/dev/null | grep '^LIBC=3D' | sed 's, ,,= g'` +eval "$cc_set_libc" +if test "$LIBC" =3D musl; then + AC_DEFINE(__MUSL_LIBC, 1, [Build with musl-libc.]) +fi + + # Check if linker supports --as-needed and --no-as-needed options. AC_CACHE_CHECK(linker --as-needed support, bfd_cv_ld_as_needed, [bfd_cv_ld_as_needed=3Dno diff --git a/gprofng/libcollector/collector.c b/gprofng/libcollector/collec= tor.c index ceff2c1cacc..93015305587 100644 --- a/gprofng/libcollector/collector.c +++ b/gprofng/libcollector/collector.c @@ -2155,7 +2155,7 @@ log_header_write (sp_origin_t origin) ucontext_t ucp; ucp.uc_stack.ss_sp =3D NULL; ucp.uc_stack.ss_size =3D 0; - if (getcontext (&ucp) =3D=3D 0) + if (CALL_UTIL (getcontext) (&ucp) =3D=3D 0) { (void) __collector_log_write ("\n", (unsigned long) ucp.uc_stack.ss_sp + ucp.uc_stack.ss_size); @@ -2413,10 +2413,9 @@ __collector_dlog (int tflag, int level, char *format= , ...) int left =3D bufsz; if ((tflag & SP_DUMP_NOHEADER) =3D=3D 0) { - p +=3D CALL_UTIL (snprintf)(p, left, "P%d,L%02u,t%02lu", - (int) getpid (), - (unsigned int) __collector_lwp_self (), - __collector_no_threads ? 0 : __collector_thr_self ()); + p +=3D CALL_UTIL (snprintf) (p, left, "P%ld,L%02lu,t%02lu", + (long) getpid (), (unsigned long) __collector_lwp_self (), + (unsigned long) (__collector_no_threads ? 0 : __collector_thr_self ())); left =3D bufsz - (p - buf); if (tflag) { diff --git a/gprofng/libcollector/collector.h b/gprofng/libcollector/collec= tor.h index c54568d891c..b589d3f3d18 100644 --- a/gprofng/libcollector/collector.h +++ b/gprofng/libcollector/collector.h @@ -21,7 +21,6 @@ #ifndef _COLLECTOR_H #define _COLLECTOR_H =20 -#include #include =20 #include "gp-defs.h" @@ -31,6 +30,11 @@ =20 #define GETRELTIME() (__collector_gethrtime() - __collector_start_time) =20 +#if defined(__MUSL_LIBC) +#define dlvsym(f, nm, v) dlsym (f, nm) +#define SIGEV_THREAD_ID 4 +#endif + extern hrtime_t __collector_start_time; =20 /* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */ diff --git a/gprofng/libcollector/dispatcher.c b/gprofng/libcollector/dispa= tcher.c index f0308605d76..d3e4c52d667 100644 --- a/gprofng/libcollector/dispatcher.c +++ b/gprofng/libcollector/dispatcher.c @@ -30,9 +30,7 @@ #include #include #include -#include #include -#include #include #include #include @@ -575,7 +573,9 @@ collector_timer_create (timer_t * ptimerid) sigev.sigev_notify =3D SIGEV_THREAD_ID | SIGEV_SIGNAL; sigev.sigev_signo =3D SIGPROF; sigev.sigev_value.sival_ptr =3D ptimerid; +#if !defined(__MUSL_LIBC) sigev._sigev_un._tid =3D __collector_gettid (); +#endif if (CALL_REAL (timer_create)(CLOCK_THREAD_CPUTIME_ID, &sigev, ptimerid) = =3D=3D -1) { TprintfT (DBG_LT2, "collector_timer_settime() failed! errno=3D%d\n",= errno); diff --git a/gprofng/libcollector/hwprofile.c b/gprofng/libcollector/hwprof= ile.c index 6fdaf1bd8ff..e360068ea30 100644 --- a/gprofng/libcollector/hwprofile.c +++ b/gprofng/libcollector/hwprofile.c @@ -29,7 +29,6 @@ #include #include #include -#include =20 #include "gp-defs.h" #define _STRING_H 1 /* XXX MEZ: temporary workaround */ @@ -378,23 +377,23 @@ static void init_ucontexts (void) { /* initialize dummy context for "collector" frames */ - getcontext (&expr_dummy_uc); + CALL_UTIL (getcontext) (&expr_dummy_uc); SETFUNCTIONCONTEXT (&expr_dummy_uc, NULL); =20 /* initialize dummy context for "out-of-range" frames */ - getcontext (&expr_out_of_range_uc); + CALL_UTIL (getcontext) (&expr_out_of_range_uc); SETFUNCTIONCONTEXT (&expr_out_of_range_uc, &__collector_hwcs_out_of_rang= e); =20 /* initialize dummy context for "frozen" frames */ - getcontext (&expr_frozen_uc); + CALL_UTIL (getcontext) (&expr_frozen_uc); SETFUNCTIONCONTEXT (&expr_frozen_uc, &__collector_hwcs_frozen); =20 /* initialize dummy context for non-program-related frames */ - getcontext (&expr_nopc_uc); + CALL_UTIL (getcontext) (&expr_nopc_uc); SETFUNCTIONCONTEXT (&expr_nopc_uc, &__collector_not_program_related); =20 /* initialize dummy context for lost-counts-related frames */ - getcontext (&expr_lostcounts_uc); + CALL_UTIL (getcontext) (&expr_lostcounts_uc); SETFUNCTIONCONTEXT (&expr_lostcounts_uc, &__collector_hwc_samples_lost); } /* initialize the signal handler */ diff --git a/gprofng/libcollector/iolib.c b/gprofng/libcollector/iolib.c index 6881f02fd30..861843c183d 100644 --- a/gprofng/libcollector/iolib.c +++ b/gprofng/libcollector/iolib.c @@ -243,16 +243,14 @@ __collector_create_handle (char *descp) { /* allocate our buffers in virtual memory */ /* later, we will remap buffers individually to the file */ - uint8_t *memory =3D (uint8_t*) CALL_UTIL (mmap64)(0, - (size_t) (NBUFS * blksz), - PROT_READ | PROT_WRITE, + uint8_t *memory =3D (uint8_t*) CALL_UTIL (mmap64_) (0, + (size_t) (NBUFS * blksz), PROT_READ | PROT_WRITE, #if ARCH(SPARC) MAP_SHARED | MAP_ANON, #else MAP_PRIVATE | MAP_ANON, #endif - -1, - (off64_t) 0); + -1, (off64_t) 0); if (memory =3D=3D MAP_FAILED) { TprintfT (0, "create_handle: can't mmap MAP_ANON (for %s): %s\n", hndl-= >fname, CALL_UTIL (strerror)(errno)); @@ -516,9 +514,8 @@ allocateChunk (DataHandle *hndl, unsigned ichunk) if (__collector_cas_ptr (&hndl->chunks[ichunk], NULL, CHUNK_BUSY) = =3D=3D NULL) { /* allocate virtual memory */ - uint8_t *newchunk =3D (uint8_t*) CALL_UTIL (mmap64)(0, - (size_t) (blksz * hndl->nflow), - PROT_READ | PROT_WRITE, + uint8_t *newchunk =3D (uint8_t*) CALL_UTIL (mmap64_) (0, + (size_t) (blksz * hndl->nflow), PROT_READ | PROT_WRITE, #if ARCH(SPARC) MAP_SHARED | MAP_ANON, #else @@ -611,8 +608,10 @@ remapBlock (DataHandle *hndl, unsigned iflow, unsigned= ichunk) char errmsg[MAXPATHLEN + 50]; hrtime_t teo =3D __collector_gethrtime (); double deltato =3D (double) (teo - tso) / 1000000.; - (void) CALL_UTIL (snprintf) (errmsg, sizeof (errmsg), " t=3D%d, %s: op= en-retries-failed =3D %d, %3.6f ms.; remap", - __collector_thr_self (), hndl->fname, iter, deltato); + (void) CALL_UTIL (snprintf) (errmsg, sizeof (errmsg), + " t=3D%lu, %s: open-retries-failed=3D%d, %3.6f ms.; remap\n", + (unsigned long) __collector_thr_self (), hndl->fname, + iter, deltato); __collector_log_write ("%s\n", SP_JCMD_COMMENT, COL_COMMENT_NONE, errmsg); rc =3D 1; @@ -623,9 +622,9 @@ remapBlock (DataHandle *hndl, unsigned iflow, unsigned = ichunk) } deleteHandle (hndl); TprintfT (0, "remapBlock: can't open file: %s: %s\n", hndl->fname, STR = (CALL_UTIL (strerror)(errno))); - __collector_log_write ("t= =3D%llu, %s: remap \n", + __collector_log_write ("t= =3D%lu, %s: remap \n", SP_JCMD_CERROR, COL_ERROR_FILEOPN, errno, - (unsigned long long) __collector_thr_self (), + (unsigned long) __collector_thr_self (), hndl->fname); rc =3D 1; goto exit; @@ -640,15 +639,18 @@ remapBlock (DataHandle *hndl, unsigned iflow, unsigne= d ichunk) char errmsg[MAXPATHLEN + 50]; hrtime_t teo =3D __collector_gethrtime (); double deltato =3D (double) (teo - tso) / 1000000.; - (void) CALL_UTIL (snprintf) (errmsg, sizeof (errmsg), " t=3D%d, %s: = open-retries =3D %d, %3.6f ms.; remap", - __collector_thr_self (), hndl->fname, iter, deltato); + (void) CALL_UTIL (snprintf) (errmsg, sizeof (errmsg), + " t=3D%d, %s: open-retries=3D%lu, %3.6f ms.; remap\n", + (unsigned long) __collector_thr_self (), hndl->fname, + iter, deltato); __collector_log_write ("%s\= n", SP_JCMD_COMMENT, COL_COMMENT_NONE, errmsg); } =20 /* Ensure disk space is allocated and the block offset is 0 */ uint32_t zero =3D 0; - int n =3D CALL_UTIL (pwrite64)(fd, &zero, sizeof (zero), (off64_t) (offs= et + blksz - sizeof (zero))); + int n =3D CALL_UTIL (pwrite64_) (fd, &zero, sizeof (zero), + (off64_t) (offset + blksz - sizeof (zero))); if (n <=3D 0) { deleteHandle (hndl); @@ -663,13 +665,9 @@ remapBlock (DataHandle *hndl, unsigned iflow, unsigned= ichunk) =20 /* Map block to file */ uint8_t *bptr =3D getBlock (hndl, iflow, ichunk); - uint8_t *vaddr =3D (uint8_t *) CALL_UTIL (mmap64)( - (void*) bptr, - (size_t) blksz, - PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_FIXED, - fd, - offset); + uint8_t *vaddr =3D (uint8_t *) CALL_UTIL (mmap64_) ((void*) bptr, + (size_t) blksz, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, + fd, offset); =20 if (vaddr !=3D bptr) { @@ -784,8 +782,9 @@ __collector_write_packet (DataHandle *hndl, CM_Packet *= pckt) TprintfT (0, "collector_write_packet: packet too long: %d (max %ld)\= n", recsz, blksz); return 1; } - unsigned tid =3D (__collector_no_threads ? __collector_lwp_self () : __c= ollector_thr_self ()); - unsigned iflow =3D tid % hndl->nflow; + collector_thread_t tid =3D __collector_no_threads ? __collector_lwp_self= () + : __collector_thr_self (); + unsigned iflow =3D (unsigned) (((unsigned long) tid) % hndl->nflow); =20 /* Acquire block */ uint32_t *sptr =3D &hndl->blkstate[iflow * NCHUNKS]; @@ -925,7 +924,8 @@ mapBuffer (char *fname, Buffer *buf, off64_t foff) =20 /* ensure disk space is allocated */ char nl =3D '\n'; - int n =3D CALL_UTIL (pwrite64)(fd, &nl, sizeof (nl), (off64_t) (foff + b= lksz - sizeof (nl))); + int n =3D CALL_UTIL (pwrite64_) (fd, &nl, sizeof (nl), + (off64_t) (foff + blksz - sizeof (nl))); if (n <=3D 0) { TprintfT (0, "mapBuffer ERROR: can't pwrite file %s at 0x%llx\n", fn= ame, @@ -937,7 +937,7 @@ mapBuffer (char *fname, Buffer *buf, off64_t foff) goto exit; } /* mmap buf->vaddr to fname at foff */ - uint8_t *vaddr =3D CALL_UTIL (mmap64)(buf->vaddr, (size_t) blksz, + uint8_t *vaddr =3D CALL_UTIL (mmap64_) (buf->vaddr, (size_t) blksz, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, fd, foff); if (vaddr !=3D buf->vaddr) { diff --git a/gprofng/libcollector/iotrace.c b/gprofng/libcollector/iotrace.c index 9b47724bab9..d94daefa89b 100644 --- a/gprofng/libcollector/iotrace.c +++ b/gprofng/libcollector/iotrace.c @@ -34,7 +34,7 @@ #include =20 #include "gp-defs.h" -#include "collector_module.h" +#include "collector.h" #include "gp-experiment.h" #include "data_pckts.h" #include "tsd.h" @@ -999,6 +999,22 @@ init_io_intf () return rc; } =20 +static void +write_io_packet (int fd, ssize_t ret, hrtime_t reqt, int iotype) +{ + IOTrace_packet iopkt; + collector_memset (&iopkt, 0, sizeof ( IOTrace_packet)); + iopkt.comm.tsize =3D sizeof (IOTrace_packet); + iopkt.comm.tstamp =3D gethrtime (); + iopkt.requested =3D reqt; + iopkt.iotype =3D iotype; + iopkt.fd =3D fd; + iopkt.nbyte =3D ret; + iopkt.comm.frinfo =3D collector_interface->getFrameInfo (io_hndl, + iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt); + collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt); +} + /*------------------------------------------------------------- open */ int open (const char *path, int oflag, ...) @@ -2412,162 +2428,147 @@ pread (int fildes, void *buf, size_t nbyte, off_t= offset) } =20 /*------------------------------------------------------------- pwrite */ -#if ARCH(Intel) && WSIZE(32) + +#if !defined(__MUSL_LIBC) && ARCH(Intel) && WSIZE(32) // map interposed symbol versions -static int -__collector_pwrite_symver (int(real_pwrite) (), int fildes, const void *bu= f, size_t nbyte, off_t offset); =20 SYMVER_ATTRIBUTE (__collector_pwrite_2_2, pwrite@@GLIBC_2.2) int __collector_pwrite_2_2 (int fildes, const void *buf, size_t nbyte, off_t o= ffset) { - TprintfT (DBG_LTT, "iotrace: __collector_pwrite_2_2@%p(fildes=3D%d, buf= =3D%p, nbyte=3D%lld, offset=3D%lld)\n", - CALL_REAL (pwrite_2_2), fildes, buf, (long long) nbyte, (long long) o= ffset); - if (NULL_PTR (pwrite)) + int *guard; + if (NULL_PTR (pwrite_2_2)) init_io_intf (); - return __collector_pwrite_symver (CALL_REAL (pwrite_2_2), fildes, buf, n= byte, offset); + if (CHCK_REENTRANCE (guard)) + return CALL_REAL (pwrite_2_2)(fildes, buf, nbyte, offset); + PUSH_REENTRANCE (guard); + hrtime_t reqt =3D gethrtime (); + ssize_t ret =3D CALL_REAL (pwrite_2_2)(fildes, buf, nbyte, offset); + if (RECHCK_REENTRANCE (guard)) + { + POP_REENTRANCE (guard); + return ret; + } + write_io_packet (fildes, ret, reqt, ret >=3D 0 ? WRITE_TRACE : WRITE_TRA= CE_ERROR); + POP_REENTRANCE (guard); + return ret; } =20 SYMVER_ATTRIBUTE (__collector_pwrite_2_1, pwrite@GLIBC_2.1) int __collector_pwrite_2_1 (int fildes, const void *buf, size_t nbyte, off_t o= ffset) { - TprintfT (DBG_LTT, "iotrace: __collector_pwrite_2_1@%p(fildes=3D%d, buf= =3D%p, nbyte=3D%lld, offset=3D%lld)\n", - CALL_REAL (pwrite_2_1), fildes, buf, (long long) nbyte, (long long) o= ffset); - if (NULL_PTR (pwrite)) + int *guard; + if (NULL_PTR (pwrite_2_1)) init_io_intf (); - return __collector_pwrite_symver (CALL_REAL (pwrite_2_1), fildes, buf, n= byte, offset); + if (CHCK_REENTRANCE (guard)) + return CALL_REAL (pwrite_2_1)(fildes, buf, nbyte, offset); + PUSH_REENTRANCE (guard); + hrtime_t reqt =3D gethrtime (); + ssize_t ret =3D CALL_REAL (pwrite_2_1)(fildes, buf, nbyte, offset); + if (RECHCK_REENTRANCE (guard)) + { + POP_REENTRANCE (guard); + return ret; + } + write_io_packet (fildes, ret, reqt, ret >=3D 0 ? WRITE_TRACE : WRITE_TRA= CE_ERROR); + POP_REENTRANCE (guard); + return ret; } - -static int -__collector_pwrite_symver (int(real_pwrite) (), int fildes, const void *bu= f, size_t nbyte, off_t offset) -{ -#else /* ^ARCH(Intel) && WSIZE(32) */ +#endif /* !defined(__MUSL_LIBC) && ARCH(Intel) && WSIZE(32) */ =20 ssize_t pwrite (int fildes, const void *buf, size_t nbyte, off_t offset) { -#endif /* ^ARCH(Intel) && WSIZE(32) */ int *guard; - ssize_t ret; - IOTrace_packet iopkt; if (NULL_PTR (pwrite)) init_io_intf (); if (CHCK_REENTRANCE (guard)) - { -#if ARCH(Intel) && WSIZE(32) - return (real_pwrite) (fildes, buf, nbyte, offset); -#else - return CALL_REAL (pwrite)(fildes, buf, nbyte, offset); -#endif - } + return CALL_REAL (pwrite)(fildes, buf, nbyte, offset); PUSH_REENTRANCE (guard); hrtime_t reqt =3D gethrtime (); -#if ARCH(Intel) && WSIZE(32) - ret =3D (real_pwrite) (fildes, buf, nbyte, offset); -#else - ret =3D CALL_REAL (pwrite)(fildes, buf, nbyte, offset); -#endif + ssize_t ret =3D CALL_REAL (pwrite)(fildes, buf, nbyte, offset); if (RECHCK_REENTRANCE (guard)) { POP_REENTRANCE (guard); return ret; } - hrtime_t grnt =3D gethrtime (); - collector_memset (&iopkt, 0, sizeof ( IOTrace_packet)); - iopkt.comm.tsize =3D sizeof ( IOTrace_packet); - iopkt.comm.tstamp =3D grnt; - iopkt.requested =3D reqt; - if (ret >=3D 0) - iopkt.iotype =3D WRITE_TRACE; - else - iopkt.iotype =3D WRITE_TRACE_ERROR; - iopkt.fd =3D fildes; - iopkt.nbyte =3D ret; - iopkt.comm.frinfo =3D collector_interface->getFrameInfo (io_hndl, iopkt.= comm.tstamp, FRINFO_FROM_STACK, &iopkt); - collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt); + write_io_packet (fildes, ret, reqt, ret >=3D 0 ? WRITE_TRACE : WRITE_TRA= CE_ERROR); POP_REENTRANCE (guard); return ret; } =20 /*------------------------------------------------------------- pwrite64 */ +#if !defined(__MUSL_LIBC) #if ARCH(Intel) && WSIZE(32) // map interposed symbol versions -static int -__collector_pwrite64_symver (int(real_pwrite64) (), int fildes, const void= *buf, size_t nbyte, off64_t offset); =20 SYMVER_ATTRIBUTE (__collector_pwrite64_2_2, pwrite64@@GLIBC_2.2) -int +ssize_t __collector_pwrite64_2_2 (int fildes, const void *buf, size_t nbyte, off64= _t offset) { - TprintfT (DBG_LTT, "iotrace: __collector_pwrite64_2_2@%p(fildes=3D%d, bu= f=3D%p, nbyte=3D%lld, offset=3D%lld)\n", - CALL_REAL (pwrite64_2_2), fildes, buf, (long long) nbyte, (long long)= offset); - if (NULL_PTR (pwrite64)) + int *guard; + if (NULL_PTR (pwrite64_2_2)) init_io_intf (); - return __collector_pwrite64_symver (CALL_REAL (pwrite64_2_2), fildes, bu= f, nbyte, offset); + if (CHCK_REENTRANCE (guard)) + return CALL_REAL (pwrite64_2_2)(fildes, buf, nbyte, offset); + PUSH_REENTRANCE (guard); + hrtime_t reqt =3D gethrtime (); + ssize_t ret =3D CALL_REAL (pwrite64_2_2)(fildes, buf, nbyte, offset); + if (RECHCK_REENTRANCE (guard)) + { + POP_REENTRANCE (guard); + return ret; + } + write_io_packet (fildes, ret, reqt, ret >=3D 0 ? WRITE_TRACE : WRITE_TRA= CE_ERROR); + POP_REENTRANCE (guard); + return ret; } =20 SYMVER_ATTRIBUTE (__collector_pwrite64_2_1, pwrite64@GLIBC_2.1) int __collector_pwrite64_2_1 (int fildes, const void *buf, size_t nbyte, off64= _t offset) { - TprintfT (DBG_LTT, "iotrace: __collector_pwrite64_2_1@%p(fildes=3D%d, bu= f=3D%p, nbyte=3D%lld, offset=3D%lld)\n", - CALL_REAL (pwrite64_2_1), fildes, buf, (long long) nbyte, (long long)= offset); - if (NULL_PTR (pwrite64)) + int *guard; + if (NULL_PTR (pwrite64_2_1)) init_io_intf (); - return __collector_pwrite64_symver (CALL_REAL (pwrite64_2_1), fildes, bu= f, nbyte, offset); + if (CHCK_REENTRANCE (guard)) + return CALL_REAL (pwrite64_2_1)(fildes, buf, nbyte, offset); + PUSH_REENTRANCE (guard); + hrtime_t reqt =3D gethrtime (); + ssize_t ret =3D CALL_REAL (pwrite64_2_1)(fildes, buf, nbyte, offset); + if (RECHCK_REENTRANCE (guard)) + { + POP_REENTRANCE (guard); + return ret; + } + write_io_packet (fildes, ret, reqt, ret >=3D 0 ? WRITE_TRACE : WRITE_TRA= CE_ERROR); + POP_REENTRANCE (guard); + return ret; } - -static int -__collector_pwrite64_symver (int(real_pwrite64) (), int fildes, const void= *buf, size_t nbyte, off64_t offset) -{ -#else /* ^ARCH(Intel) && WSIZE(32) */ +#endif =20 ssize_t pwrite64 (int fildes, const void *buf, size_t nbyte, off64_t offset) { -#endif /* ^ARCH(Intel) && WSIZE(32) */ int *guard; - ssize_t ret; - IOTrace_packet iopkt; if (NULL_PTR (pwrite64)) init_io_intf (); if (CHCK_REENTRANCE (guard)) - { -#if ARCH(Intel) && WSIZE(32) - return (real_pwrite64) (fildes, buf, nbyte, offset); -#else - return CALL_REAL (pwrite64)(fildes, buf, nbyte, offset); -#endif - } + return CALL_REAL (pwrite64)(fildes, buf, nbyte, offset); PUSH_REENTRANCE (guard); hrtime_t reqt =3D gethrtime (); -#if ARCH(Intel) && WSIZE(32) - ret =3D (real_pwrite64) (fildes, buf, nbyte, offset); -#else - ret =3D CALL_REAL (pwrite64)(fildes, buf, nbyte, offset); -#endif + ssize_t ret =3D CALL_REAL (pwrite64)(fildes, buf, nbyte, offset); if (RECHCK_REENTRANCE (guard)) { POP_REENTRANCE (guard); return ret; } - hrtime_t grnt =3D gethrtime (); - collector_memset (&iopkt, 0, sizeof ( IOTrace_packet)); - iopkt.comm.tsize =3D sizeof ( IOTrace_packet); - iopkt.comm.tstamp =3D grnt; - iopkt.requested =3D reqt; - if (ret >=3D 0) - iopkt.iotype =3D WRITE_TRACE; - else - iopkt.iotype =3D WRITE_TRACE_ERROR; - iopkt.fd =3D fildes; - iopkt.nbyte =3D ret; - iopkt.comm.frinfo =3D collector_interface->getFrameInfo (io_hndl, iopkt.= comm.tstamp, FRINFO_FROM_STACK, &iopkt); - collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt); + write_io_packet (fildes, ret, reqt, ret >=3D 0 ? WRITE_TRACE : WRITE_TRA= CE_ERROR); POP_REENTRANCE (guard); return ret; } +#endif =20 /*------------------------------------------------------------- fgets */ char* diff --git a/gprofng/libcollector/jprofile.c b/gprofng/libcollector/jprofil= e.c index 9daaa5a267e..52114066726 100644 --- a/gprofng/libcollector/jprofile.c +++ b/gprofng/libcollector/jprofile.c @@ -285,12 +285,6 @@ __collector_jprofile_start_attach (void) { jthread thread; (*jvmti)->GetCurrentThread (jvmti, &thread); -#ifdef DEBUG - collector_thread_t tid; - tid =3D __collector_thr_self (); - TprintfT (0, "jprofile attach: AttachCurrentThread: thread: %lu jni= _env=3D%p jthread=3D%p\n", - (unsigned long) tid, jni_env, thread); -#endif /* DEBUG */ jvmti_VMInit (jvmti, jni_env, thread); (*jvmti)->GenerateEvents (jvmti, JVMTI_EVENT_COMPILED_METHOD_LOAD); (*jvmti)->GenerateEvents (jvmti, JVMTI_EVENT_DYNAMIC_CODE_GENERATED= ); diff --git a/gprofng/libcollector/libcol_util.c b/gprofng/libcollector/libc= ol_util.c index c709b3c5ed1..d682aa0ab29 100644 --- a/gprofng/libcollector/libcol_util.c +++ b/gprofng/libcollector/libcol_util.c @@ -1116,9 +1116,9 @@ __collector_util_init () /* internal calls for mapping in libcollector call mmap64 */ ptr =3D dlsym (libc, "mmap64"); if (ptr) - __collector_util_funcs.mmap64 =3D (void*(*)(void *, size_t, int, int, = int, off_t))ptr; + __collector_util_funcs.mmap64_ =3D (void*(*)(void *, size_t, int, int,= int, off_t))ptr; else - __collector_util_funcs.mmap64 =3D __collector_util_funcs.mmap; + __collector_util_funcs.mmap64_ =3D __collector_util_funcs.mmap; =20 ptr =3D dlsym (libc, "munmap"); if (ptr) @@ -1214,16 +1214,16 @@ __collector_util_init () #if ARCH(Intel) && WSIZE(32) ptr =3D dlvsym (libc, "pwrite64", "GLIBC_2.2"); // it is in /lib/libpthr= ead.so.0 if (ptr) - __collector_util_funcs.pwrite64 =3D (ssize_t (*)())ptr; + __collector_util_funcs.pwrite64_ =3D (ssize_t (*)())ptr; else { Tprintf (DBG_LT0, "libcol_util: WARNING: dlvsym for %s@%s failed. Us= ing dlsym() instead.", "pwrite64", "GLIBC_2.2"); #endif /* ARCH(Intel) && WSIZE(32) */ ptr =3D dlsym (libc, "pwrite64"); if (ptr) - __collector_util_funcs.pwrite64 =3D (ssize_t (*)())ptr; + __collector_util_funcs.pwrite64_ =3D (ssize_t (*)())ptr; else - __collector_util_funcs.pwrite64 =3D __collector_util_funcs.pwrite; + __collector_util_funcs.pwrite64_ =3D __collector_util_funcs.pwrite; #if ARCH(Intel) && WSIZE(32) } #endif /* ARCH(Intel) && WSIZE(32) */ @@ -1319,6 +1319,15 @@ __collector_util_init () __collector_util_funcs.getcpuid =3D __collector_getcpuid; __collector_util_funcs.memset =3D collector_memset; =20 + ptr =3D dlsym (libc, "getcontext"); + if (ptr) + __collector_util_funcs.getcontext =3D (int(*)())ptr; + else + { + CALL_UTIL (fprintf)(stderr, "collector_util_init COL_ERROR_UTIL_INIT= getcontext: %s\n", dlerror ()); + err =3D COL_ERROR_UTIL_INIT; + } + ptr =3D dlsym (libc, "malloc"); if (ptr) __collector_util_funcs.malloc =3D (void *(*)(size_t))ptr; diff --git a/gprofng/libcollector/libcol_util.h b/gprofng/libcollector/libc= ol_util.h index e13a02ea6d7..c32c76f091b 100644 --- a/gprofng/libcollector/libcol_util.h +++ b/gprofng/libcollector/libcol_util.h @@ -59,12 +59,11 @@ extern int __collector_xml_snprintf (char *s, size_t n,= const char *format, ...) extern int __collector_xml_vsnprintf (char *s, size_t n, const char *forma= t, va_list args); =20 /* ------- collector_thread ----------------- */ -pid_t __collector_gettid (); +extern pid_t __collector_gettid (); extern void __collector_ext_gettid_tsd_create_key (); -#define collector_thread_t pthread_t // not using pid_t, since = tid is defined as pthread_t in package structures, and other codes assume t= his type -#define statvfs_t struct statvfs -#define __collector_lwp_self() (collector_thread_t)__collector_gettid() //= not using pthread_self() -#define __collector_thr_self() (collector_thread_t)__collector_gettid() //= not using pthread_self() +typedef pthread_t collector_thread_t; +#define __collector_lwp_self() ((collector_thread_t) ((unsigned long) __co= llector_gettid())) +#define __collector_thr_self() ((collector_thread_t) ((unsigned long) __co= llector_gettid())) =20 /* ------- collector_mutex ----------------- */ /* diff --git a/gprofng/libcollector/linetrace.c b/gprofng/libcollector/linetr= ace.c index 978c5503e2e..a209308c767 100644 --- a/gprofng/libcollector/linetrace.c +++ b/gprofng/libcollector/linetrace.c @@ -29,6 +29,8 @@ #include #include #include +#include + =20 #include "descendants.h" =20 @@ -360,7 +362,7 @@ check_fd_dynamic (int fd) size_t sz =3D (size_t) 8192; /* one page should suffice */ if (sz > off) sz =3D off; - char *p =3D CALL_UTIL (mmap64)((char *) 0, sz, PROT_READ, MAP_PRIVATE, f= d, (off64_t) 0); + char *p =3D CALL_UTIL (mmap64_)((char *) 0, sz, PROT_READ, MAP_PRIVATE, = fd, (off64_t) 0); if (p =3D=3D MAP_FAILED) { TprintfT (DBG_LT0, "check_fd_dynamic(): ERROR/WARNING: mmap failed f= or `%d'\n", fd); diff --git a/gprofng/libcollector/memmgr.c b/gprofng/libcollector/memmgr.c index 5ada421f3f4..aa13ea77852 100644 --- a/gprofng/libcollector/memmgr.c +++ b/gprofng/libcollector/memmgr.c @@ -131,7 +131,7 @@ alloc_chunk (unsigned sz, int log) if (log =3D=3D 1) Tprintf (DBG_LT2, "alloc_chunk mapping %u, rounded up from %u\n", (uns= igned int) chunksz, sz); /* mmap64 is only in 32-bits; this call goes to mmap in 64-bits */ - ptr =3D (char*) CALL_UTIL (mmap64)(0, chunksz, PROT_READ | PROT_WRITE, + ptr =3D (char*) CALL_UTIL (mmap64_)(0, chunksz, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, (int) -1, (off64_t) 0); if (ptr =3D=3D MAP_FAILED) { diff --git a/gprofng/libcollector/mmaptrace.c b/gprofng/libcollector/mmaptr= ace.c index ba5c9129f4c..bd299e6f64f 100644 --- a/gprofng/libcollector/mmaptrace.c +++ b/gprofng/libcollector/mmaptrace.c @@ -441,13 +441,9 @@ checksum_mapname (MapInfo* map) } =20 =20 -#if (ARCH(Intel) && WSIZE(32)) || ARCH(SPARC) -static void* -dlopen_searchpath_symver (void*(real_dlopen) (), void* caller_addr, const = char* basename, int mode) -#else static void* -dlopen_searchpath (void* caller_addr, const char* basename, int mode) -#endif +dlopen_searchpath (void*(real_dlopen) (const char *, int), + void *caller_addr, const char *basename, int mode) { TprintfT (DBG_LT2, "dlopen_searchpath(%p, %s, %d)\n", caller_addr, basen= ame, mode); Dl_info dl_info; @@ -458,7 +454,8 @@ dlopen_searchpath (void* caller_addr, const char* basen= ame, int mode) } TprintfT (DBG_LT2, "dladdr(%p): %p fname=3D%s\n", caller_addr, dl_info.dli_fbase, dl_info.dli_fname); - int noload =3D RTLD_BINDING_MASK | RTLD_NOLOAD; //XXXX why RTLD_BINDING_= MASK? + int noload =3D RTLD_LAZY | RTLD_NOW | RTLD_NOLOAD; + void *caller_hndl =3D NULL; #define WORKAROUND_RTLD_BUG 1 #ifdef WORKAROUND_RTLD_BUG // A dynamic linker dlopen bug can result in corruption/closure of open = streams @@ -470,29 +467,20 @@ dlopen_searchpath (void* caller_addr, const char* bas= ename, int mode) #endif const char* tmp_path =3D (dl_info.dli_fbase =3D=3D (void*) MAINBASE) ? NULL : dl_info.dli_fname; - void* caller_hndl =3D NULL; -#if ((ARCH(Intel) && WSIZE(32)) || ARCH(SPARC)) - caller_hndl =3D (real_dlopen) (tmp_path, noload); -#else - caller_hndl =3D CALL_REAL (dlopen)(tmp_path, noload); -#endif + caller_hndl =3D real_dlopen (tmp_path, noload); =20 #else //XXXX workaround should be removed once linker patches are all avai= lable =20 - void* caller_hndl =3D NULL; -#if (ARCH(Intel) && WSIZE(32) || ARCH(SPARC) - caller_hndl =3D (real_dlopen) (dl_info.dli_fname, noload); -#else - caller_hndl =3D CALL_REAL (dlopen)(dl_info.dli_fname, noload); -#endif + caller_hndl =3D real_dlopen (dl_info.dli_fname, noload); =20 #endif //XXXX workaround should be removed once linker patches are all ava= ilable =20 if (!caller_hndl) { TprintfT (0, "ERROR: dlopen(%s,NOLOAD): %s\n", dl_info.dli_fname, dl= error ()); - return 0; + return NULL; } +#if !defined(__MUSL_LIBC) Dl_serinfo _info, *info =3D &_info; Dl_serpath *path; =20 @@ -546,7 +534,7 @@ dlopen_searchpath (void* caller_addr, const char* basen= ame, int mode) I have already confirmed with our user that the workaround is working with his real application. Additionally, the dlopen_searchpath() function is called only by the - libcorrector init() function when the experiment is started. + libcollector init() function when the experiment is started. Therefore, allocating some extra bytes on the stack which is local to this routine is harmless. */ @@ -575,7 +563,8 @@ dlopen_searchpath (void* caller_addr, const char* basen= ame, int mode) if (ret) return ret; // success! } - return 0; +#endif + return NULL; } =20 static void @@ -1550,40 +1539,9 @@ munmap (void *start, size_t length) =20 =20 /*------------------------------------------------------------- dlopen */ -// map interposed symbol versions -#if (ARCH(Intel) && WSIZE(32)) || ARCH(SPARC) - -static void * -__collector_dlopen_symver (void*(real_dlopen) (), void *caller, const char= *pathname, int mode); - -SYMVER_ATTRIBUTE (__collector_dlopen_2_1, dlopen@@GLIBC_2.1) -void * -__collector_dlopen_2_1 (const char *pathname, int mode) -{ - if (NULL_PTR (dlopen)) - init_mmap_intf (); - void *caller =3D __builtin_return_address (0); // must be called inside = dlopen first layer interpostion - return __collector_dlopen_symver (CALL_REAL (dlopen_2_1), caller, pathna= me, mode); -} - -SYMVER_ATTRIBUTE (__collector_dlopen_2_0, dlopen@GLIBC_2.0) -void * -__collector_dlopen_2_0 (const char *pathname, int mode) -{ - if (NULL_PTR (dlopen)) - init_mmap_intf (); - void* caller =3D __builtin_return_address (0); // must be called inside = dlopen first layer interpostion - return __collector_dlopen_symver (CALL_REAL (dlopen_2_0), caller, pathna= me, mode); -} -#endif - -#if (ARCH(Intel) && WSIZE(32)) || ARCH(SPARC) static void * -__collector_dlopen_symver (void*(real_dlopen) (), void *caller, const char= *pathname, int mode) -#else -void * -dlopen (const char *pathname, int mode) -#endif +__collector_dlopen_symver (void*(real_dlopen) (const char *, int), + void *caller, const char *pathname, int mode) { const char * real_pathname =3D pathname; char new_pathname[MAXPATHLEN]; @@ -1595,10 +1553,6 @@ dlopen (const char *pathname, int mode) origin_offset =3D 10; if (origin_offset) { -#if ! ((ARCH(Intel) && WSIZE(32)) || ARCH(SPARC)) - // 'caller' is not passed as an argument - void * caller =3D __builtin_return_address (0); // must be called in= side dlopen first layer interpostion -#endif Dl_info dl_info; if (caller && dladdr (caller, &dl_info) !=3D 0) { @@ -1619,37 +1573,18 @@ dlopen (const char *pathname, int mode) init_mmap_intf (); TprintfT (DBG_LT2, "libcollector.dlopen(%s,%d) interposing\n", pathname ? pathname : "", mode); - void* ret =3D NULL; + void *ret =3D NULL; =20 // set guard for duration of handling dlopen, since want to ensure // new mappings are resolved after the actual dlopen has occurred PUSH_REENTRANCE; hrtime_t hrt =3D GETRELTIME (); =20 - if (real_pathname && !__collector_strchr (real_pathname, '/')) - { // got an unqualified name - // get caller and use its searchpath -#if ! ((ARCH(Intel) && WSIZE(32)) || ARCH(SPARC)) - void* caller =3D __builtin_return_address (0); // must be called ins= ide dlopen -#endif - if (caller) - { -#if (ARCH(Intel) && WSIZE(32)) || ARCH(SPARC) - ret =3D dlopen_searchpath_symver (real_dlopen, caller, real_pathname, m= ode); -#else - ret =3D dlopen_searchpath (caller, real_pathname, mode); -#endif - } - } + if (caller && real_pathname && !__collector_strchr (real_pathname, '/')) + ret =3D dlopen_searchpath (real_dlopen, caller, real_pathname, mode); =20 if (!ret) - { -#if (ARCH(Intel) && WSIZE(32)) || ARCH(SPARC) - ret =3D (real_dlopen) (real_pathname, mode); -#else - ret =3D CALL_REAL (dlopen)(real_pathname, mode); -#endif - } + ret =3D real_dlopen (real_pathname, mode); TprintfT (DBG_LT2, "libcollector -- dlopen(%s) returning %p\n", pathname= , ret); =20 /* Don't call update if dlopen failed: preserve dlerror() */ @@ -1660,6 +1595,39 @@ dlopen (const char *pathname, int mode) return ret; } =20 +void * +dlopen (const char *pathname, int mode) +{ + if (NULL_PTR (dlopen)) + init_mmap_intf (); + void* caller =3D __builtin_return_address (0); // must be called inside = dlopen first layer interpostion + return __collector_dlopen_symver (CALL_REAL (dlopen), caller, pathname, = mode); +} + +#if !defined(__MUSL_LIBC) && ((ARCH(Intel) && WSIZE(32)) || ARCH(SPARC)) +// map interposed symbol versions + +SYMVER_ATTRIBUTE (__collector_dlopen_2_1, dlopen@@GLIBC_2.1) +void * +__collector_dlopen_2_1 (const char *pathname, int mode) +{ + if (NULL_PTR (dlopen_2_1)) + init_mmap_intf (); + void *caller =3D __builtin_return_address (0); // must be called inside = dlopen first layer interpostion + return __collector_dlopen_symver (CALL_REAL (dlopen_2_1), caller, pathna= me, mode); +} + +SYMVER_ATTRIBUTE (__collector_dlopen_2_0, dlopen@GLIBC_2.0) +void * +__collector_dlopen_2_0 (const char *pathname, int mode) +{ + if (NULL_PTR (dlopen_2_0)) + init_mmap_intf (); + void* caller =3D __builtin_return_address (0); // must be called inside = dlopen first layer interpostion + return __collector_dlopen_symver (CALL_REAL (dlopen_2_0), caller, pathna= me, mode); +} +#endif + /*------------------------------------------------------------- dlclose */ int dlclose (void *handle) diff --git a/gprofng/libcollector/profile.c b/gprofng/libcollector/profile.c index 996d3f09198..ee9fb7d3b0c 100644 --- a/gprofng/libcollector/profile.c +++ b/gprofng/libcollector/profile.c @@ -268,7 +268,7 @@ __collector_ext_profile_handler (siginfo_t *info, ucont= ext_t *context) /* assume this case is rare, and accept overhead of creating dummy_u= c */ TprintfT (0, "collector_profile_handler: ERROR: got NULL context!\n"= ); context =3D &uctxmem; - getcontext (context); /* initialize dummy context */ + CALL_UTIL (getcontext) (context); /* initialize dummy context */ SETFUNCTIONCONTEXT (context, &__collector_lost_profile_context); } ClockPacket pckt; diff --git a/gprofng/libcollector/synctrace.c b/gprofng/libcollector/synctr= ace.c index 492ef9993f7..d48aeaa2d2d 100644 --- a/gprofng/libcollector/synctrace.c +++ b/gprofng/libcollector/synctrace.c @@ -32,10 +32,9 @@ #include =20 #include "gp-defs.h" -#include "collector_module.h" +#include "collector.h" #include "gp-experiment.h" #include "data_pckts.h" -#include "i18n.h" #include "tsd.h" #include "cc_libcollector.h" =20 diff --git a/gprofng/libcollector/unwind.c b/gprofng/libcollector/unwind.c index f8e11823c81..009b5ab8456 100644 --- a/gprofng/libcollector/unwind.c +++ b/gprofng/libcollector/unwind.c @@ -232,7 +232,7 @@ memory_error_func (int status ATTRIBUTE_UNUSED, bfd_vma= addr ATTRIBUTE_UNUSED, =20 #elif ARCH(Aarch64) #define FILL_CONTEXT(context) \ - { getcontext(context); \ + { CALL_UTIL (getcontext) (context); \ context->uc_mcontext.sp =3D (__u64) __builtin_frame_address(0); \ } =20 diff --git a/gprofng/src/Experiment.cc b/gprofng/src/Experiment.cc index c797724af07..98aae9714ac 100644 --- a/gprofng/src/Experiment.cc +++ b/gprofng/src/Experiment.cc @@ -6466,7 +6466,7 @@ int Experiment::copy_file_to_archive (const char *name, const char *aname, int= hide_msg) { errno =3D 0; - int fd_w =3D open64 (aname, O_WRONLY | O_CREAT | O_EXCL, 0644); + int fd_w =3D ::open64 (aname, O_WRONLY | O_CREAT | O_EXCL, 0644); if (fd_w =3D=3D -1) { if (errno =3D=3D EEXIST) @@ -6484,7 +6484,7 @@ Experiment::copy_file_to_archive (const char *name, c= onst char *aname, int hide_ return 1; } =20 - int fd_r =3D open64 (name, O_RDONLY); + int fd_r =3D ::open64 (name, O_RDONLY); if (fd_r =3D=3D -1) { fprintf (stderr, GTXT ("er_archive: unable to open `%s': %s\n"), diff --git a/gprofng/src/Print.cc b/gprofng/src/Print.cc index d415d591e1e..03932530956 100644 --- a/gprofng/src/Print.cc +++ b/gprofng/src/Print.cc @@ -2209,14 +2209,14 @@ print_anno_file (char *name, const char *sel, const= char *srcFile, { fitem =3D func->getDefSrc (); found =3D (func->line_first > 0) - && strcmp (basename (srcFile), - basename (fitem->get_name ())) =3D=3D 0; + && strcmp (get_basename (srcFile), + get_basename (fitem->get_name ())) =3D=3D 0; } else { Vec_loop (SourceFile*, sources, index, fitem) { - if (strcmp (basename (srcFile), basename (fitem->get_name ())) =3D=3D 0) + if (strcmp (get_basename (srcFile), get_basename (fitem->get_name ())) = =3D=3D 0) { found =3D true; break; diff --git a/gprofng/src/collector_module.h b/gprofng/src/collector_module.h index f608dab5831..6cf53d5b27f 100644 --- a/gprofng/src/collector_module.h +++ b/gprofng/src/collector_module.h @@ -25,6 +25,7 @@ #include #include #include +#include #include =20 #include "gp-defs.h" @@ -55,6 +56,7 @@ typedef struct CollectorUtilFuncs int (*fprintf)(FILE *stream, const char *format, ...); void (*free)(void *ptr); int (*fstat)(int fd, struct stat *buf); + int (*getcontext)(ucontext_t *ucp); int (*getcpuid)(); char *(*getcwd)(char *buf, size_t size); char *(*getenv)(const char *name); @@ -66,7 +68,7 @@ typedef struct CollectorUtilFuncs int (*mkdir)(); time_t (*mktime)(struct tm *timeptr); void *(*mmap)(void *, size_t, int, int, int, off_t); - void *(*mmap64)(); + void *(*mmap64_)(); int (*munmap)(); int (*open)(const char *, int, ...); int (*open_bare)(const char *, int, ...); @@ -75,7 +77,7 @@ typedef struct CollectorUtilFuncs FILE *(*popen)(const char *command, const char *mode); int (*putenv)(char *string); ssize_t (*pwrite)(); - ssize_t (*pwrite64)(); + ssize_t (*pwrite64_)(); ssize_t (*read)(); int (*setenv)(const char *name, const char *value, int overwrite); int (*sigfillset)(sigset_t *set);