From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DC546385829C; Tue, 2 Aug 2022 20:17:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DC546385829C From: "leo at yuriev dot ru" To: glibc-bugs@sourceware.org Subject: [Bug libc/29438] New: enabling gmon for arbitrary DSO Date: Tue, 02 Aug 2022 20:17:07 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: libc X-Bugzilla-Version: 2.38 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: leo at yuriev dot ru X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: glibc-bugs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-bugs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Aug 2022 20:17:08 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D29438 Bug ID: 29438 Summary: enabling gmon for arbitrary DSO Product: glibc Version: 2.38 Status: UNCONFIRMED Severity: normal Priority: P2 Component: libc Assignee: unassigned at sourceware dot org Reporter: leo at yuriev dot ru CC: drepper.fsp at gmail dot com Target Milestone: --- As a developer, I need the ability to activate/use gmon (gprof monitor) for= my DSO (shared library). Yes, of course, I know that gmon is not intended for this. However, such restriction can be easily circumvented approximately as shown below. As a result, gmon.out will be created, which unfortunately cannot be proces= sed correctly by gprof due to a problem similar to PIE in 2017 (Bug 21189, Bug 22284). The reason is that the fix made is only intended to work in the case of a P= IE, but not a DSO. In particular due that the `load_address` is gathered strict= ly for executable only (https://sourceware.org/git/?p=3Dglibc.git;a=3Dblob;f=3Dgmon/gmon.c;h=3Ddee= 64803ada583d79ca9adc281beffce4300255f;hb=3Dd165ca64980f90ccace088670652cc20= 3d1b5411#l55). So I think this can be easily fixed if we take the `load_address` not from executable but of the first DSO, the text segment of which intersects with = the range of addresses passed to `monstartup()`. Will such a patch be accepted if I prepare it, or will there be other ideas/suggestions? Leo, Regards. --- /* It is worth noting that the code below works for DSO * when `-pg` is not enabled in the main executable=20 * but does not create problems if `-pg` is enabled.=20 */ extern void _mcleanup (void); extern void monstartup(unsigned long, unsigned long); extern void __gmon_start__(void) __attribute__((__weak__)); extern void _init (void); extern void _fini (void); __attribute__((__constructor__, __no_instrument_function__, __no_profile_instrument_function__))=20 static void mydso_global_constructor(void) { #ifdef ENABLE_GPROF_FOR_THIS_DSO if (!&__gmon_start__) monstartup((u_long)&_init, (u_long)&_fini); #endif } __attribute__((__destructor__, __no_instrument_function__, __no_profile_instrument_function__))=20 void static mydso_global_destructor(void) { #ifdef ENABLE_GPROF_FOR_THIS_DSO if (!&__gmon_start__) _mcleanup(); #endif } --=20 You are receiving this mail because: You are on the CC list for the bug.=