From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 102433858423 for ; Tue, 10 Oct 2023 19:05:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 102433858423 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696964732; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=chgtmLAMDwSTR5wnGbDsw0YCJRHhttmckJa6HZGWiLM=; b=Bb3PrkXGMrgb+kItitti6tzhOZ98/6mL4KWknD0Pw/QqewxYLTCFY5PWxtYZAy3TipXXZv jBVm97cq8EDBtpt3SpH/yXivF7/tSzGGamXCuBrqRMDutHHDa/LpLQ09ywHgsYzlFff+qq KuUfNOh3RU9dPALrwgomySbkB2DpFaw= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-386-Ti74gJ2RM9W9Fwo8X8UzlA-1; Tue, 10 Oct 2023 15:05:31 -0400 X-MC-Unique: Ti74gJ2RM9W9Fwo8X8UzlA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D80F91C2B66C for ; Tue, 10 Oct 2023 19:05:30 +0000 (UTC) Received: from oak (unknown [10.22.9.100]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BF9B92026D37 for ; Tue, 10 Oct 2023 19:05:30 +0000 (UTC) Date: Tue, 10 Oct 2023 15:05:29 -0400 From: Joe Simmons-Talbott To: libc-alpha@sourceware.org Subject: Re: [PATCH] elf: Get rid of alloca usage in _dl_start_profile Message-ID: <20231010190529.GL4098455@oak> References: <20230929135222.1195747-1-josimmon@redhat.com> <20231003193302.GF4098455@oak> MIME-Version: 1.0 In-Reply-To: <20231003193302.GF4098455@oak> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -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 > > >