From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x32d.google.com (mail-ot1-x32d.google.com [IPv6:2607:f8b0:4864:20::32d]) by sourceware.org (Postfix) with ESMTPS id 704853858D39 for ; Mon, 12 Dec 2022 13:51:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 704853858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-ot1-x32d.google.com with SMTP id p10-20020a9d76ca000000b0066d6c6bce58so7296627otl.7 for ; Mon, 12 Dec 2022 05:51:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=IIEVASaTA/e2grkqqUD42QruHWR1h/m4P96KikjqRh8=; b=KznKyZLHDVZJuXoaN9wOmaKMC8BHOPU/XW2KsCl2V78apjuL1Xj/j3nAo1MpDJD+3k SqM5Yi0oNz0tcmitvr14K1CelCUEE0gHf7zQUK0cSPZnfgbgxu3uGl2JrS3ialh8H5hZ NXp0XQjOeS+u9jZVU+Wh/sFL1i1LJqan1qdyZ2Me6eF14hXGcIdSKMdIu22Bbs8F0Hq9 qOiF6KMWb/EOIbNxlrKpbI+cTNP22CtAyYzI0tctrRGTGPohVxjxCSOz2X2tS/5X7q1w PSNEbHDJBbXX7FvG7928NuleSw+4YyKFHlHu2U8Rfrz6bzzXXwRG3Y6sFaNYzrW/HEfx 0H0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IIEVASaTA/e2grkqqUD42QruHWR1h/m4P96KikjqRh8=; b=1VPHRgPuZjIEyXmC3ku6DO+7T5vn3XrYpT1kXplGd1q/OBDsXBp4UIjrmKWZTAo/99 Vcse7EWIMcV8QKIE12SF7eeV863TKr3cS5S1A4SY5H7RZ2Xf/hkJ63bcu0UIdEU74ds+ 6SX3X60SZhfCZPKikRHi3GHqAjQV0sB5mbZKyaEB5/Mhszu3HpgoiY26ZbjsnwCRjyMu b9eUC30zJqo1c6HKVNHRQI0QvH8G2wcGeqcEx/7d+IEbV5KM2VYHNMFsxAUANl6mvvcR dI7syJzIR+nhGaWN1cjMFZ/2JAxjnZ6KoiCVu15KutYRRwNY/EhjqP2YUTwjaIIxPb7X Cr5w== X-Gm-Message-State: ANoB5pn4Qe4bXwxlHkUV5grto26STqYPFKP4TToYVHa17YaCHjVmrLR2 l3ioNYd0OSkXQjNYnpKaZINKDw== X-Google-Smtp-Source: AA0mqf6jH4Mb87B2t0OwF1M0maFelvv6aAE4jQeC69TFGoEskZcwV4OSFcp2UM0sjVeGIK5TIZ7f8Q== X-Received: by 2002:a9d:311:0:b0:670:a10b:f343 with SMTP id 17-20020a9d0311000000b00670a10bf343mr61859otv.9.1670853109704; Mon, 12 Dec 2022 05:51:49 -0800 (PST) Received: from [192.168.15.31] (201-92-181-161.dsl.telesp.net.br. [201.92.181.161]) by smtp.gmail.com with ESMTPSA id e5-20020a9d63c5000000b006619533d1ddsm4030851otl.76.2022.12.12.05.51.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 12 Dec 2022 05:51:48 -0800 (PST) Message-ID: <4d17b0bb-ef33-bf88-1e4a-fc90159c4390@linaro.org> Date: Mon, 12 Dec 2022 10:51:45 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH 4/7] Move libc_freeres_ptrs and libc_subfreeres to weak functions Content-Language: en-US To: Florian Weimer , Adhemerval Zanella via Libc-alpha Cc: Fangrui Song References: <20221115193159.173838-1-adhemerval.zanella@linaro.org> <20221115193159.173838-5-adhemerval.zanella@linaro.org> <87zgbsswva.fsf@oldenburg.str.redhat.com> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <87zgbsswva.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,NICE_REPLY_A,RCVD_IN_BARRACUDACENTRAL,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,URIBL_BLACK 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 12/12/22 08:08, Florian Weimer wrote: > * Adhemerval Zanella via Libc-alpha: > >> diff --git a/malloc/set-freeres.c b/malloc/set-freeres.c >> index be8c2a35fc..ce5d010133 100644 >> --- a/malloc/set-freeres.c >> +++ b/malloc/set-freeres.c >> @@ -15,32 +15,210 @@ >> License along with the GNU C Library; if not, see >> . */ > >> +/* Resource Freeing Hooks: >> + >> + Normally a process exits and the OS cleans up any allocated >> + memory. However, when tooling like mtrace or valgrind is monitoring >> + the process we need to free all resources that are part of the >> + process in order to provide the consistency required to track >> + memory leaks. >> + >> + A single public API exists and is __libc_freeres(), and this is used >> + by applications like valgrind to freee resouces. >> + >> + Each free routines must be explicit listed below, with the care to define >> + weak functions for external symbol if applicable. */ >> + >> +/* From libc.so. */ >> +extern void __libc_freemem (void) weak_function; >> +extern void __hdestroy (void) weak_function; >> +extern void __gconv_cache_freemem (void) weak_function; > > These declarations should come from headers under include/, so that they > can be proper type-checked against the implementation. Ack. > >> +static void (*__libc_freeres_funcs[])(void) attribute_relro = >> +{ >> + __libc_freemem, >> + __hdestroy, >> + __gconv_cache_freemem, > > I think we can avoid these relocations for the dynamic case if we just > call these functions using call_function_static_weak, or directly free > the pointers using call_free_static_weak (see the other message). The > latter has somewhat large code size, but I think that's the right > trade-off here. I used a function pointer array mainly because it tends to generate less code on some ABIs compare to a chain of call_function_static_weak, but I did not take in consideration the relocation time spent. I don't have a strong opinion in fact, I will change to direct call using call_free_static_weak.