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 30A943858D20 for ; Mon, 30 Oct 2023 12:24:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 30A943858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 30A943858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698668667; cv=none; b=Ptf94ItS2+6CtGHjHzz1W+9jXTLD/XZ/QkcdW139Vw7NQfh1KQNjYU8rI9C2DaBeBiTGjlk58yU0vUE5t5uyqlnv/ZN5VU5LiW7GwaKTYZ8AprdwMneO6nrDLTz9aHL2xvoAxNgHdok13zWPGWfvu0+bOc+0A3kl3SQ9Dhz0/k0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698668667; c=relaxed/simple; bh=a6q59Uh5VzdL2YmgBKbgrM81gx43ekyxkEKy4H+ezYM=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=F8ZQIsVNjR1aAIK2+bqn0JP4LxQ6IMHdD2R5WLrp1BTgTwTxCUAXiOCcYdE5eBVDvz67/3fwj1sHUPe6Qd/X+ZiVIxuNKikXhaZpfSeRm35to/Dfnw+zZzcD7D4rLL7JOva740F/1ogW7AR5gyu5JPxxpNS2v9nW8Pa6JhXfcvw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698668665; 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=zq8vtI3mRPWaVOGxkt5ejpliWDVZV4xIdpRGLHQz9cU=; b=XKR4mN9J5FswRj6mEiBkcz/zGyoz0ONkCEUhIniqv9Lma6mYGrDd+jRzSJoafKxuz9Oldm cINA1Qn5qZLvDaYbytq6UP/2ftJVcWXNBwJbw53gnSBxdcDmoVoDhgQ4SNUNaWmfR+vJeb XSCCblDrBnq7qqVPC/oPjr1vxtNiEIE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-558-pizZNbPkPACIIrsLbfQz4g-1; Mon, 30 Oct 2023 08:24:24 -0400 X-MC-Unique: pizZNbPkPACIIrsLbfQz4g-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 79AE185A58A for ; Mon, 30 Oct 2023 12:24:24 +0000 (UTC) Received: from oak (unknown [10.22.16.210]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6394F2026D4C for ; Mon, 30 Oct 2023 12:24:24 +0000 (UTC) Date: Mon, 30 Oct 2023 08:24:23 -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: <20231030122423.GC496230@oak> References: <20230929135222.1195747-1-josimmon@redhat.com> <20231003193302.GF4098455@oak> <20231010190529.GL4098455@oak> MIME-Version: 1.0 In-Reply-To: <20231010190529.GL4098455@oak> X-Scanned-By: MIMEDefang 3.4.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 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 > > > #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 > > > > > >