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 1A9BC3857681 for ; Mon, 31 Oct 2022 16:14:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1A9BC3857681 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-oa1-x29.google.com with SMTP id 586e51a60fabf-13ba86b5ac0so13990377fac.1 for ; Mon, 31 Oct 2022 09:14:30 -0700 (PDT) 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 :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=L0FY1hSCzmLKUtogG+LDVCz01AxmX5xeJVI0OJMswGg=; b=WGODckJ2Elq/MpSFq6QEagwHNpbWhIGR7QLmfDEcgxQCOkJgvt5A0kMUp84vXsY9Hc Qp0P9Q6eG81YQPrxQO9wiWy0qxqEfzJHzN+9elNvumttsTFqsBGTM3qMEeQNwL706FRf Zvc1UDLapYM+hsoLLL2CqffUx85lhX9lYkkvRreu/hoa0AKMgpi1BH8PwprWacs/Xa5C stCsld6WMuVuhm88cXXIV0cw5+zgyg2ImV3eRKJYlaky5QreQBunR9FGdNKcPy80w60q bV+6z4DhMLwNDS5UEcFyCQhaUpifuEQgP2RktbUW/2keMSQ2Ts5SOfci9JxegifahlBJ 38dw== 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 :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=L0FY1hSCzmLKUtogG+LDVCz01AxmX5xeJVI0OJMswGg=; b=MatQ6MArR/NI5cq8mp8UYo8N27Ya/h7BzKOjsWltMYR1147qTpVNgk3Cs6IMujXHP3 1mZHGGu3zXx0MPETno7nozSOOc/Fx6/0nEKWjj4RRY7E5RLV4qKKIMvFj5n7SP17iJOC SBz2I1yXL6dlFNW7LfQE6oXkmk1Nww5vj48xNb+qlrZ9CmMOHuIH8+DI9o27C390cFlA UTAwL8LL2TkWKNmAh6Z4GAZi+mygtlmI2tdHRm42kqWGrLNDMx1iFEMEArIcA2hYhG/G pPvSbYFDvUwSF7JhS1oVtCN5qNhMD67iZRkFM0+ceg7C/o6NvPeLkhaN6kEGOigoyqPh mzPQ== X-Gm-Message-State: ACrzQf3atks5TOhZ1eeYyyn+MdhS67skTcst4HQh5jBURZ3wCDI+f1Vy PSxS5zRRAfyZm0r3N9XRh5EujFvOpgJhcqHe X-Google-Smtp-Source: AMsMyM7LgLFHNzJpAG+BPinAonSoluqFTFyW5RKGCFV4Aiosh1t4bOnMFO9fQ6JyQmV+BHiCiNTv2Q== X-Received: by 2002:a05:6870:ac0d:b0:13b:b9e7:e6d0 with SMTP id kw13-20020a056870ac0d00b0013bb9e7e6d0mr16835690oab.17.1667232869432; Mon, 31 Oct 2022 09:14:29 -0700 (PDT) Received: from ?IPV6:2804:1b3:a7c0:17c8:29c8:c66:a795:b2b1? ([2804:1b3:a7c0:17c8:29c8:c66:a795:b2b1]) by smtp.gmail.com with ESMTPSA id q21-20020a056830233500b00661c0747545sm2994271otg.44.2022.10.31.09.14.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 31 Oct 2022 09:14:29 -0700 (PDT) Message-ID: <90413fe7-d1eb-610b-7eac-019b676455f9@linaro.org> Date: Mon, 31 Oct 2022 13:14:27 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.4.0 Subject: Re: [PATCH 10/20] malloc: Fix alignment logic in obstack Content-Language: en-US To: Szabolcs Nagy , libc-alpha@sourceware.org References: From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.8 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 List-Id: On 27/10/22 12:33, Szabolcs Nagy via Libc-alpha wrote: > If sizeof(ptrdiff_t) < sizeof(void*) the alignment logic was wrong: > incorrectly assumed that base was already sufficiently aligned. > > Use more robust alignment logic: this one should work on any target. > Note: this is an installed header so it must be namespace clean and > portable hence it uses unsigned long for the alignment offset. > --- > malloc/obstack.h | 19 +++---------------- > 1 file changed, 3 insertions(+), 16 deletions(-) > > diff --git a/malloc/obstack.h b/malloc/obstack.h > index 4b01cdfe4d..1cf18e5464 100644 > --- a/malloc/obstack.h > +++ b/malloc/obstack.h > @@ -116,22 +116,9 @@ > # define PTR_INT_TYPE ptrdiff_t > #endif > > -/* If B is the base of an object addressed by P, return the result of > - aligning P to the next multiple of A + 1. B and P must be of type > - char *. A + 1 must be a power of 2. */ > - > -#define __BPTR_ALIGN(B, P, A) ((B) + (((P) - (B) + (A)) & ~(A))) > - > -/* Similar to _BPTR_ALIGN (B, P, A), except optimize the common case > - where pointers can be converted to integers, aligned as integers, > - and converted back again. If PTR_INT_TYPE is narrower than a > - pointer (e.g., the AS/400), play it safe and compute the alignment > - relative to B. Otherwise, use the faster strategy of computing the > - alignment relative to 0. */ > - > -#define __PTR_ALIGN(B, P, A) \ > - __BPTR_ALIGN (sizeof (PTR_INT_TYPE) < sizeof (void *) ? (B) : (char *) 0, \ > - P, A) > +/* Align P to the next multiple of A + 1, where A + 1 is a power of 2, > + A fits into unsigned long and P has type char *. */ > +#define __PTR_ALIGN(B, P, A) ((P) + (-(unsigned long)(P) & (A))) Shouldn't you use uintptr_t here to be consistent with your other changes that exactly change using long to cast from pointers? It would be good to check with gnulib as well, since this header is also shared with it. > > #include >