Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jAgZK-0002Bo-2k for pgsql-hackers@arkaria.postgresql.org; Sat, 07 Mar 2020 21:01:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jAgZI-0007OU-R7 for pgsql-hackers@arkaria.postgresql.org; Sat, 07 Mar 2020 21:01:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jAgZI-0007ON-Cn for pgsql-hackers@lists.postgresql.org; Sat, 07 Mar 2020 21:01:08 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jAgZB-0001I5-R4 for pgsql-hackers@postgresql.org; Sat, 07 Mar 2020 21:01:07 +0000 Received: by mail-pg1-x541.google.com with SMTP id u12so2805495pgb.10 for ; Sat, 07 Mar 2020 13:01:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:cc:date:in-reply-to:references :mime-version:content-transfer-encoding; bh=+YLvXLaVvdp+ElRgeBJFrnbBIi+GMUU2XlWJpe8Pwmc=; b=BERxxlZOIh7nItLMwc/j0hQH1w7bGU1Hu4JkDMiJ8t1bRyUDa03q7vCLaOb+JLofAh 6g4oOd5b7HMq5n3886+OQ6Klm5pLV1nzO5aXX7TAXOguJb1fBVwPeiZZP/7ay2RPI/G/ 0Jo/gLVsTrVDQuChsAtKTDdffwSaxivk7Uqa/epssPE4cjc7RXa70uiUz6Xh0ue27EZ5 SEmsVor27baxjQlIWHIiiep5xeMHhmfFI/yJCZoUBwE22zT6VrHZVKtTTKUqtyfJPnXX n8Q60XCujMv02sZEkTHLlHVZKFvOlSSkcguky/l26TXt4QUCYStYYddqsY+5oVtl0dMo EnVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:mime-version:content-transfer-encoding; bh=+YLvXLaVvdp+ElRgeBJFrnbBIi+GMUU2XlWJpe8Pwmc=; b=J8xPCne13nlWaR3e2mNd+H2qL1bBGsIX2kBaQ2OJsChDrATVxL4qeYJbN1+6stWBCA vVnC8RC1BppKXRGhGiFW5/hclyix4FEEEVqMlNbmD84i+MGqZjT7cPOEmi6tV/2Bcmf2 f183prNWnbh2bTmQ3s0Modb3v/xBXLBhZtk4OaQeyyT7aHtqctbhPS6PMsLNCq5rZzQV F/IHGWzKMct7CfU9pgkPDuHsqwz51k2tm9V/TsNWr/kc2DeMkWlvSAgWViWQ99dNmNQT uKboMX4/RZn/tRaM6QkBwOCanyW2znME1CZR2aJYBJVRXWadb1jWBF+AaEJPFvCeiPrq NlJw== X-Gm-Message-State: ANhLgQ19zVl6d6k/RuMwHJdD53ooDU3B9cWgYye5Elb8Zh3MArIIWljv 5twKkOKiwtJn0FoFZ4JSlJdFmQ== X-Google-Smtp-Source: ADFU+vt9cYbr0d3EOK8BnnQURgFxyFOgVq7+8ZxKZolsDgLU7d+d7AN9Dy/VVBvyHa961t/g7ffvEQ== X-Received: by 2002:a62:e30b:: with SMTP id g11mr9869055pfh.57.1583614859087; Sat, 07 Mar 2020 13:00:59 -0800 (PST) Received: from jdavis.lan (c-73-231-146-4.hsd1.ca.comcast.net. [73.231.146.4]) by smtp.gmail.com with ESMTPSA id k24sm5312517pfg.27.2020.03.07.13.00.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 07 Mar 2020 13:00:57 -0800 (PST) Message-ID: <91ca648cfd1f99bf07981487a7d81a1ec926caad.camel@j-davis.com> Subject: Re: Add LogicalTapeSetExtend() to logtape.c From: Jeff Davis To: Adam Lee Cc: pgsql-hackers@postgresql.org, Peter Geoghegan , Heikki Linnakangas Date: Sat, 07 Mar 2020 13:00:55 -0800 In-Reply-To: <91f9ae9935c715d5638954f52e0e33c4d1dc1388.camel@j-davis.com> References: <20200228061641.GA883@earth.local> <619e61919fd604c2caa629536ee87615b732e054.camel@j-davis.com> <20200303014935.GA1022@earth.local> <20200304035719.GB1022@earth.local> <91f9ae9935c715d5638954f52e0e33c4d1dc1388.camel@j-davis.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5-0ubuntu0.18.04.1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, 2020-03-04 at 12:06 -0800, Jeff Davis wrote: > I tracked the problem down. Because of the name _FORTIFY_SOURCE, I got somewhat concerned that this change (logtape-20200303) was somehow interfering with a safety mechanism in the compiler. There's a mechanism in GCC called object size tracking[1]. memcpy() is replaced by __builtin___memcpy_chk(), which verifies that the amount being copied doesn't exceed the destination object size -- but of course this only works if GCC knows the destination object size. If it doesn't know the object size, or if it can prove at compile time that it will never be exceeded, then it replaces the checked memcpy with a call to normal memcpy (at least [1] seems to suggest that it will). But I did some experiments and GCC is clearly not able to know the destination object size either before or after the logtape-20200303 change: * palloc (and friends) lack the alloc_size function attribute[2], which is required for GCC to try to track it (aside: maybe we should add it as an unrelated change?) * if I add the alloc_size attribute to palloc, it is able to do very basic tracking of the object size; but not in more complex cases like the buffer in logtape.c Therefore, from [1], I'd expect the call to checked memcpy to be replaced by a call to normal memcpy() either before or after the change. It is replaced by normal memcpy() before the change, but not after. I conclude that this is arbitrary and not fundamentally related to object size checking or _FORTIFY_SOURCE. I don't think I should hold up this change because of an arbitrary decision by the compiler. Regards, Jeff Davis [1] https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html [2] https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-alloc_005fsize-function-attribute