From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id 277E33858C55 for ; Tue, 1 Nov 2022 13:07:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 277E33858C55 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-x330.google.com with SMTP id c18-20020a056830349200b0066c47e192f0so3726379otu.12 for ; Tue, 01 Nov 2022 06:07:51 -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 :cc:to:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=rXQdMsanVnRvwWcutMDb1Go/P8KufMF2hnQxLbaB0+Q=; b=tmxQLRtFG34baf4dtCuwr+RDp1qQaKXoWXnBYZA0QihK5caMAi4eFZ68MagGQvcrZ/ eP1PODB0vknpeLQNSIhMyOhY8UgZcyc2Xf3R5dX0OULXfW09DlIby8SIL5SndVMPd+vM Lhhr81IPgqt/Gedg+lv9ZSkgsCNZfAiRpuXgrUNOreL3dyGBm0UY/RsNi/LTL23GHPoY 85p+eoEVE1ZuVzUfouqRqJuzzMgHkkjwndmAv/6zecPKgdTt4CzgrQq1OeaYqJieko2X cT/JpaFMEKqSkNi2NZm4etsz4yG9czaRfDbmYBos4flsObC2o4lEOFO7vpJP6nkIu81I QW4Q== 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=rXQdMsanVnRvwWcutMDb1Go/P8KufMF2hnQxLbaB0+Q=; b=rTbQwqjBYu2zfik8gcXjlJPvJhyYTkDJ4IOiURoZZJGVVkXSRCGvVRl39AeSQxzmSP aQgmPnQzYPVZ4nwUbfhkwbhYraWSj4fzYXwyYlX/yVo0gXo+rBVimBBWJ9IvGxqvM6vM lAv5P4l6vpufA3/1568hG3MbtXyx9bFUO6WY5cxS5R04nl4Z6KENaU0NgOdqpHGPLZn1 SayH1/vvkKEBVwr65E5ADhL353CtWuOq7eWUTMJz2G+TVd6XwIIWUKMQzaSQtpJssdXf sM7u6edw38yna80kgGJoDBugQBMazC05xKyy6rfB31/5eC5a75YvqNkNl5+dz/55p4UN oFSQ== X-Gm-Message-State: ACrzQf0d9YFYNxCGhDAuQZActHt5glU0kGNXbfqvq/FhtwIMzkjZnH2n tYZmfkSGa6+R/TWUw53vH62O7uvzppESLMfJ X-Google-Smtp-Source: AMsMyM5HePu9WcH31w4qw9whWW4TYqx0BPD5GhwRjWnEINaoqmQb3jCTPzGuT0LaSpYZp5sFrGTDew== X-Received: by 2002:a9d:70c8:0:b0:66c:3c59:6c3b with SMTP id w8-20020a9d70c8000000b0066c3c596c3bmr8801989otj.325.1667308070355; Tue, 01 Nov 2022 06:07:50 -0700 (PDT) Received: from [192.168.15.31] ([191.17.238.148]) by smtp.gmail.com with ESMTPSA id w10-20020a056870e2ca00b0013b0b19100fsm4421967oad.32.2022.11.01.06.07.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Nov 2022 06:07:49 -0700 (PDT) Message-ID: <6d59830b-602c-d2fd-8c11-a0d704af162a@linaro.org> Date: Tue, 1 Nov 2022 10:07:47 -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.1 Subject: Re: [PATCH 10/20] malloc: Fix alignment logic in obstack Content-Language: en-US To: Szabolcs Nagy Cc: libc-alpha@sourceware.org References: <90413fe7-d1eb-610b-7eac-019b676455f9@linaro.org> 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.1 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 01/11/22 06:43, Szabolcs Nagy wrote: > The 10/31/2022 13:14, Adhemerval Zanella Netto wrote: >> 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? > > here the offset part is unsigned long, but the pointer is kept > char *. in other patches the problem was that the pointer > was turned into long. > > here unsigned int would be enough, since obstack->alignment_mask > is int, larger alignments are not supported. > > the new formula may not be the fastest to compute, but if the > goal is portability then i think it's better than the current > code. Alright, although I still why not use uintptr_t here for consistency (as we do for all other pointer conversions). And the code already include stddef.h. > >> >> It would be good to check with gnulib as well, since this header is also >> shared with it. > > i see. i haven't looked at gnulib