From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x29.google.com (mail-oa1-x29.google.com [IPv6:2001:4860:4864:20::29]) by sourceware.org (Postfix) with ESMTPS id 8E0CB3858D28 for ; Thu, 21 Jul 2022 13:10:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8E0CB3858D28 Received: by mail-oa1-x29.google.com with SMTP id 586e51a60fabf-10d6e8990b9so2292338fac.7 for ; Thu, 21 Jul 2022 06:10:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:organization:in-reply-to :content-transfer-encoding; bh=hyCCWW4g59xGqrsk9j5+yd953VrGzRf48jsASvVuoLI=; b=owIBKCbzlKGMpIz6DKA75k/DIQOShHlRyk0fPPjkRIRsyVHrml98NGm9eVRxlk2MHP QneyBz1FM938YbQ0vuj6pUNzQ8V52L0WDIEcW5RfoklAPDe0pSMCvA/G8MfX8ilfmqkU f8zVQh/FSPt0a9EQcksJrVe7rlpsFUidtxoFlHibX3JAY3mRWMAaCTm/Buj/bbVWwD8S Cwa8CiKrGqm4D20OWi59KRKokSP8kR6oxYlRalmZW64Z2F0eAV08Pwc02hPjZhVtRPDt Qcy/x5ikXSbcFV6IEV1zJzHlgA/RxLOHkd5jxNa5pL8tdDwgd8ODSSSVf+bFBpK5teIV lv9Q== X-Gm-Message-State: AJIora87vxOcbr0vP9N8Df4GgWd2tELxB3H0W8GkagGGEiD3aWfy56HG D9uPILUZ8YNjLYRr7jhPaxUTlx+Z2jXgMA== X-Google-Smtp-Source: AGRyM1sQFFQi6f4letH8A0CDWDFh38EyADaKZyTtUE/u67zp58TmPxYY1x+MqSX1GksX0tCG6aP3dA== X-Received: by 2002:a05:6870:8a13:b0:10c:23ef:272a with SMTP id p19-20020a0568708a1300b0010c23ef272amr5013714oaq.20.1658409028801; Thu, 21 Jul 2022 06:10:28 -0700 (PDT) Received: from ?IPV6:2804:431:c7cb:8ded:90a7:7be2:9a21:5f25? ([2804:431:c7cb:8ded:90a7:7be2:9a21:5f25]) by smtp.gmail.com with ESMTPSA id i9-20020a4ad089000000b00435b0a84995sm726977oor.24.2022.07.21.06.10.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Jul 2022 06:10:28 -0700 (PDT) Message-ID: <21e64150-606d-df60-e50f-df09ca5a67ff@linaro.org> Date: Thu, 21 Jul 2022 10:10:25 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.0.2 Subject: Re: [PATCH] malloc: Simplify implementation of __malloc_assert Content-Language: en-US To: Florian Weimer , libc-alpha@sourceware.org References: <87a6924uvf.fsf@oldenburg.str.redhat.com> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <87a6924uvf.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Jul 2022 13:10:38 -0000 On 21/07/22 07:34, Florian Weimer via Libc-alpha wrote: > It is prudent not to run too much code after detecting heap > corruption, and __fxprintf is really complex. The line number > and file name do not carry much information, so it is not included > in the error message. (__libc_message only supports %s formatting.) > The function name and assertion should provide some context. > > Tested on i686-linux-gnu and x86_64-linux-gnu. Also emulated the > __libc_message call using GDB, and it produced the expected output. > > Thanks, > Florian > --- > malloc/malloc.c | 15 +++++---------- > 1 file changed, 5 insertions(+), 10 deletions(-) > > diff --git a/malloc/malloc.c b/malloc/malloc.c > index 12908b8f97..bd3c76ed31 100644 > --- a/malloc/malloc.c > +++ b/malloc/malloc.c > @@ -292,19 +292,14 @@ > # define __assert_fail(assertion, file, line, function) \ > __malloc_assert(assertion, file, line, function) > > -extern const char *__progname; > - > -static void > +_Noreturn static void > __malloc_assert (const char *assertion, const char *file, unsigned int line, > const char *function) > { > - (void) __fxprintf (NULL, "%s%s%s:%u: %s%sAssertion `%s' failed.\n", > - __progname, __progname[0] ? ": " : "", > - file, line, > - function ? function : "", function ? ": " : "", > - assertion); > - fflush (stderr); > - abort (); > + __libc_message (do_abort, "\ > +Fatal glibc error: malloc assertion failure in %s: %s\n", > + function, assertion); > + __builtin_unreachable (); > } > #endif > #endif > Would be better to keep the the file and line information?