Bug 29479 - Collection fails when built without java support: symbol lookup error: ...-binutils-2.39/bin/../lib/gprofng/libgp-collector.so: undefined symbol: __collector_jprofile_start_attach
Summary: Collection fails when built without java support: symbol lookup error: ...-bi...
Alias: None
Product: binutils
Classification: Unclassified
Component: gprofng (show other bugs)
Version: 2.39
: P2 normal
Target Milestone: ---
Assignee: Vladimir Mezentsev
Depends on:
Reported: 2022-08-12 09:21 UTC by Sergei Trofimovich
Modified: 2022-08-27 07:51 UTC (History)
2 users (show)

See Also:
Last reconfirmed: 2022-08-13 00:00:00


Note You need to log in before you can comment on or make changes to this bug.
Description Sergei Trofimovich 2022-08-12 09:21:08 UTC
Attempted to use `gprofng` today and got the failure:

$ gprofng collect app $(which ls)
Creating experiment directory test.3.er (Process ID: 2240198) ...
...-coreutils-9.1/bin/ls: symbol lookup error: ..-binutils-2.39/bin/../lib/gprofng/libgp-collector.so: undefined symbol: __collector_jprofile_start_attach

I think the failure happens because __collector_jprofile_start_attach() is conditionally enabled but used unconditionally:

$ git grep -P '__collector_jprofile_start_attach|GPROFNG_JAVA_PROFILING' | cat

# unconditional use and export:

gprofng/libcollector/collector.c:    __collector_jprofile_start_attach ();
gprofng/libcollector/collector.h:extern int __collector_jprofile_start_attach ();

# conditional definition:

gprofng/libcollector/jprofile.c:#if defined(GPROFNG_JAVA_PROFILING)
gprofng/libcollector/jprofile.c:int __collector_jprofile_start_attach (void);
gprofng/libcollector/jprofile.c:__collector_jprofile_start_attach (void)
gprofng/libcollector/jprofile.c:#endif /* GPROFNG_JAVA_PROFILING */
Comment 1 Sergei Trofimovich 2022-08-12 21:59:17 UTC
So far I worked it around locally by removing java-specific code in libcollector:

--- a/gprofng/libcollector/collector.c
+++ b/gprofng/libcollector/collector.c
@@ -912,9 +912,11 @@ __collector_open_experiment (const char *exp, const char *params, sp_origin_t or
   /* init tsd for unwind, called right after __collector_tsd_allocate()*/
   __collector_ext_unwind_key_init (1, NULL);

   /* start java attach if suitable */
   if (exp_origin == SP_ORIGIN_DBX_ATTACH)
     __collector_jprofile_start_attach ();
   start_sec_time = CALL_UTIL (time)(NULL);
   __collector_start_time = collector_interface.getHiResTime ();
   TprintfT (DBG_LT0, "\t__collector_open_experiment; resetting start_time\n");
--- a/gprofng/libcollector/unwind.c
+++ b/gprofng/libcollector/unwind.c
@@ -557,6 +557,7 @@ __collector_get_frame_info (hrtime_t ts, int mode, void *arg)
   int size = max_frame_size;

 #define MIN(a,b) ((a)<(b)?(a):(b))
   /* get Java info */
   if (__collector_java_mode && __collector_java_asyncgetcalltrace_loaded && context && !pseudo_context)
@@ -569,6 +570,7 @@ __collector_get_frame_info (hrtime_t ts, int mode, void *arg)
          size -= sz;

   /* get native stack */
   if (context)

Is it a reasonable approach? Or should jprofile.c unconditionally define those functions? Say, with a possible no-op when `javac` is not available. What would be your preference?
Comment 2 Vladimir Mezentsev 2022-08-13 00:42:22 UTC
Thanks for catching this.
My ol8 and ol9 are not reporting anything.

% gprofng collect app $(which ls)
Creating experiment directory test.1.er (Process ID: 155186) ...
acinclude.m4  common  configure     doc		     libcollector  Makefile.in	src	   testsuite
aclocal.m4    config  configure.ac  gp-display-html  Makefile.am   README	test.1.er

These functions are undefined (but never called):
% nm lib/gprofng/libgp-collector.so | egrep '__collector_jprofile_start_attach|__collector_ext_jstack_unwind'
                 U __collector_ext_jstack_unwind
                 U __collector_jprofile_start_attach

I will push your fix to the master branch.
Comment 3 Sourceware Commits 2022-08-18 18:21:28 UTC
The master branch has been updated by Vladimir Mezentsev <vmezents@sourceware.org>:


commit 49ddd814ac1071af7c4f45d5f8398b91862f2c7f
Author: Vladimir Mezentsev <vladimir.mezentsev@oracle.com>
Date:   Wed Aug 17 19:55:23 2022 -0700

    gprofng: fix bug 29479 Collection fails when built without java support
    2022-08-17  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>
            PR gprofng/29479
            * libcollector/collector.c: Add #if defined(GPROFNG_JAVA_PROFILING) for
            java specific code.
            * libcollector/unwind.c: Likewise.
Comment 4 Vladimir Mezentsev 2022-08-18 18:29:37 UTC
 Fixed in the master branch.