public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/29438] New: enabling gmon for arbitrary DSO
@ 2022-08-02 20:17 leo at yuriev dot ru
  2022-08-02 20:18 ` [Bug libc/29438] " leo at yuriev dot ru
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: leo at yuriev dot ru @ 2022-08-02 20:17 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=29438

            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 processed
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 PIE,
but not a DSO. In particular due that the `load_address` is gathered strictly
for executable only
(https://sourceware.org/git/?p=glibc.git;a=blob;f=gmon/gmon.c;h=dee64803ada583d79ca9adc281beffce4300255f;hb=d165ca64980f90ccace088670652cc203d1b5411#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 
 * but does not create problems if `-pg` is enabled. 
 */
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__)) 
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__)) 
void static mydso_global_destructor(void) {
#ifdef ENABLE_GPROF_FOR_THIS_DSO
  if (!&__gmon_start__)
    _mcleanup();
#endif
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-04-28 17:23 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-02 20:17 [Bug libc/29438] New: enabling gmon for arbitrary DSO leo at yuriev dot ru
2022-08-02 20:18 ` [Bug libc/29438] " leo at yuriev dot ru
2022-08-03 15:30 ` leo at yuriev dot ru
2022-08-03 19:33 ` leo at yuriev dot ru
2022-10-21 13:39 ` nsz at gcc dot gnu.org
2023-01-30 12:32 ` leo at yuriev dot ru
2023-02-08 12:07 ` leo at yuriev dot ru
2023-02-22 22:24 ` cvs-commit at gcc dot gnu.org
2023-04-28 12:13 ` cvs-commit at gcc dot gnu.org
2023-04-28 14:35 ` cvs-commit at gcc dot gnu.org
2023-04-28 14:35 ` cvs-commit at gcc dot gnu.org
2023-04-28 17:23 ` cvs-commit at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).