From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2083.outbound.protection.outlook.com [40.107.22.83]) by sourceware.org (Postfix) with ESMTPS id C061E3858C55 for ; Tue, 1 Nov 2022 09:43:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C061E3858C55 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=c74+2IRsj1jt0EclxllPKS0JxqSyTnHoyB/LGzEqPKdVL9UD1sma/7gpTNV1Y9BR+7pJl3jcHtiNK2MClq4XOaQ6zdWehx2LTWRUUl+It15zvolxUEq3FoPr5ZItav6EKkngJ3/sknN7Czx/bScd4UdDl1JiKNlzZl+AwR+a3IslSf6oCfBhSlJ8ARbnqITZ4Z5JiQRK2UT0kUoryscnjI47l4HReu/0RftnsARX8iEumKe3k84e6OZDma2gY9A2BUpyVNk1oce1EPhiy3JI9/Z/3U9xXhT/tZAfKSNK1jEbB0syOqdgupq1BEZLhBu2KOQuJhuZ8XAw8ouOa2Huxw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=E5RCf1vMQaEoAsdTylxvS7av8rwqnZlvkGWNhaHqW+8=; b=oVeQWhtqh+vB4OSvrCywtI2uMt1jvTAdxZUl13l+aeFREEzwf/vL6d0ecmtkHu4C9UEaZusFXZ+q/9p0nPof0sjGBDF94bTjI53VBTjR1rZ+G16EQpAUVyZRmzNTfzpGRv3XSC1uaT8JBNcIy4ULoe+9JaYcUMMtqH5XKyHiCk4YqRuCPuyI10EraWsWrwgayGufaS/cTuv8sDgTkm+qp3CM5sJZk5xmdeKGS3VdJzQGasuoKc5y+4oyQ8Uro+aT7pmNrCJrAe/0eSdukz1xjnjXqZ+TWHOLVsIvpYtxli1q/zjZdXzPsZ8qDZzEMyrTryob9OedV4nw4bUKNXsMnQ== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=E5RCf1vMQaEoAsdTylxvS7av8rwqnZlvkGWNhaHqW+8=; b=WeEm3Egc2V5l5Y93Ds9l1A6+we5mgxLVV1c4pwlYOR6mKcuwJMRBdBJ741Dln3XK0PBS1A4HcnUy4MsfIUMsCGLzg4pWM7dfjvAjzFlPCAc+JJVQGmvbMumFrZILhiVG2qlTE71SUVICe5RfdOsa1972KYXF1S6uPPr2UNcSQBM= Received: from DB8PR09CA0017.eurprd09.prod.outlook.com (2603:10a6:10:a0::30) by DB9PR08MB6476.eurprd08.prod.outlook.com (2603:10a6:10:258::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.21; Tue, 1 Nov 2022 09:43:32 +0000 Received: from DBAEUR03FT024.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:a0:cafe::cc) by DB8PR09CA0017.outlook.office365.com (2603:10a6:10:a0::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.21 via Frontend Transport; Tue, 1 Nov 2022 09:43:32 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DBAEUR03FT024.mail.protection.outlook.com (100.127.142.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.14 via Frontend Transport; Tue, 1 Nov 2022 09:43:32 +0000 Received: ("Tessian outbound b4aebcc5bc64:v130"); Tue, 01 Nov 2022 09:43:31 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 19734675ebe132db X-CR-MTA-TID: 64aa7808 Received: from c30d8f5b8be1.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 7FCB781B-9312-42CA-B685-855F55384E32.1; Tue, 01 Nov 2022 09:43:25 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id c30d8f5b8be1.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 01 Nov 2022 09:43:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LjfE6oybmDKkTklNStULiKm8hh1fQV5mKdvyOQ7TpAKfs+mQ6i6rdZQyGgyxBoqKRGzaT7UhsiPqgj1m31zoujZcY5bK8/Me9JHhUHCaGhPv1kwXMaqCw4bxwsQU9EFc6W+q9uwmHf/PbsRUDa5D6uNJFUyKq6Ohcbpp3srldAp1LpnCuxSxPWX8cWmFVhSx4fCJ+WSrXsNH7t9qTrmXeaQJxK2V9h94QXxK/zyadDMuHSIkxq+8T9ydWRNi5GtxkxUlEEKlZzq71twS71VwL7/h4BIqByS2wg4Ly1bow4d1ToOo4mV0YwwHvt1bDgl/X+B9cdscZW67mCybLi7QSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=E5RCf1vMQaEoAsdTylxvS7av8rwqnZlvkGWNhaHqW+8=; b=PbH/bg42o1Z5kyJrf6i8C10rVVMM0Bwd1dpzNjRD4eXdwEZjk74bNem7Gz3Y658lTwOUuKDTCEvZZKEkzAZvqBz+I9JGg9jy/RtoygSSevUjFxa0WAG/Unb7jatMFoBGBMWZ+pXyEbg3ghOWtM6+Wn2aNuRCc6Ha7fYvQY0vCKjv2earspATmFkCINAkSnUhAqv3N7W20U2qiRvbxanFj63lyNNVp/VBZsKOpFBtzVTQUpshmo9sXyKVXPBENG958SmZFiaAkms1xs7OnsLE0Sa+Y8NBBPLMDMffsW0RKu+skhq1oeqmTyiOgEWdBfAYfuL9X0AYbzwra6zQBd7xQQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=E5RCf1vMQaEoAsdTylxvS7av8rwqnZlvkGWNhaHqW+8=; b=WeEm3Egc2V5l5Y93Ds9l1A6+we5mgxLVV1c4pwlYOR6mKcuwJMRBdBJ741Dln3XK0PBS1A4HcnUy4MsfIUMsCGLzg4pWM7dfjvAjzFlPCAc+JJVQGmvbMumFrZILhiVG2qlTE71SUVICe5RfdOsa1972KYXF1S6uPPr2UNcSQBM= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from DB9PR08MB7179.eurprd08.prod.outlook.com (2603:10a6:10:2cc::19) by GV1PR08MB8107.eurprd08.prod.outlook.com (2603:10a6:150:94::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.16; Tue, 1 Nov 2022 09:43:23 +0000 Received: from DB9PR08MB7179.eurprd08.prod.outlook.com ([fe80::8999:7c8d:d088:d198]) by DB9PR08MB7179.eurprd08.prod.outlook.com ([fe80::8999:7c8d:d088:d198%5]) with mapi id 15.20.5769.021; Tue, 1 Nov 2022 09:43:23 +0000 Date: Tue, 1 Nov 2022 09:43:07 +0000 From: Szabolcs Nagy To: Adhemerval Zanella Netto Cc: libc-alpha@sourceware.org Subject: Re: [PATCH 10/20] malloc: Fix alignment logic in obstack Message-ID: References: <90413fe7-d1eb-610b-7eac-019b676455f9@linaro.org> Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <90413fe7-d1eb-610b-7eac-019b676455f9@linaro.org> X-ClientProxiedBy: LO2P265CA0482.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:13a::7) To DB9PR08MB7179.eurprd08.prod.outlook.com (2603:10a6:10:2cc::19) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: DB9PR08MB7179:EE_|GV1PR08MB8107:EE_|DBAEUR03FT024:EE_|DB9PR08MB6476:EE_ X-MS-Office365-Filtering-Correlation-Id: 18618a07-f6b9-4f6d-ecf2-08dabbed89d1 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: vzCfBhTNAY7QuKZ55M7u6N6V5cGMkUDOHC6SPiu9zzw8O30g7f7p5hBhk7DL74akr2wOZ+yHXZ6kQh6vmQyx3UCgXdtAcNMP+4x11D05MkaEkp5Ev8MsZ0B++0OYnQV7W0jiI3SQKGEx5oAxWBtnTh2+qlWc8rOG6unctlIHpoWtz4W66SaDFZdDz1zV+/sjM5T9QASWhx1DX4Y5GptvBCbyx8Wf0bMIIwzgAu/qDTv1nQ/8XnzIiAheXdlcKevv9YRwh99BO28CFDId1mQu/OmKjunAG5gkHcrLui5qBvmMW8LmEHcw9sd8FMKksNwqVIcXs5DkBkfX3csqanSTQqVxowb3zgGKXL9w9pLxq4cUPoknhAj78uTBrphba6cm3XOwk4MFBIhhKMmsckYz2dg5JgIG1IsXkJsoI+dOW5tRWHe3Z5WcUE6A80+Lb3dlYgYId8+30zmBW2ZRYtjpwwqkVNHrMMdfJBh0562B6sgk326wmC5OfLZKX9LWEjk0FW8bcOpW8guaDwOCuq9jaOMk9KAYkajmSkD9M+y0JXmEcoRGZVRK4juiYIgZe+ErgjbwR23tQAxdpxNgs+XB7kaSQVFIDcNYRa0wPAwpFOwZnMdVsv1Ie6s8hmT3cS0/rjdLUFP/YgDDlnksJqNVjY3Alt4wgaF6/yyCuW+f1HifrYs+yjXr+s74XXvjc1uIiCP+lh1hlxqS4BsuuOkbgQ== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB9PR08MB7179.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(136003)(346002)(366004)(396003)(39860400002)(376002)(451199015)(6506007)(53546011)(6666004)(83380400001)(66556008)(66946007)(66476007)(8676002)(38100700002)(4326008)(36756003)(2616005)(186003)(86362001)(6486002)(6512007)(26005)(478600001)(316002)(6916009)(8936002)(44832011)(2906002)(41300700001)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR08MB8107 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT024.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: f82f95c2-8507-429e-b2c0-08dabbed8462 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: J75idWXc/tTROtCW+BK0jkWRyAlwr4m33RqQWkSEGFjhMtosR6zEW7x2nCXtbwKzEzaitNsGOfAkk0dYVb/lDOU/bjn23NVHFC9k6LChbye03Ipik3bzkVORdf0ge77Ty9h5psFZxlc2t8lLp1HW1HwE9dfDm5FR2Hfg+OmCGmEBUKDUfjsbJid3nH1e/IoVJo1UdW6laPsAMwR8+DGHwNje9Y+ZWNy+hCGKBpTaGl2gYyMxtnYxDvKLWynUsL22QM3rGhgC5NcEwVKMGk2ndR+dqKETm2cfQRHPrc9KSdIs8iLniCuipFIDaJhiEzZiQOleu2/eK/tmdM08hXUIBTvN8tjM/Lzmn/v8u8jJ/3M5JEx6MyI3b84QAxZI9YmuOIa73Jruq6nO3O81M/R+LE/T3iRL26ZuHF+1dqKNUB3/hSBTKaExOmn4BCauDlXOcdaOkZWABGqeFrdeEXu2C2hWvo0V6IhLqGiG0nYWEXq6l7+S+b5ZafVuO8vDD+bS5OnjLYjuyGYwJPaYiUXTgEX5DvBbaa5/cJiOM8f36DheFq4N4qIZNe3UciT89Qdi1hbpAodmAgA1ReVS1jwq/VoNWDNlteYAMyY2vo4Xsk7oADZzxSoCRzyLFGAOM4Ni+ijo36Ml0y0yszRkw8FERI17hNMA0ycJlDH7bxKK9XPozdml8rbZ6zgMaObTU7/KbKmVwaAIcEr4Op4gspjEjJVaATKlJOSFewzTJoszx8Dt78IkllVIJ5JmhpwO0loA2B2TeLavsY/HvD+e6YxKJQ== X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230022)(4636009)(39860400002)(376002)(136003)(346002)(396003)(451199015)(36840700001)(40470700004)(46966006)(336012)(2906002)(82740400003)(47076005)(53546011)(40460700003)(86362001)(6666004)(26005)(316002)(41300700001)(6512007)(8676002)(4326008)(70586007)(40480700001)(6506007)(2616005)(70206006)(82310400005)(44832011)(186003)(81166007)(356005)(8936002)(6862004)(36756003)(5660300002)(6486002)(83380400001)(478600001)(36860700001);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2022 09:43:32.0226 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 18618a07-f6b9-4f6d-ecf2-08dabbed89d1 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DBAEUR03FT024.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB6476 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,FORGED_SPF_HELO,GIT_PATCH_0,KAM_DMARC_NONE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE,TXREP,UNPARSEABLE_RELAY 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: 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. > > 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. > > > > > #include > >