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.129.124]) by sourceware.org (Postfix) with ESMTPS id 3E5F33858C2D for ; Tue, 3 Oct 2023 19:33:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3E5F33858C2D 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=1696361599; 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=66H4I+g0DC+liEviJFYwEAxo6v1fsA73woGO1/KPQVo=; b=XI4lPTWEWgM78id6+IMyvzDM0KxfC61JNrkmQi0ySrTeIENKUrrhxgZuDx4qMOVwaKTgDS 5dY3eBU7LkNWE28zdm+mF+hQU8ZPqnTq4xOtuWapAzpLoVy2bBOvWpoFLhC1VtecjIbf4/ E+MvPxzQ0DGpgg0krKMiP/nNLNC4zS0= 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-523-nLZEnoAFNRCQG4BMfXKYQA-1; Tue, 03 Oct 2023 15:33:18 -0400 X-MC-Unique: nLZEnoAFNRCQG4BMfXKYQA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (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 4D2963C17086 for ; Tue, 3 Oct 2023 19:33:18 +0000 (UTC) Received: from oak (unknown [10.22.16.149]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 351D94A9B0C for ; Tue, 3 Oct 2023 19:33:18 +0000 (UTC) Date: Tue, 3 Oct 2023 15:33:16 -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: <20231003193302.GF4098455@oak> References: <20230929135222.1195747-1-josimmon@redhat.com> MIME-Version: 1.0 In-Reply-To: <20230929135222.1195747-1-josimmon@redhat.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 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_H4,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: 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 >