From: Joe Simmons-Talbott <josimmon@redhat.com>
To: libc-alpha@sourceware.org
Subject: Re: [PATCH] elf: Get rid of alloca usage in _dl_start_profile
Date: Mon, 30 Oct 2023 08:24:23 -0400 [thread overview]
Message-ID: <20231030122423.GC496230@oak> (raw)
In-Reply-To: <20231010190529.GL4098455@oak>
Ping.
On Tue, Oct 10, 2023 at 03:05:29PM -0400, Joe Simmons-Talbott wrote:
> Ping.
>
> On Tue, Oct 03, 2023 at 03:33:16PM -0400, Joe Simmons-Talbott wrote:
> > On Fri, Sep 29, 2023 at 09:52:19AM -0400, Joe Simmons-Talbott wrote:
> > > Replace alloca usage with a scratch_buffer.
> >
> > This was tested by enabling profiling in the build and running a test
> > application with LD_PROFILE defined. I also generated a directory with
> > over 1024 characters and defined LD_PROFILE_OUTPUT pointing to that
> > directory to test the malloc path. In both cases the .profile file was
> > created. I wasn't able to process the .profile files with gprof though
> > as it complained about the version.
> >
> > Thanks,
> > Joe
> > > ---
> > > elf/dl-profile.c | 17 +++++++++++++++--
> > > 1 file changed, 15 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/elf/dl-profile.c b/elf/dl-profile.c
> > > index 8be0065fbd..8ae50020bb 100644
> > > --- a/elf/dl-profile.c
> > > +++ b/elf/dl-profile.c
> > > @@ -22,6 +22,7 @@
> > > #include <fcntl.h>
> > > #include <inttypes.h>
> > > #include <limits.h>
> > > +#include <scratch_buffer.h>
> > > #include <stdio.h>
> > > #include <stdlib.h>
> > > #include <string.h>
> > > @@ -201,6 +202,8 @@ _dl_start_profile (void)
> > > int s_scale;
> > > #define SCALE_1_TO_1 0x10000L
> > > const char *errstr = NULL;
> > > + struct scratch_buffer sbuf;
> > > + scratch_buffer_init (&sbuf);
> > >
> > > /* Compute the size of the sections which contain program code. */
> > > for (ph = GL(dl_profile_map)->l_phdr;
> > > @@ -318,8 +321,14 @@ _dl_start_profile (void)
> > > /* First determine the output name. We write in the directory
> > > OUTPUT_DIR and the name is composed from the shared objects
> > > soname (or the file name) and the ending ".profile". */
> > > - filename = (char *) alloca (strlen (GLRO(dl_profile_output)) + 1
> > > - + strlen (GLRO(dl_profile)) + sizeof ".profile");
> > > + size_t filename_len = (strlen (GLRO(dl_profile_output)) + 1
> > > + + strlen (GLRO(dl_profile)) + sizeof ".profile");
> > > + if (!scratch_buffer_set_array_size (&sbuf, 1, filename_len))
> > > + {
> > > + _dl_error_printf ("failed to allocate memory");
> > > + return;
> > > + }
> > > + filename = sbuf.data;
> > > cp = __stpcpy (filename, GLRO(dl_profile_output));
> > > *cp++ = '/';
> > > __stpcpy (__stpcpy (cp, GLRO(dl_profile)), ".profile");
> > > @@ -339,6 +348,7 @@ _dl_start_profile (void)
> > > __close_nocancel (fd);
> > > _dl_error_printf (errstr, filename,
> > > __strerror_r (errnum, buf, sizeof buf));
> > > + scratch_buffer_free (&sbuf);
> > > return;
> > > }
> > >
> > > @@ -380,6 +390,7 @@ _dl_start_profile (void)
> > >
> > > _dl_error_printf ("%s: file is no correct profile data file for `%s'\n",
> > > filename, GLRO(dl_profile));
> > > + scratch_buffer_free (&sbuf);
> > > return;
> > > }
> > >
> > > @@ -483,6 +494,8 @@ _dl_start_profile (void)
> > >
> > > /* Turn on profiling. */
> > > running = 1;
> > > +
> > > + scratch_buffer_free (&sbuf);
> > > }
> > >
> > >
> > > --
> > > 2.39.2
> > >
> >
>
next prev parent reply other threads:[~2023-10-30 12:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-29 13:52 Joe Simmons-Talbott
2023-10-03 19:33 ` Joe Simmons-Talbott
2023-10-10 19:05 ` Joe Simmons-Talbott
2023-10-30 12:24 ` Joe Simmons-Talbott [this message]
2023-10-30 12:44 ` Andreas Schwab
2023-10-31 20:17 ` Joe Simmons-Talbott
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231030122423.GC496230@oak \
--to=josimmon@redhat.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).